Dear Peter,

On Mon, Sep 15, 2008 at 3:57 PM, Peter Harley <[email protected]> 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

Reply via email to