Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
Consider the following excerpt: svg = drawer.GetDrawingText() svg2 = svg.replace('svg:','') svg3 = SVG(svg2) print 'displaying svg:' display(svg) print 'displaying svg2:' display(svg2) print 'displaying svg3:' display(svg3) svg and svg2 display as xml text. svg3 displays as the image, in a Jupyter notebook in Chrome. On Mon, Oct 24, 2016 at 6:44 PM, Dimitri Maziuk wrote: > On 10/24/2016 04:39 PM, Peter S. Shenkin wrote: > > > Or is it > > rather because chemists in your target audience will be thinking of the > > first atom in, say, a structure from an sd file as atom #1? > > That > > > 2. Regarding the last line, most of the RDKit code I've seen in past > > examples displays the molecule using code like the following. When is it > > necessary/not necessary to remove the "svg" string from the results of > > GetDrawingText()? > > Not sure: it's a namespace, I'm assuming ipython can't deal with xml > namespaces. Properly written programs should show it either way, > unfortunately my target viewer is firefox (it's a web application and > the user's default browser is firefox) and firefox isn't one of them. > Without svg:'s it'll show the file as xml text instead of the image. > > HTH > -- > Dimitri Maziuk > Programmer/sysadmin > BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu > > -- The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
On 10/24/2016 04:39 PM, Peter S. Shenkin wrote: > Or is it > rather because chemists in your target audience will be thinking of the > first atom in, say, a structure from an sd file as atom #1? That > 2. Regarding the last line, most of the RDKit code I've seen in past > examples displays the molecule using code like the following. When is it > necessary/not necessary to remove the "svg" string from the results of > GetDrawingText()? Not sure: it's a namespace, I'm assuming ipython can't deal with xml namespaces. Properly written programs should show it either way, unfortunately my target viewer is firefox (it's a web application and the user's default browser is firefox) and firefox isn't one of them. Without svg:'s it'll show the file as xml text instead of the image. HTH -- Dimitri Maziuk Programmer/sysadmin BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu signature.asc Description: OpenPGP digital signature -- The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
Hi, Dimitri, I have two questions about your code. 1. Why are you incrementing the atom index by 1? Are there functions in RDKit, for example, that use atom indices using index-origin 1? Or is it rather because chemists in your target audience will be thinking of the first atom in, say, a structure from an sd file as atom #1? 2. Regarding the last line, most of the RDKit code I've seen in past examples displays the molecule using code like the following. When is it necessary/not necessary to remove the "svg" string from the results of GetDrawingText()? svg = drawer.GetDrawingText().replace('svg:','') SVG(svg) Thanks, -P. On Mon, Oct 24, 2016 at 2:31 PM, Dimitri Maziuk wrote: > Since you already got your answer I'll just post this for posterity: > > > import sys > import rdkit > import rdkit.Chem > import rdkit.Chem.AllChem > import rdkit.Chem.Draw > import rdkit.Chem.Draw.rdMolDraw2D > > mol=rdkit.Chem.SupplierFromFilename(sys.argv[1],removeHs=False).next() > dr=rdkit.Chem.Draw.rdMolDraw2D.MolDraw2DSVG(800,800) > dr.SetFontSize(0.3) > op = dr.drawOptions() > for i in range(mol.GetNumAtoms()) : > op.atomLabels[i]=mol.GetAtomWithIdx(i).GetSymbol() + str((i+1)) > rdkit.Chem.AllChem.Compute2DCoords(mol) > dr.DrawMolecule(mol) > dr.FinishDrawing() > svg=dr.GetDrawingText() > > > -- > Dimitri Maziuk > Programmer/sysadmin > BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu > > > > -- > 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 > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > > -- The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
Since you already got your answer I'll just post this for posterity: import sys import rdkit import rdkit.Chem import rdkit.Chem.AllChem import rdkit.Chem.Draw import rdkit.Chem.Draw.rdMolDraw2D mol=rdkit.Chem.SupplierFromFilename(sys.argv[1],removeHs=False).next() dr=rdkit.Chem.Draw.rdMolDraw2D.MolDraw2DSVG(800,800) dr.SetFontSize(0.3) op = dr.drawOptions() for i in range(mol.GetNumAtoms()) : op.atomLabels[i]=mol.GetAtomWithIdx(i).GetSymbol() + str((i+1)) rdkit.Chem.AllChem.Compute2DCoords(mol) dr.DrawMolecule(mol) dr.FinishDrawing() svg=dr.GetDrawingText() -- Dimitri Maziuk Programmer/sysadmin BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu signature.asc Description: OpenPGP digital signature -- 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 Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
Hi, Hongbin, Thank you very much for your help. That worked! That blog entry is a great tutorial, in general. So it turned out that in the following test code, I had correctly figured out how to set atomLabels, but instead of the last two lines in my .ipynb I had just asserted "m". (How quickly we forget.. :-} ) Best, -P. rdDepictor.Compute2DCoords(m) drawer = rdMolDraw2D.MolDraw2DSVG(400, 200) drawer.drawOptions().atomLabels[0] = '0' drawer.DrawMolecule(m) drawer.FinishDrawing() svg = drawer.GetDrawingText().replace('svg:','') SVG(svg) On Sun, Oct 23, 2016 at 11:38 PM, 杨弘宾 wrote: > Hi,Peter S. Shenkin, > I think this blog may help you draw molecule with labels and it told > more about drawing with rdMolDraw2D. > http://rdkit.blogspot.com/2015/02/new-drawing-code.html > > -- > Hongbin Yang > > *From:* Peter S. Shenkin > *Date:* 2016-10-24 10:18 > *To:* Dimitri Maziuk ; RDKit Discuss > > *Subject:* [Rdkit-discuss] 2D drawing with atoms labeled by index > Hi, > > How do you get RDKit to label the atoms in a 2D drawing with their indices? > > There was some discussion of this that included Dimitri Maziuk in > September, but it wasn't clear to me whether he actually had to modify the > underlying drawing code to get this behavior. > > -P. > > -- 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 Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] 2D drawing with atoms labeled by index
Hi,Peter S. Shenkin, I think this blog may help you draw molecule with labels and it told more about drawing with rdMolDraw2D. http://rdkit.blogspot.com/2015/02/new-drawing-code.html Hongbin Yang From: Peter S. ShenkinDate: 2016-10-24 10:18To: Dimitri Maziuk; RDKit DiscussSubject: [Rdkit-discuss] 2D drawing with atoms labeled by indexHi, How do you get RDKit to label the atoms in a 2D drawing with their indices? There was some discussion of this that included Dimitri Maziuk in September, but it wasn't clear to me whether he actually had to modify the underlying drawing code to get this behavior. -P. -- 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 Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss