Hi,

Today I checked out the lastest version from the svn.  I took only the 
trunk and built this and ran a python script I used with a previous 
version to depict a molecule.  However, I received the following error:

AttributeError: type object 'MolDrawing' has no attribute 'registerCanvas'


I did the following in the python script much like the people at cinfony 
do to depict with aggdraw:

import os, sys, copy
from rdkit.Chem import rdDepictor
from rdkit import Geometry

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem.Draw import MolDrawing
from rdkit.Chem.AvailDescriptors import descDict

import rdkit.DataStructs
import rdkit.Chem.MACCSkeys
import rdkit.Chem.AtomPairs.Pairs
import rdkit.Chem.AtomPairs.Torsions

# PIL and Tkinter
try:
     import Tkinter as tk
     import Image as PIL
     import ImageTk as PILtk
except:
     PILtk = None

# Aggdraw
try:
     import aggdraw
except ImportError:
     aggdraw = None


def draw(Mol, show=True, filename=None, update=False, usecoords=False, 
width=300, height=300, background='white', atoms='color'):
     """Create a 2D depiction of the molecule.  This method was taken 
from cinfony.

     Optional parameters:
       show -- display on screen (default is True)
       filename -- write to file (default is None)
       update -- update the coordinates of the atoms to those
                 determined by the structure diagram generator
                 (default is False)
       usecoords -- don't calculate 2D coordinates, just use
                    the current coordinates (default is False)

     Aggdraw is used for 2D depiction. Tkinter and
     Python Imaging Library are required for image display.
     Python code found at:  /usr/local/RDKit_2010_12_1/rdkit
     """
     if usecoords:
         confId = 0
     else:
         if update:
             AllChem.Compute2DCoords(Mol)
             confId = 0
         else:
             confId = Mol.GetNumConformers()
             AllChem.Compute2DCoords(Mol, clearConfs = False)
     if show or filename:
         if not aggdraw:
             errormessage = ("Aggdraw not found, but is required for 2D"
                             "structure depiction. "
                             "See installation instructions for more "
                             "information.")
             raise ImportError, errormessage

         Chem.Kekulize(Mol)
         MolDrawing.registerCanvas('agg')
     import pdb;pdb.set_trace()
         img = PIL.new("RGBA",(width,height),background)
         canvas = aggdraw.Draw(img)
         canvas.setantialias(True)
         drawer = MolDrawing.MolDrawing(canvas)
     MolDrawing.elemDict
     if atoms == 'color' and background == 'white' :
         print 'Color on white'
         MolDrawing.elemDict[6] = (0,0,0)
     elif atoms == 'color' and background == 'black':
         print 'Color on black'
         MolDrawing.elemDict[6] = (1,1,1)
     elif atoms == 'white' and background == 'black':
         print 'White on black'
         MolDrawing.elemDict = {
         16: (0,0,0),
         17: (0,0,0),
         35: (0,0,0),
         6: (1,1,1),
         0: (0,0,0),
         7: (0,0,0),
         8: (0,0,0),
         9: (0,0,0),
         15: (0,0,0)
         }
     elif atoms == 'black' and background == 'white':
         print 'Black on white'
         MolDrawing.elemDict = {
         16: (0,0,0),
         17: (0,0,0),
         35: (0,0,0),
         6: (0,0,0),
         0: (0,0,0),
         7: (0,0,0),
         8: (0,0,0),
         9: (0,0,0),
         15: (0,0,0)
         }
         drawer.wedgeDashedBonds = True
     drawer.bondLineWidth = 2.5
         drawer.AddMol(Mol, confId = confId)
         canvas.flush()

         if filename: # Note: overwrite is allowed
             img.save(filename)
         if show:
             if not tk:
                 errormessage = ("Tkinter or Python Imaging "
                                 "Library not found, but is required for 
image "
                                 "display. See installation instructions 
for "
                                 "more information.")
                 raise ImportError, errormessage
             root = tk.Tk()
             root.title((hasattr(Mol, "title") and Mol.title)
                        or Mol.__str__().rstrip())
             frame = tk.Frame(root, colormap="new", 
visual='truecolor').pack()
             imagedata = PILtk.PhotoImage(img)
             label = tk.Label(frame, image=imagedata).pack()
             quitbutton = tk.Button(root, text="Close", 
command=root.destroy).pack(fill=tk.X)
             root.mainloop()
         Chem.SanitizeMol(Mol)



Sorry for all the code, but I think much of it is relevant so I pasted 
it here.

Is the registerCanvas method removed from newer version?  If so how can 
I modify my Draw function so that it will work with the newest version 
from svn?

Thank you for any help.

Don





------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to