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

DrawMorganBit fails by default #5863

Closed
eguidotti opened this issue Dec 11, 2022 · 1 comment
Closed

DrawMorganBit fails by default #5863

eguidotti opened this issue Dec 11, 2022 · 1 comment
Labels
Milestone

Comments

@eguidotti
Copy link
Contributor

I'm trying to visualise fingerprints with DrawMorganBit but an error occurs when prepareMolsBeforeDrawing=True (the default) and stereochemistry is not displayed when prepareMolsBeforeDrawing=False. To reproduce:

  1. Generate the fingerprints for a molecule and plot the molecule
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint

smiles = "C[C@]12C[C@H](O)[C@H]3[C@@H](CCC4=CC(=O)C=C[C@@]43C)[C@@H]1CC[C@]2(O)C(=O)CO"
mol = Chem.MolFromSmiles(smiles)

info = {}
GetMorganFingerprint(mol, radius=2, bitInfo=info, useChirality=True)
fingerprint = 1236726849

mol

Unknown

  1. plot the fingerprint setting prepareMolsBeforeDrawing=False -> OK but does not display stereochemistry
drawOptions = Draw.rdMolDraw2D.MolDrawOptions()
drawOptions.prepareMolsBeforeDrawing = False
Draw.DrawMorganBit(mol, fingerprint, info, drawOptions=drawOptions)

Unknown

  1. plot the fingerprint by default -> FAILS
Draw.DrawMorganBit(mol, fingerprint, info)
[23:39:09] 

****
Invariant Violation
no eligible neighbors for chiral center
Violation occurred on line 240 in file /Users/runner/work/rdkit-pypi/rdkit-pypi/build/temp.macosx-11.0-arm64-cpython-39/rdkit/Code/GraphMol/FileParsers/MolFileStereochem.cpp
Failed Expression: nbrScores.size()
****

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[16], line 1
----> 1 Draw.DrawMorganBit(mol, fingerprint, info)

File ~/Library/Caches/pypoetry/virtualenvs/drugpredictor-wS4XGoJo-py3.9/lib/python3.9/site-packages/rdkit/Chem/Draw/IPythonConsole.py:304, in DrawMorganBit(mol, bitId, bitInfo, drawOptions, **kwargs)
    302 else:
    303   fn = Draw.DrawMorganBit
--> 304 return _DrawBit(fn, mol, bitId, bitInfo, drawOptions=drawOptions, **kwargs)

File ~/Library/Caches/pypoetry/virtualenvs/drugpredictor-wS4XGoJo-py3.9/lib/python3.9/site-packages/rdkit/Chem/Draw/IPythonConsole.py:277, in _DrawBit(fn, *args, **kwargs)
    274 if 'useSVG' not in kwargs:
    275   kwargs['useSVG'] = ipython_useSVG
--> 277 res = fn(*args, **kwargs)
    278 if kwargs['useSVG']:
    279   return SVG(res)

File ~/Library/Caches/pypoetry/virtualenvs/drugpredictor-wS4XGoJo-py3.9/lib/python3.9/site-packages/rdkit/Chem/Draw/__init__.py:701, in DrawMorganBit(mol, bitId, bitInfo, whichExample, **kwargs)
    699 def DrawMorganBit(mol, bitId, bitInfo, whichExample=0, **kwargs):
    700   atomId, radius = bitInfo[bitId][whichExample]
--> 701   return DrawMorganEnv(mol, atomId, radius, **kwargs)

File ~/Library/Caches/pypoetry/virtualenvs/drugpredictor-wS4XGoJo-py3.9/lib/python3.9/site-packages/rdkit/Chem/Draw/__init__.py:865, in DrawMorganEnv(mol, atomId, radius, molSize, baseRad, useSVG, aromaticColor, ringColor, centerColor, extraColor, drawOptions, **kwargs)
    863 drawOptions.includeMetadata = False
    864 drawer.SetDrawOptions(drawOptions)
--> 865 drawer.DrawMolecule(menv.submol, highlightAtoms=menv.highlightAtoms,
    866                     highlightAtomColors=menv.atomColors, highlightBonds=menv.highlightBonds,
    867                     highlightBondColors=menv.bondColors, highlightAtomRadii=menv.highlightRadii,
    868                     **kwargs)
    869 drawer.FinishDrawing()
    870 return drawer.GetDrawingText()

RuntimeError: Invariant Violation
	no eligible neighbors for chiral center
	Violation occurred on line 240 in file Code/GraphMol/FileParsers/MolFileStereochem.cpp
	Failed Expression: nbrScores.size()
	RDKIT: 2022.03.5
	BOOST: 1_75

Expected behavior
The fingerprint should be plotted correctly by default, and preserve the stereochemistry of the parent molecule. From my understanding, DrawMorganBit should plot a zoom of the molecule on the fingerprint environment. But it seems some additional steps happen here that attempt to sanitize or modify the fingerprint environment before plotting

Configuration (please complete the following information):

  • RDKit version: 2022.03.5
  • OS: macOS
  • Python version (if relevant): 3.9
  • Are you using conda? No
  • If you are using conda, which channel did you install the rdkit from? pipit
  • If you are not using conda: how did you install the RDKit? pip install rdkit-pypi
@eguidotti eguidotti added the bug label Dec 11, 2022
@greglandrum
Copy link
Member

Confirmed the problem.

greglandrum added a commit to greglandrum/rdkit that referenced this issue Dec 15, 2022
we make the code more robust in cases where we can not wedge bonds
@greglandrum greglandrum added this to the 2022_09_4 milestone Dec 15, 2022
greglandrum added a commit that referenced this issue Jan 16, 2023
we make the code more robust in cases where we can not wedge bonds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants