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

drawReaction() should not hit a PRECONDITION with prepareMolsBeforeDrawing=false #5259

Closed
ptosco opened this issue May 4, 2022 · 0 comments
Assignees
Labels
Milestone

Comments

@ptosco
Copy link
Contributor

ptosco commented May 4, 2022

Describe the bug
When MolDrawOptions.prepareMolsBeforeDrawing is set to false the code hits a PRECONDITION.
The problem arises when DrawMol::getAtomSymbol() calls Atom::getTotalNumHs() as implicit valence has not been computed yet.
The fix is simple: it is sufficient to move mol.updatePropertyCache(false) out of the if (drawOptions().prepareMolsBeforeDrawing) {} clause in MolDraw2D::makeReactionDrawMol()`.

To Reproduce

from rdkit import Chem
from rdkit.Chem import rdChemReactions
from rdkit.Chem.Draw import rdMolDraw2D, IPythonConsole

rxn = rdChemReactions.ReactionFromSmarts('[CH3:1]-[OH:2]>>[CH2:1]=[OH0:2]')
d2d = rdMolDraw2D.MolDraw2DSVG(800, 300)
d2d.drawOptions().prepareMolsBeforeDrawing = False
d2d.DrawReaction(rxn)
[09:39:33] 

****
Pre-condition Violation
getNumImplicitHs() called without preceding call to calcImplicitValence()
Violation occurred on line 297 in file /scratch/toscopa1/src/rdkit/Code/GraphMol/Atom.cpp
Failed Expression: d_implicitValence > -1
****

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_242993/2731136680.py in <module>
      2 d2d = rdMolDraw2D.MolDraw2DSVG(800, 300)
      3 d2d.drawOptions().prepareMolsBeforeDrawing = False
----> 4 d2d.DrawReaction(rxn)
      5 #d2d.FinishDrawing()
      6 #svg = d2d.GetDrawingText()

RuntimeError: Pre-condition Violation
	getNumImplicitHs() called without preceding call to calcImplicitValence()
	Violation occurred on line 297 in file Code/GraphMol/Atom.cpp
	Failed Expression: d_implicitValence > -1
	RDKIT: 2022.09.1pre
	BOOST: 1_74

Expected behavior
drawReaction() should not fail because a PRECONDITION is hit.

@ptosco ptosco added the bug label May 4, 2022
@ptosco ptosco self-assigned this May 4, 2022
ptosco pushed a commit to ptosco/rdkit that referenced this issue May 4, 2022
@ptosco ptosco mentioned this issue May 4, 2022
ptosco pushed a commit to ptosco/rdkit that referenced this issue May 4, 2022
@greglandrum greglandrum added this to the 2022_03_3 milestone May 5, 2022
greglandrum pushed a commit that referenced this issue Jun 2, 2022
Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
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