I now have this working, and I'm incredibly close to my goal: saving an
image file as a StringIO object, and then rendering it on the fly using PIL.

However, if I use

f = StringIO()

Draw.MolToImageFile(mol, f)
>

I get a KeyError, "unknown extension." This makes sense--PIL's Image module
does not know what filetype to save the image as. So I figured I'd try the
function SmilesToJpeg from DrawUtils, but when I try to import DrawUtils, I
get:

In [27]: from Draw import DrawUtils
> ------------------------------------------------------------
>    File "/usr/lib/python2.6/dist-packages/rdkit/sping/PDF/pidPDF.py", line
> 27
>      from rdkit import sping.pagesizes
>                             ^
> SyntaxError: invalid syntax
>

Anyway, I need either to get this SmilesToJpeg (or MolsToJpeg) function
working, or figure out some way to tell MolToImageFile to use a specific
filetype, ideally png.

Let me know what you recommend.

-Ari

On Thu, Jul 9, 2009 at 11:18 PM, Greg Landrum <[email protected]>wrote:

> Hi Ari,
>
> On Thu, Jul 9, 2009 at 11:09 PM, Aryeh
> Gold-Parker<[email protected]> wrote:
> >>
> >>
> >> /usr/lib/python2.6/dist-packages/rdkit/Chem/Draw/aggCanvas.py in
> >> addCanvasText(canvas, text, pos, font, color, **kwargs)
> >>      72 def addCanvasText(canvas,text,pos,font,color=(0,0,0),**kwargs):
> >>      73   color = convertColor(color)
> >> ---> 74   font = Font(color,faceMap[font.face],size=font.size)
> >>      75   w,h=canvas.textsize(text,font)
> >>      76   bw,bh=w*1.1,h*1.1
> >>
> >> IOError: cannot load font
> >
> >
> > Aggdraw was compiled with freetype support (at least it should have
> been). I
> > have the libraries installed, and pointed aggdraw's setup.py to /usr.
> >
> > Why would I be getting this problem?
>
> The handling of the fonts in aggCanvas.py is not really optimal (as
> you see). At the moment it's hard coded to use
> $RDBASE/rdkit/Chem/Draw/FreeSans.ttf; this isn't really what it should
> be doing (ideally it would try to figure out the location of the
> system ttf directory(ies)), but it does work so long as RDBASE is set
> correctly.
> What you might try is editing aggCanvas.py and replacing:
>
>  
> faceMap={'sans':os.path.join(RDConfig.RDCodeDir,'Chem','Draw','FreeSans.ttf')}
> with:
>  faceMap={'sans':os.path.join(os.path.dirname(__file__),'FreeSans.ttf')}
>
> -greg
>

Reply via email to