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

KekulizeException of molecule from Smarts pattern with new RDKit release #5156

Closed
schallerdavid opened this issue Apr 1, 2022 · 2 comments
Closed
Labels
Milestone

Comments

@schallerdavid
Copy link

Describe the bug
With the new release of RDKit (2022.03.1) we observed a KekulizeException that was not thrown by the previous RDKit release (2021.09.5), which prevents the rendering of a certain Smarts pattern with the Draw.MolsToGridImage functionality.

To Reproduce

from rdkit import Chem
mol = Chem.MolFromSmarts("[#6](:,-[#6]-,:[#7]-,:[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1):,-[#6]:,-[#7]:,-[#6]")
Chem.Kekulize(m1)

Expected behavior
Both version behave consistent.

Configuration (please complete the following information):

  • RDKit versions: 2022.03.1 and 2021.09.5
  • OS: Ubuntu 20.04, MacOS, Windows
  • Python 3.7 - 3.9
  • Are you using conda? yes
  • If you are using conda, which channel did you install the rdkit from? conda-forge

Additional context
If the KekulizeException is correctly thrown for this Smarts pattern in the new RDKit version, it would be great to still be able to visualize it with Draw.MolsToGridImage. However, I cannot find a possibility to prevent the kekulization of the given molecules in this function, so the KekulizeError always gets thrown.

Thanks in a advance,
David

@greglandrum
Copy link
Member

Hi @schallerdavid thanks for the bug report. I'll take a look and see if I can figure out what's going on and how to fix it

@greglandrum greglandrum added this to the 2022_03_2 milestone Apr 7, 2022
@ptosco
Copy link
Contributor

ptosco commented Apr 7, 2022

@schallerdavid to visualize all molecules including those failing to kekulize, you can try the following:

from rdkit import Chem
from rdkit.Chem.Draw import rdMolDraw2D, MolsToGridImage

mol_fails = Chem.MolFromSmarts("[#6](:,-[#6]-,:[#7]-,:[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1):,-[#6]:,-[#7]:,-[#6]")
mol_succeeds = Chem.MolFromSmiles("c1ccccn1")

drawOptions = rdMolDraw2D.MolDrawOptions()
drawOptions.prepareMolsBeforeDrawing = False

def prepare_mol(mol):
    try:
        mol_draw = rdMolDraw2D.PrepareMolForDrawing(mol)
    except Chem.KekulizeException:
        mol_draw = rdMolDraw2D.PrepareMolForDrawing(mol, kekulize=False)
        Chem.SanitizeMol(mol_draw, Chem.SANITIZE_ALL ^ Chem.SANITIZE_KEKULIZE)
    return mol_draw

drawOptions = rdMolDraw2D.MolDrawOptions()
drawOptions.prepareMolsBeforeDrawing = False

mols = [mol_succeeds, mol_fails]

MolsToGridImage([prepare_mol(mol) for mol in mols], drawOptions=drawOptions)
[16:56:10] Can't kekulize mol.  Unkekulized atoms: 3

image

@greglandrum greglandrum modified the milestones: 2022_03_2, 2022_03_3 Apr 25, 2022
@greglandrum greglandrum modified the milestones: 2022_03_3, 2022_03_4 Jun 1, 2022
@greglandrum greglandrum modified the milestones: 2022_03_4, 2022_03_5 Jul 5, 2022
greglandrum added a commit to greglandrum/rdkit that referenced this issue Jul 8, 2022
prepareMolForDrawing() was being called for mols without coords even if the option was disabled
This resolves that
greglandrum added a commit that referenced this issue Aug 4, 2022
* make 2D coord gen more robust w.r.t. sanitization

* Fixes #5156

prepareMolForDrawing() was being called for mols without coords even if the option was disabled
This resolves that

* update expected hashes
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

3 participants