Re: [Rdkit-discuss] rdMolDraw2D drawing code
On Tue, Sep 6, 2016 at 10:00 PM, Dimitri Maziukwrote: > On 09/05/2016 03:47 AM, Greg Landrum wrote: > > Dave's right about the font size: it's expressed in whatever coordinates > > the molecule is being drawn in. > > I'd put Dave's explanation in the doc++ (?) comment on FontSize > get/setter in MolDraw2D: > http://www.rdkit.org/Python_Docs/rdkit.Chem.Draw. > rdMolDraw2D.MolDraw2D-class.html > > Right now they just say "float". If you're dealing with SVG output, font > sizes are px, em, and points, and you need a couple of tries to figure > them out. It's a minor thing. > > Pull requests with documentation tweaks/corrections are always welcome. > > I suspect the other part of Dmitri's question is about the way bonds are > > shortened so that they don't draw all the way through the atom labels. > > Yes, I think. It looks like there's more padding on the top and the > right, and less padding on the left and bottom. E.g. H39 in the attached > "all" version is the worst, but it is consistent in all 3. > > The other one on the "all" picture is that the bond to O21 isn't > shortened enough and there isn't much room left between 021 and O24. > > OTOH all three labels: H38, O21, H39 could be drawn without even > shortening the bonds if we could just move them up a little. (Well, H39 > could be just drawn without shortening the bond at all.) > > Last but not least, my starting point is a 3D MOL file and I call > rdkit.Chem.AllChem.Compute2DCoords( mh ) -- last thing before > DrawMolecule(). Attached CID112084.svg is the one generated without > AddHs(), notice how layout is very different on that one. > Yes, the layout will always be different when you are using different atoms. ;-) 2D depictions of non-trivial molecules that include H atoms have a tendency to be pretty crowded. This makes them a challenge for the coordinate generation algorithm. This is an example of that. I'm not sure that there's a good general solution, or if it's worth investing the time in trying to find one given that this is something of a special case. > > I've a suspicion that that layout might look better with all the Hs and > numbers added, than the one I get (the other 3 pictures). > > -- > Dimitri Maziuk > Programmer/sysadmin > BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu > > > -- > > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > > -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] rdMolDraw2D drawing code
PS. looking at this, it may have come out a little confusing, so I start with a 3D mol file and run it through rdkit.Chem.AllChem.Compute2DCoords() CID112084.svg is what comes out. Running rdkit.Chem.AddHs() before Compute2DCoords() generates the layout seen on other 3 pictures. CID112084.allh.svg is what comes out after AddHs(). CID112084.nonum.svg is what comes out after op = dr.drawOptions() for i in range( mh.GetNumAtoms() ) : op.atomLabels[i] = mh.GetAtomWithIdx( i ).GetSymbol() CID112084.all.svg is with the above loop changed to op.atomLabels[i] = mh.GetAtomWithIdx( i ).GetSymbol() + str ((i+1)) -- Dimitri Maziuk Programmer/sysadmin BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu signature.asc Description: OpenPGP digital signature -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] rdMolDraw2D drawing code
On 09/05/2016 03:47 AM, Greg Landrum wrote: > Dave's right about the font size: it's expressed in whatever coordinates > the molecule is being drawn in. I'd put Dave's explanation in the doc++ (?) comment on FontSize get/setter in MolDraw2D: http://www.rdkit.org/Python_Docs/rdkit.Chem.Draw.rdMolDraw2D.MolDraw2D-class.html Right now they just say "float". If you're dealing with SVG output, font sizes are px, em, and points, and you need a couple of tries to figure them out. It's a minor thing. > I suspect the other part of Dmitri's question is about the way bonds are > shortened so that they don't draw all the way through the atom labels. Yes, I think. It looks like there's more padding on the top and the right, and less padding on the left and bottom. E.g. H39 in the attached "all" version is the worst, but it is consistent in all 3. The other one on the "all" picture is that the bond to O21 isn't shortened enough and there isn't much room left between 021 and O24. OTOH all three labels: H38, O21, H39 could be drawn without even shortening the bonds if we could just move them up a little. (Well, H39 could be just drawn without shortening the bond at all.) Last but not least, my starting point is a 3D MOL file and I call rdkit.Chem.AllChem.Compute2DCoords( mh ) -- last thing before DrawMolecule(). Attached CID112084.svg is the one generated without AddHs(), notice how layout is very different on that one. I've a suspicion that that layout might look better with all the Hs and numbers added, than the one I get (the other 3 pictures). -- Dimitri Maziuk Programmer/sysadmin BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu signature.asc Description: OpenPGP digital signature -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] rdMolDraw2D drawing code
Dave's right about the font size: it's expressed in whatever coordinates the molecule is being drawn in. Cross-platform font handling is tough. Cross-platform, cross-toolkit font handling is even tougher. What's currently there seems to be an quasi-workable solution. I suspect the other part of Dmitri's question is about the way bonds are shortened so that they don't draw all the way through the atom labels. This is handled by a function in MolDraw2D that attempts to take into account the font size. It doesn't always succeed (see the comments above about font handling). It's easy enough to add an option that allows you to adjust the amount of padding that's used in that code. Here's the github issue: https://github.com/rdkit/rdkit/issues/1056 -greg On Mon, Sep 5, 2016 at 9:57 AM, David Cosgrovewrote: > HI Dmitri, > > Sorry for the delay replying. I assume that by 'add padding' you mean that > the code that generates the 2D drawing coordinates should take account of > the size of the labels and would, from your example, maybe open out the > C9-O23-C14 bond a bit so that O21 and O24 are further apart? If so, then I > can duck that one cheerfully as it's not part of the MolDraw2D code. The 2D > coordinates are generated in RDDepictor - MolDraw2D just uses the results > from that. Having just had a peer at $RDBASE/GraphMol/Depictor/Depictor.h, > it would seem as though adding a padding as you suggest might not be > straightforward, but I guess it might be possible to alter the distance > matrix that is being embedded in 2D to take account of atom label sizes. > The joy of open source projects is of course that you have the opportunity > to change things if you don't like how they're done at present. Maybe > something to think about at the UGM hackathon day? > > As you say, your best bet in the short term is probably to adjust the font > size in the drawing. MolDraw2D.h says that the font sizes are given "in > molecule coordinate units. That's probably Angstrom for RDKit" which in > reality means it's relative to a C-C bond in benzene of 1.5 units. This is > then changed internally to a value appropriate for the drawing engine that > is being used in a particular instance. If you can see a sensible place to > put this information in the documentation, feel free to send a changed > version to Greg for inclusion in the next release. I am struggling to find > any such documentation myself, and maybe that was your point ;-). > > Cheers, > Dave > > > On Fri, Sep 2, 2016 at 9:07 PM, Dimitri Maziuk > wrote: > >> Hi all, >> >> I finally got a round tuit for playing with the drawing code and I like >> it -- great job, thank you Greg and Dave and everyone who contributed. >> >> One question though: is it possible to add padding around atom labels? >> Or use some other trick to make the attached look less crowded? (Yes, I >> do want all Hs and all atom labels with numbers.) >> >> The best I can come up with is reduce the font size a little, that works >> fine. I think it'd be nice if the fine manual for MolDraw2D said what >> the units used by FontSize()/SetFontSize() are. >> >> So, any better ideas than just slightly smaller labels? >> >> TIA >> -- >> Dimitri Maziuk >> Programmer/sysadmin >> BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu >> >> >> -- >> >> ___ >> Rdkit-discuss mailing list >> Rdkit-discuss@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >> >> > > > -- > > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > > -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] rdMolDraw2D drawing code
HI Dmitri, Sorry for the delay replying. I assume that by 'add padding' you mean that the code that generates the 2D drawing coordinates should take account of the size of the labels and would, from your example, maybe open out the C9-O23-C14 bond a bit so that O21 and O24 are further apart? If so, then I can duck that one cheerfully as it's not part of the MolDraw2D code. The 2D coordinates are generated in RDDepictor - MolDraw2D just uses the results from that. Having just had a peer at $RDBASE/GraphMol/Depictor/Depictor.h, it would seem as though adding a padding as you suggest might not be straightforward, but I guess it might be possible to alter the distance matrix that is being embedded in 2D to take account of atom label sizes. The joy of open source projects is of course that you have the opportunity to change things if you don't like how they're done at present. Maybe something to think about at the UGM hackathon day? As you say, your best bet in the short term is probably to adjust the font size in the drawing. MolDraw2D.h says that the font sizes are given "in molecule coordinate units. That's probably Angstrom for RDKit" which in reality means it's relative to a C-C bond in benzene of 1.5 units. This is then changed internally to a value appropriate for the drawing engine that is being used in a particular instance. If you can see a sensible place to put this information in the documentation, feel free to send a changed version to Greg for inclusion in the next release. I am struggling to find any such documentation myself, and maybe that was your point ;-). Cheers, Dave On Fri, Sep 2, 2016 at 9:07 PM, Dimitri Maziukwrote: > Hi all, > > I finally got a round tuit for playing with the drawing code and I like > it -- great job, thank you Greg and Dave and everyone who contributed. > > One question though: is it possible to add padding around atom labels? > Or use some other trick to make the attached look less crowded? (Yes, I > do want all Hs and all atom labels with numbers.) > > The best I can come up with is reduce the font size a little, that works > fine. I think it'd be nice if the fine manual for MolDraw2D said what > the units used by FontSize()/SetFontSize() are. > > So, any better ideas than just slightly smaller labels? > > TIA > -- > Dimitri Maziuk > Programmer/sysadmin > BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu > > > -- > > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > > -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] rdMolDraw2D drawing code
Hi all, I finally got a round tuit for playing with the drawing code and I like it -- great job, thank you Greg and Dave and everyone who contributed. One question though: is it possible to add padding around atom labels? Or use some other trick to make the attached look less crowded? (Yes, I do want all Hs and all atom labels with numbers.) The best I can come up with is reduce the font size a little, that works fine. I think it'd be nice if the fine manual for MolDraw2D said what the units used by FontSize()/SetFontSize() are. So, any better ideas than just slightly smaller labels? TIA -- Dimitri Maziuk Programmer/sysadmin BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu signature.asc Description: OpenPGP digital signature -- ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss