pckroon / pysmiles

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

Will pysmiles generate the only SMILES? #10

Closed njzjz closed 5 years ago

njzjz commented 5 years ago

Will two identical structures have different SMILES? Could I use pysmiles to distinguish isomers?

njzjz commented 5 years ago

What I mean is: can I use the following code to find two structures is the same:

if write_smiles(mol1) == write_smiles(mol2):
    # same
else:
    # isomer
pckroon commented 5 years ago

Hi,

in a word: no. What you are describing is known as "canonical SMILES". The problem is that there are many ways of defining it. However, the networkx isomorphism [1] functions contain functionality to see whether mol1 == mol2. You will need to supply appropriate edge_match and node_match function to make sure e.g. elements and bond orders match.

[1] https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.isomorphism.is_isomorphic.html#networkx.algorithms.isomorphism.is_isomorphic

njzjz commented 5 years ago

I see. Thank you.

pckroon commented 5 years ago

Your best bet might actually be going for a different library that can write Standard InChi. That should, in theory, also deal with things like resonance structures.