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

Draw.MolToImage(mol) does not work for Python 3, because cairo for Python 3 has not yet implemented Surface.create_for_data #460

Closed
apahl opened this issue Mar 23, 2015 · 0 comments
Labels
Milestone

Comments

@apahl
Copy link
Contributor

apahl commented Mar 23, 2015

Hi,

I'm playing around with RDKit and Python 3 to prepare my planned complete switch to Py3 (drumroll...) and stumbled upon the above mentioned error:

Steps to reproduce (latest RDKit git master compiled for Python 3):

In [1]: from rdkit.Chem import AllChem as Chem
   ...: from rdkit.Chem import Draw
   ...: from rdkit.Chem.Draw import IPythonConsole
   ...: Draw.DrawingOptions.atomLabelFontFace = "DejaVu Sans"
   ...: Draw.DrawingOptions.atomLabelFontSize = 18
In [2]: mol = Chem.MolFromSmiles("c1ccccc1O")
In [7]: Draw.MolToImage(mol)

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-7-761f43a1d43c> in <module>()
----> 1 Draw.MolToImage(mol)

/home/apl/progs/RDKit/rdkit/Chem/Draw/__init__.py in MolToImage(mol, size, kekulize, wedgeBonds, fitImage, options, canvas, **kwargs)
     92     raise ValueError('Null molecule provided')
     93   if canvas is None:
---> 94     img,canvas=_createCanvas(size)
     95   else:
     96     img=None

/home/apl/progs/RDKit/rdkit/Chem/Draw/__init__.py in _createCanvas(size)
     48       from PIL import Image
     49     img = Image.new("RGBA",size,(0,0,0,0))
---> 50     canvas = Canvas(img)
     51   else:
     52     from rdkit.Chem.Draw.spingCanvas import Canvas

/home/apl/progs/RDKit/rdkit/Chem/Draw/cairoCanvas.py in __init__(self, image, size, ctx, imageType, fileName)
     74       surface = cairo.ImageSurface.create_for_data (
     75         a, cairo.FORMAT_ARGB32,
---> 76         image.size[0], image.size[1], stride)
     77       ctx = cairo.Context(surface)
     78       size=image.size[0], image.size[1]

NotImplementedError: Surface.create_for_data: Not Implemented yet.

Also, calling the object in a IPython 3 qtconsole or notebook does not give the rendered image of the structure but just the general Python object information:

In [12]: mol
Out[12]: <rdkit.Chem.rdchem.Mol at 0x7f37bfaef730>

draw to file works as expected:

In [12]: Draw.MolToFile(mol, "test.png")

test

All the best,
Axel

greglandrum added a commit that referenced this issue May 16, 2015
Fix mol drawing on Python3 (issue #460)
@apahl apahl closed this as completed Jun 2, 2015
@greglandrum greglandrum added the bug label Jun 4, 2015
@greglandrum greglandrum added this to the 2015_09_1 milestone Jun 4, 2015
sriniker pushed a commit to sriniker/rdkit that referenced this issue Oct 20, 2015
…t seem to be quite there, yet

* this hack fixes issue rdkit#460 by trying to use cairocffi when running on Python3 and cairo when running on Python2
* tested for both Python versions
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