rdkit icon indicating copy to clipboard operation
rdkit copied to clipboard

Can't kekulize (sanitized!) mol in DrawMorganBit

Open eguidotti opened this issue 3 years ago • 1 comments

Describe the bug I'm trying to plot a fingerprint with DrawMorganBit. I found a few cases where DrawMorganBit fails to kekulize the molecule, but the molecule is kekulized successufly by Chem.MolFromSmiles. Please see below to reproduce the issue

To Reproduce

from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint

smiles = "CCCn1ccc(-c2cc(-c3ncc(C)cn3)n3cc(NC(=O)NCC)nc3c2)cc1=O"
mol = Chem.MolFromSmiles(smiles) # success
Chem.SanitizeMol(mol) # success 

info = {}
GetMorganFingerprint(mol, radius=2, bitInfo=info)
fingerprint = 1614124742
print(info[fingerprint]) # prints: ((9, 2),)

Draw.DrawMorganBit(mol, fingerprint, info) # -> fails: Can't kekulize mol

Expected behavior I would expect that DrawMorganBit completes succesfully

Configuration (please complete the following information):

  • RDKit version: '2021.09.5'
  • OS: MacOS
  • Python version (if relevant): 3.8.12
  • Are you using conda? No
  • If you are not using conda: how did you install the RDKit? pip install rdkit-pypi

eguidotti avatar Mar 24 '22 13:03 eguidotti

I found a solution, that is, disable drawOptions.prepareMolsBeforeDrawing:

drawOptions = Draw.rdMolDraw2D.MolDrawOptions()
drawOptions.prepareMolsBeforeDrawing = False
Draw.DrawMorganBit(mol, fingerprint, info, useSVG=True, drawOptions=drawOptions)

It seems that DrawMorganBit is kekulizing the fingerprint (not the molecule) before drawing. I wonder whether this is intended (?)

eguidotti avatar Mar 29 '22 15:03 eguidotti