openforcefield / cmiles

Generate canonical molecule identifiers for quantum chemistry database
https://cmiles.readthedocs.io
MIT License
23 stars 7 forks source link

cmiles.utils.to_canonical_label failure #30

Open jchodera opened 4 years ago

jchodera commented 4 years ago

The following code raises an exception:

>>> import cmiles
>>> cmiles.utils.to_canonical_label("[H:13][c:1]1[c:3]([n:8][c:5]([n:10][c:6]1[N:12]([H:19])[c:7]2[c:2]([c:4]([n:9][n:11]2[H:18])[H:16])[H:14])[H:17])[H:15]", (9, 5, 11, 5))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/choderaj/miniconda/lib/python3.7/site-packages/cmiles/utils.py", line 193, in to_canonical_label
    return toolkit.generate_index(mol, labeled_atoms)
  File "/Users/choderaj/miniconda/lib/python3.7/site-packages/cmiles/_cmiles_oe.py", line 203, in generate_index
    a.SetMapIdx(i + 1)
AttributeError: 'NoneType' object has no attribute 'SetMapIdx'
ChayaSt commented 4 years ago

@jchodera, the problem here seems to be that the labels you are providing for the atoms have 5 twice. So you are trying to add 2 labels to the same atom.

ChayaSt commented 4 years ago

@jthorton, openeye will throw an error if the same atom is being labeled twice but rdkit will silently return an index ignoring the second occurrence of the same index. RDKit should raise an error so this is something _cmiles_rdkit.py should check.