Re: [Rdkit-discuss] MolToImageFile issues
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Greg L. <gre...@gm...> - 2008-09-15 21:14:03
|
Dear Peter, On Mon, Sep 15, 2008 at 3:57 PM, Peter Harley <pj...@ca...> wrote: > Hi, > > I've been using RDkit to draw png files successfully until recently I found > some molecules that it seems to struggle with. I was hoping you could shed > some light on this: > >>>> import Chem >>>> from Chem import Draw >>>> mol = Chem.MolFromSmiles(r'O=C/C=C/c1ccccc1') >>>> Draw.MolToImageFile(mol, 'test.png') > > Traceback (most recent call last): > File "<pyshell#9>", line 1, in <module> > Draw.MolToImageFile(mol, 'test.png') > File "C:\rdkit\Python\Chem\Draw\__init__.py", line 48, in MolToImageFile > img = MolToImage(mol,size=size,kekulize=kekulize,wedgeBonds=wedgeBonds) > File "C:\rdkit\Python\Chem\Draw\__init__.py", line 39, in MolToImage > AllChem.Compute2DCoords(mol) > RuntimeError: Pre-condition Violation > >>>> Draw.MolToImageFile(mol, 'test.png', kekulize=False) > > It appears that its the kekulizing that causes it to fail, but I can't > really see why. Maybe this should be filed as a bug? It actually seems to be in the code that generates 2D coordinates and is somehow connected with the way the molecule is copied before being kekulized. Here's a walk through of two of the steps in MolToImageFile: [20] >>> mol = Chem.MolFromSmiles(r'O=C/C=C/c1ccccc1') [21] >>> m2 = Chem.Mol(mol.ToBinary()) [22] >>> AllChem.Compute2DCoords(m2) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) c:\glandrum\<ipython console> in <module>() RuntimeError: Pre-condition Violation The problem is caused by the direction indications on the bonds: [26] >>> mol = Chem.MolFromSmiles(r'O=C/C=C/C') [27] >>> m2 = Chem.Mol(mol.ToBinary()) [28] >>> AllChem.Compute2DCoords(m2) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) c:\glandrum\<ipython console> in <module>() RuntimeError: Pre-condition Violation [29] >>> mol = Chem.MolFromSmiles(r'O=CC=CC') [30] >>> m2 = Chem.Mol(mol.ToBinary()) [31] >>> AllChem.Compute2DCoords(m2) Out[31]: 0 Thanks for reporting this, I will file it as a bug and get it fixed. -greg |