Hi, greg,    DrawMolecules did not work in my compute, I guess it is a future 
feature from my version (v2016.3.1), isn't it?     And I tried your second 
suggestion but it still cracked.  Maybe the old version of MolDraw2D is buggy.
    The following are fake compouns for test, and each one is drawable.
# mycompounds.smiSMILESc1cccccc1[N+]([O-])=O    1CCC[N+]([O-])=O        
2CC[N+]([O-])=O 3C[N+]([O-])=O  4c1c(CC)cccc1[N+]([O-])=O       5
# codefrom rdkit import Chemfrom rdkit.Chem.Draw import rdMolDraw2Dfrom 
rdkit.Chem import Drawfrom rdkit.Chem import rdDepictorfrom rdkit.Chem import 
rdMolTransformsmols = 
Chem.SmilesMolSupplier('mycompounds.smi',delimiter='\t')len(mols)mols = 
list(mols)def centerMol(mol):    conf = mol.GetConformer()    pt = 
rdMolTransforms.ComputeCentroid(conf)    for i in range(conf.GetNumAtoms()):    
    conf.SetAtomPosition(i,conf.GetAtomPosition(i) - pt)        drawer = 
rdMolDraw2D.MolDraw2DSVG(400,400) smarts = Chem.MolFromSmarts('N(-O)=O')i=0 for 
mol in mols:     if not mol.HasSubstructMatch(smarts):        continue    
rdDepictor.Compute2DCoords(mol)    tm = Chem.Mol(mol)    centerMol(tm)    
drawer.FinishDrawing() svg = drawer.GetDrawingText().replace('svg:','') 

Hongbin Yang 

 From: Greg LandrumDate: 2017-02-18 12:59To: 杨弘宾CC: rdkit-discussSubject: Re: 
[Rdkit-discuss] jupyter cracked when drawing with "abnormal" operation of 

On Fri, Feb 17, 2017 at 6:31 AM, 杨弘宾 <yanyangh...@163.com> wrote:

Hi, everyone,    I want to draw two molecules in a svg file with rdMolDraw2D. 
When I executed the following code, the jupyter cracked without any error or 
warning.```drawer = rdMolDraw2D.MolDraw2DSVG(400,400)


for mol in mols:

  if mol.HasSubstructMatch(smarts):

    rdDepictor.Compute2DCoords(mol)     #if i == 1:    #  continue


    if i > 1:



svg = drawer.GetDrawingText().replace('svg:','')

It seems that we cannot directly draw two molecules with the same drawer? So 
how can I draw as I wanted?
Do you want to draw the molecules on top of each other (somewhat problematic at 
the moment, but doable) or in a grid?If you want to have them in a grid, the 
solution is:
drawer = rdMolDraw2D.MolDraw2DSVG(400,400,200,200) p = 
 svg = drawer.GetDrawingText().replace('svg:','') 
That's an overall image size of 400x400 with 200x200 panes for the individual 
molecules. At the moment molecular highlighting does not work when you do this 
(there's a github item for that here: 
If you want to put them on top of each other, what you show above should kind 
of work. You probably should center each of the molecules first though:
from rdkit.Chem import rdMolTransformsdef centerMol(mol):    conf = 
mol.GetConformer()    pt = rdMolTransforms.ComputeCentroid(conf)    for i in 
conf.SetAtomPosition(i,conf.GetAtomPosition(i) - pt)        drawer = 
rdMolDraw2D.MolDraw2DSVG(400,400) p = Chem.MolFromSmarts('c1ccccn1')i=0 for mol 
in mols:     tm = Chem.Mol(mol)    centerMol(tm)    
drawer.DrawMolecule(tm,highlightAtoms=tm.GetSubstructMatch(p))     i+=1     if 
i > 1:       break drawer.FinishDrawing() svg = 
Note that this can end up being somewhat ugly since the drawing code will 
determine the scaling factors to make the molecules fit in the canvas from the 
first molecule.
I think it is fixable by adding some additional logic to DrawMolecules() but 
I'm going to have to look into it. that's this item in github: 

By the way, I've no idea why it cracked. From the experiment of the commented 
code, I can conclude it was caused by the drawer. So is it possible to fix the 
bug, adding error or warning instead of "KernelRestarter: restarting kernel" in 
I can't reproduce a crash there. Which version of the RDKit are you using?

Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Rdkit-discuss mailing list

Reply via email to