Hello,

I thought we had removed all of these by now. I'll open an issue and fix
the code.

Best,

Peter


On Tue, Dec 20, 2016 at 6:01 AM David Hall <li...@cowsandmilk.net> wrote:

> The replace and split methods were removed from the string module in
> python3. You can replace the code as follows:
>
>     s = s.replace('\r\n', '\n')
>     s = s.replace('\n\r', '\n')
>     s = s.replace('\r', '\n')
>     lines = s.split('\n')
>
>
> On Tue, Dec 20, 2016 at 2:45 AM, Pavel Polishchuk <
> pavel_polishc...@ukr.net> wrote:
>
> Hi,
>
>   I try to print multiline legends for molecules in a grid and use the
> following code from notebook
>
>   from rdkit import Chem
>   from rdkit.Chem import Draw
>   # from rdkit.Chem.Draw import IPythonConsole
>
>   mols = [Chem.MolFromSmiles(s) for s in ["CCC", "CCCCC"]]
>   legends = ["1\nCCC", "2\nCCCCC"]
>   Draw.MolsToGridImage(mols, molsPerRow=5, subImgSize=(200,200),
> legends=legends)
>
>   it returns error: AttributeError: module 'string' has no attribute
> 'replace' (full stack is below)
>
>   If I uncomment IPythonConsole import then it returns the picture with
> labels, but with spaces instead of new line symbols.
>
>   What can I do in this situation? RDKit 2016.03.2
>
> Kind regards,
> Pavel.
>
>
> ---------------------------------------------------------------------------AttributeError
>                             Traceback (most recent call 
> last)<ipython-input-2-684f4abceace> in <module>()      1 mols = 
> [Chem.MolFromSmiles(s) for s in ["CCC", "CCCCC"]]      2 legends = ["1\nCCC", 
> "2\nCCCCC"]----> 3 p = Draw.MolsToGridImage(mols, molsPerRow=5, 
> subImgSize=(200,200), legends=legends)
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/Chem/Draw/__init__.py
>  in MolsToGridImage(mols, molsPerRow, subImgSize, legends, 
> highlightAtomLists, useSVG, **kwargs)    387   else:    388       return 
> _MolsToGridImage(mols,molsPerRow=molsPerRow,subImgSize=subImgSize,--> 389     
>             legends=legends, highlightAtomLists=highlightAtomLists, **kwargs) 
>    390     391 def ReactionToImage(rxn, subImgSize=(200,200),**kwargs):
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/Chem/Draw/__init__.py
>  in _MolsToGridImage(mols, molsPerRow, subImgSize, legends, 
> highlightAtomLists, **kwargs)    334       highlights=highlightAtomLists[i]   
>  335     if mol is not None:--> 336       img = 
> _moltoimg(mol,subImgSize,highlights,legends[i],**kwargs)    337       
> res.paste(img,(col*subImgSize[0],row*subImgSize[1]))    338   return res
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/Chem/Draw/__init__.py
>  in _moltoimg(mol, sz, highlights, legend, **kwargs)    302     if not 
> hasattr(rdMolDraw2D,'MolDraw2DCairo'):    303         img = 
> MolToImage(mol,sz,legend=legend,highlightAtoms=highlights,--> 304             
>                  **kwargs)    305     else:    306         nmol = 
> rdMolDraw2D.PrepareMolForDrawing(mol,kekulize=kwargs.get('kekulize',True))
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/Chem/Draw/__init__.py
>  in MolToImage(mol, size, kekulize, wedgeBonds, fitImage, options, canvas, 
> **kwargs)    132     #                         
> color=(0,0,1),fill=False,stroke=True)    133     
> font=Font(face='sans',size=12)--> 134     
> canvas.addCanvasText(legend,pos,font)    135     136   if 
> kwargs.get('returnCanvas',False):
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/Chem/Draw/spingCanvas.py
>  in addCanvasText(self, text, pos, font, color, **kwargs)     72     labelP = 
> pos[0]-txtWidth/2+offset,pos[1]+txtHeight/2     73     color = 
> convertColor(color)---> 74     
> self.canvas.drawString(text,labelP[0],labelP[1],font,color=color)     75     
> return (bw,bh,offset)     76
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/sping/PIL/pidPIL.py
>  in drawString(self, s, x, y, font, color, angle, **kwargs)    313     if 
> '\n' in s or '\r' in s:    314       self.drawMultiLineString(s, x,y, font, 
> color, angle,--> 315                                **kwargs)    316       
> return    317     if not font: font = self.defaultFont
> /home/pavel/anaconda3/envs/my-rdkit-env/lib/python3.5/site-packages/rdkit/sping/pid.py
>  in drawMultiLineString(self, s, x, y, font, color, angle, **kwargs)    393   
>               dy = h * math.cos(angle*math.pi/180.0)    394                 
> dx = h * math.sin(angle*math.pi/180.0)--> 395                 s = 
> string.replace(s, '\r\n', '\n')    396                 s = string.replace(s, 
> '\n\r', '\n')    397                 s = string.replace(s, '\r', '\n')
> AttributeError: module 'string' has no attribute 'replace'
>
>
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today.http://sdm.link/intel
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today.http://sdm.link/intel
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to