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

rdMolDraw2D, problems during generation of pictures from SMARTS, differences between Cairo and SVG #3572

Closed
wopozka opened this issue Nov 17, 2020 · 3 comments · Fixed by #3615
Labels
Milestone

Comments

@wopozka
Copy link

wopozka commented Nov 17, 2020

Configuration:
import rdkit
rdkit.version
-->

  • RDKit Version: 2020.09.1
  • Operating system: MacOSX Darwin
  • Python version (if relevant): 3.7
  • Are you using conda? Yes
  • If you are using conda, which channel did you install the rdkit from? rdkit
  • If you are not using conda: how did you install the RDKit?

Description:

I would like to generate pictures for some SMARTS definitions using rdMolDraw2D. I found that for some SMARTS it is not possible to generate pictures using Cairo, as it ends up with kekulization error. The same procedure using SVG as is succesful. Setting parameters like prepareMolsBeforeDrawing = False, or PrepareMolForDrawing(mol, kekulize=False), does not help and ends up with the same error. Example code below

  1. Working code for SVG engine
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
import rdkit
print(rdkit.__version__)
mol = Chem.MolFromSmarts('c[N+]#[N]')
d2d = rdMolDraw2D.MolDraw2DSVG(300, 300)
d2d.DrawMolecule(mol)
d2d.FinishDrawing()
SVG(d2d.GetDrawingText())

image

  1. The same for Cairo
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
import rdkit
print(rdkit.__version__)
mol = Chem.MolFromSmarts('c[N+]#[N]')
d2d = rdMolDraw2D.MolDraw2DCairo(300, 300)
d2d.DrawMolecule(mol)
d2d.FinishDrawing()

end up with error:
RDKit ERROR: [17:49:00] non-ring atom 0 marked aromatic

It does not work even if I try to switch preparation of molecule before drawing

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
import rdkit
print(rdkit.__version__)
mol = Chem.MolFromSmarts('c[N+]#[N]')
d2d = rdMolDraw2D.MolDraw2DCairo(300, 300)
d2d.prepareMolsBeforeDrawing = False
Options = d2d.drawOptions()
Options.prepareMolsBeforeDrawing = False
d2d.SetDrawOptions(Options)
mol1 = rdMolDraw2D.PrepareMolForDrawing(mol, kekulize=False)
mol1.UpdatePropertyCache(False)
d2d.DrawMolecule(mol1)
d2d.FinishDrawing()

RDKit ERROR: [17:52:50] non-ring atom 0 marked aromatic

@DavidACosgrove
Copy link
Collaborator

The difference is that the Cairo drawer calls addMoleculeMetadata and the exception is being thrown from there. So it's not a drawing error as such.

@greglandrum
Copy link
Member

greglandrum commented Nov 26, 2020

@wopozka , the comment from @DavidACosgrove is correct.
Until we fix the problem (which is a bug), you can work around it by disabling the code which writes metadata to the PNG Options.includeMetadata = False

@greglandrum greglandrum added this to the 2020_09_3 milestone Nov 26, 2020
@wopozka
Copy link
Author

wopozka commented Dec 3, 2020

@greglandrum, thanks for the valuable advice. As I can use svg that is not a problem for me. I just noticed strange behaviour during png generation and then switched to svg.

@greglandrum greglandrum linked a pull request Dec 5, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants