Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrawRDKBits raised RDKit error when it applied to the compounds that contains imidazole. #2164

Closed
yamasakih opened this issue Nov 13, 2018 · 2 comments · Fixed by #5976
Closed
Labels
Milestone

Comments

@yamasakih
Copy link

Description:

  • RDKit Version: 2018.09.1
  • Platform: MaxOS 10.13.6

When I apply RDKFingerprint to the compounds that contains imidazole as substructure,
RDKit Error raised like below.

from rdkit import rdBase, Chem
from rdkit.Chem import AllChem, Draw
from rdkit.Chem.Draw import DrawRDKitBit, DrawRDKitBits, IPythonConsole

mol = Chem.MolFromSmiles('c1cncn(C)1')
bi = {}
_ = AllChem.RDKFingerprint(mol, minPath=1, maxPath=5, bitInfo=bi)
tuples = [(mol, k, bi) for k in bi.keys()]
DrawRDKitBits(tuples)

result:

RDKit ERROR: [18:31:04] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4
RDKit ERROR: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-fa9fb99cd597> in <module>()
----> 1 DrawRDKitBits(tuples, molsPerRow=8)

~/anaconda3/lib/python3.6/site-packages/rdkit/Chem/Draw/IPythonConsole.py in DrawRDKitBits(*args, **kwargs)
    256   else:
    257     fn = Draw.DrawRDKitBits
--> 258   return _DrawBit(fn, *args, **kwargs)
    259 DrawRDKitBits.__doc__ = Draw.DrawRDKitBits.__doc__
    260 

~/anaconda3/lib/python3.6/site-packages/rdkit/Chem/Draw/IPythonConsole.py in _DrawBit(fn, *args, **kwargs)
    200   if 'useSVG' not in kwargs:
    201     kwargs['useSVG'] = ipython_useSVG
--> 202   res = fn(*args, **kwargs)
    203   if kwargs['useSVG']:
    204     return SVG(res)

~/anaconda3/lib/python3.6/site-packages/rdkit/Chem/Draw/__init__.py in DrawRDKitBits(tpls, **kwargs)
    731     bondpath = bitInfo[bitId][whichExample]
    732     envs.append((mol, bondpath))
--> 733   return DrawRDKitEnvs(envs, **kwargs)
    734 
    735 def DrawRDKitBit(mol, bitId, bitInfo, whichExample=0, **kwargs):

~/anaconda3/lib/python3.6/site-packages/rdkit/Chem/Draw/__init__.py in DrawRDKitEnvs(envs, molsPerRow, subImgSize, baseRad, useSVG, aromaticColor, extraColor, nonAromaticColor, legends, **kwargs)
    825   drawer.DrawMolecules(submols, legends=legends, highlightAtoms=highlightAtoms,
    826                        highlightAtomColors=atomColors, highlightBonds=highlightBonds,
--> 827                        highlightBondColors=bondColors, highlightAtomRadii=highlightRadii, **kwargs)
    828   drawer.FinishDrawing()
    829   return drawer.GetDrawingText()

ValueError: Sanitization error: Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4

I think that imidazole is caused by not being able to kekulize if it does not have hydrogen.

mol = Chem.MolFromSmiles('c1cncn1')

result:

RDKit ERROR: [06:51:21] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4
RDKit ERROR: 
@greglandrum greglandrum added this to the 2018_09_2 milestone Nov 13, 2018
@greglandrum
Copy link
Member

Confirmed.
A bit more specific about what is causing the problem:

mol = Chem.MolFromSmiles('c1cncn(C)1')
bi = {}
_ = AllChem.RDKFingerprint(mol, minPath=1, maxPath=5, bitInfo=bi)
tuples = [(mol, k, bi) for k in bi.keys()]
DrawRDKitBits((tuples[38],))

@greglandrum
Copy link
Member

Here's a reproducible of the root cause, which is a kekulization failure caused by the PathToSubmol() call.

mol = Chem.MolFromSmiles('c1cncn(C)1')
bondPath = [0, 1, 2, 3, 5]
submol = Chem.PathToSubmol(mol, bondPath)
submol.UpdatePropertyCache()
submol.Debug()
Chem.Kekulize(submol)

@greglandrum greglandrum modified the milestones: 2018_09_2, 2018_09_3 Feb 21, 2019
@greglandrum greglandrum modified the milestones: 2018_09_3, 2018_09_4 Mar 26, 2019
@greglandrum greglandrum removed this from the 2018_09_4 milestone Jan 14, 2023
greglandrum added a commit to greglandrum/rdkit that referenced this issue Jan 14, 2023
greglandrum added a commit that referenced this issue Jan 16, 2023
* Fixes #5974
Fixes #2164
Fixes #5971

* change in response to review
plus switch off the logging while kekulizing
greglandrum added a commit that referenced this issue Jan 16, 2023
* Fixes #5974
Fixes #2164
Fixes #5971

* change in response to review
plus switch off the logging while kekulizing
@greglandrum greglandrum added this to the 2023_03_1 milestone Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants