pckroon / pysmiles

A lightweight python-only library for reading and writing SMILES strings
Apache License 2.0
147 stars 21 forks source link

Adjacency matrix #8

Closed nshervt closed 5 years ago

nshervt commented 5 years ago

Hello,

I was trying to use this code to find a graph representation for a given SMILE string. I tried

from pysmiles import read_smiles
import networkx as nx

smiles = 'N=CN(C=O)CC=O' 
mol = read_smiles(smiles)

# atom vector (C only)
print(mol.nodes(data='element'))
# adjacency matrix
print(nx.to_numpy_matrix(mol))

Apparently, this does not differ between single/double/triple bonds. Is there a way to enforce that? Thanks!

pckroon commented 5 years ago

nx.to_numpy_array(mol, weight='order') should do what you want. See also https://networkx.github.io/documentation/stable/reference/generated/networkx.convert_matrix.to_numpy_array.html#networkx.convert_matrix.to_numpy_array