rdkit
rdkit copied to clipboard
Can't kekulize (sanitized!) mol in DrawMorganBit
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
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 (?)