Re: [Rdkit-discuss] RDKit Font weight

2017-10-18 Thread mark
Hello Greg,

Thanks for your responses and time on this.

I've tried to look into this a load more, but searching the docs for examples 
has not turned much round, and the API doc doesn't give examples.  I appreciate 
you have a massive doc task to do.
But in the manual, I see 
http://www.rdkit.org/docs/GettingStartedInPython.html#working-with-2d-molecules-generating-depictions
 

 and this doesn't even mention MolDraw2DSVG.
When I google MolDraw2DSVG the second hit after the API is 
http://rdkit.blogspot.co.uk/2015/02/new-drawing-code.html 
 which describes a 
better-than-original-pure-python drawing capability, but is not MolDraw2DSVG.  
I presume that is also deprecated.  A bit confusing.  Where is the best place 
to look to see examples of MolDraw2DSVG in action?

Re the below, I actually mean white bonds not black bonds, as the images will 
be presented on a dark background, but I will use string manipulation to cover 
the output files no probs.  Thanks for that.
I will check out molecule rotation code, and thanks also for confirming 
python-only coding. 

Re InchI, I was looking at SMILES, as I would like to get as accurate as 
possible while still presenting posh graphics, but reading a bit looks like 
SMILES suffers geometrically where InchI does not, hence movement away from 
SMILES.  In your experience, which is the best *commonly used* format for 
accuracy?  I use pubchem for pretty much all source data, and write to SVG, and 
so after SMILES, InchI (not InchIKey) appeared to be a good balance between 
conformation, use and functionality.  Any comment in the regard massively 
appreciated;  I'm only recently back in (bio)chem after a hiatus for 12 years.


Thanks,

Mark Lewis





> On 18 Oct 2017, at 13:53, Greg Landrum  wrote:
> 
> 
> 
> On Wed, Oct 18, 2017 at 10:12 AM, mark  > wrote:
> Thanks Greg - it's nice of you to even be willing to support the old drawing 
> methods in terms of documenting them.
> I did have a search for Cairo docs but my quick goog ran aground.  I had been 
> expecting to roll something to process obabel svg output, I thought I'd get 
> more of the control done from the source conversion of InchI to SVG and 
> that's still the case - I'll look further into the rdkit code. Could I ask:
> 1) Which of MolDraw2DSVG and MolDraw2DCairo is best (hopefully not too 
> contentious a question).
> 
> I think you want an SVG, so that would be the one to use. The Cairo one 
> produces a PNG.
>  
>  My requirement is to ideally:
> a. Take InchI string
> 
> As long as you aware that InChIs are not a good way to transfer chemical 
> information this is fine. 
> You may be able to create beautiful chemistry drawings, but the chemistry 
> itself is going to be horrible a lot of the time. InChI just wasn't designed 
> to be an interchange format.
>  
> b. Render as a set of SVGs optimised for current iPhone, iPad and latest 
> Android screen resolutions
> - transparent bg
> - all white bonds and atom text in sans bold
> 
> I assume you mean black bonds? The atom text thing you can do via string 
> manipulation. 
>  
> - ensure all non-carbon atoms' text identifiers are perfectly positioned in 
> the mol render (think max-posh latest mobile rendering)
> 
> That's going to be tough to do; it's a hard problem. Concrete suggestions as 
> to how to improve the existing code are, of course, very welcome.
>  
> + this is so that as technology advances, each device equivalent will get a 
> higher res-still, but as SVG, the nearest image to fit will scale OK 
> (probably until I end up using iPad-optimised images for iPhones...) with no 
> worries about antialiasing artefacts, bond lines perfectly meeting each end 
> it was originally rendered to, as the svg is scaled to fit a new, slightly 
> larger resolution
> + I've given up the notion of being able to rotate a molecule after rendering 
> and have the text remain the right way up - unless you know of a way (not 
> googled this yet)
> 
> Nope, you want to rotate it first. There is RDKit code to do this.
>  
> c. Use a self-rolled post-pro script to edit the svg into the required state 
> (such as bold text etc) as needed
> d. Use python where possible
> 
> 2) You mention using c++ classes, and although I can programme c++ my 
> knowledge is 20 years old; I can programme c and python more easily, so are 
> you suggesting I need to actually write this in c++?  
> 
> Nope. The "C++ rendering code" is all exposed to Python, so you can work 
> purely in Python. I just use that phrase to contrast it with the old, pure 
> python, rendering code.
>  

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! 

Re: [Rdkit-discuss] RDKit Font weight

2017-10-18 Thread mark
Thanks Greg - it's nice of you to even be willing to support the old drawing 
methods in terms of documenting them.
I did have a search for Cairo docs but my quick goog ran aground.  I had been 
expecting to roll something to process obabel svg output, I thought I'd get 
more of the control done from the source conversion of InchI to SVG and that's 
still the case - I'll look further into the rdkit code. Could I ask:
1) Which of MolDraw2DSVG and MolDraw2DCairo is best (hopefully not too 
contentious a question).  My requirement is to ideally:
a. Take InchI string
b. Render as a set of SVGs optimised for current iPhone, iPad and latest 
Android screen resolutions
- transparent bg
- all white bonds and atom text in sans bold
- ensure all non-carbon atoms' text identifiers are perfectly positioned in the 
mol render (think max-posh latest mobile rendering)
+ this is so that as technology advances, each device equivalent will get a 
higher res-still, but as SVG, the nearest image to fit will scale OK (probably 
until I end up using iPad-optimised images for iPhones...) with no worries 
about antialiasing artefacts, bond lines perfectly meeting each end it was 
originally rendered to, as the svg is scaled to fit a new, slightly larger 
resolution
+ I've given up the notion of being able to rotate a molecule after rendering 
and have the text remain the right way up - unless you know of a way (not 
googled this yet)
c. Use a self-rolled post-pro script to edit the svg into the required state 
(such as bold text etc) as needed
d. Use python where possible

2) You mention using c++ classes, and although I can programme c++ my knowledge 
is 20 years old; I can programme c and python more easily, so are you 
suggesting I need to actually write this in c++?  

Thanks,

Mark Lewis





> On 18 Oct 2017, at 10:48, Greg Landrum  wrote:
> 
> Hi Mark,
> 
> I'm afraid that a lot of the fine control that it looks like you want is not 
> going to be possible. But I will do what I can.
> 
> Your questions are all connected to the old, pure Python, drawing code. We're 
> not doing anything further with this and I'm encouraging people to switch 
> over to the new C++ drawing code. There are some functions in rdkit.Chem.Draw 
> that use this, but if you're interested in having a bit more control over the 
> options, you should use the MolDraw2DSVG or MolDraw2DCairo classes for this.
> 
> A general point is that all of this stuff is "under documented". There is 
> some info on the RDKit blog, but the best way to figure out how to use it is 
> generally via searching the mailing list, asking here, or just experimenting 
> with the options that are there. I will eventually write docs for this, but 
> it's one of those things that can also be done by members of the community.
> 
> A couple more detailed answers, in the context of using MolDraw2DSVG since I 
> think that's what you're looking to generate, are below.
> 
> On Wed, Oct 18, 2017 at 7:21 AM, mark  > wrote:
> This outputs several files for various screen sizes of mobile I'm developing 
> for.
> 
> 1) How can I make the font weight bold?  or italic for that matter.  The 
> sping/piddle docs list these with the font face and size but these are split 
> out in the rdkit docs
> 
> At the moment there's no way to do this other than editing the SVG that comes 
> out of the rendering code. As long as you want all the text to be the same, 
> this is a straightforward string replacement operation. Finer control than 
> that is not currently possible.
>  
> 2) I found 
> http://www.rdkit.org/docs/api/rdkit.Chem.Draw.MolDrawing%27.DrawingOptions-class.html
>  
> 
>  having looked at the code for MolDrawing, but there appears to be no 
> documentation as regard what each of these options does. Where is this 
> documentation?
> 
> non-existent, see above
>  
> 3) Even with options.defaultColor = (1, 1, 1) non-carbon atoms display 
> coloured (O red, N blue etc). But I need a monochrome image.  Can anyone 
> confirm if monochrome images are possible please and how this is done?
> 
> Here's how you draw a molecule in black and white using the new code:
> d = Draw.MolDraw2DSVG(300, 300)
> d.drawOptions().useBWAtomPalette()
> d.DrawMolecule(dm)
> d.FinishDrawing()
> 
>  
> 4) In the attached image, you will notice that the non-carbon, non-hydrogen 
> atoms are slightly out of place, too far down from exactly where they are 
> expected to be drawn.  How can this be adjusted?  It appears not to matter 
> what I set the font size to, they are always out of place.  I think this 
> might be because of the fact the glyphs are aligned to the bottom of their 
> containers in the svg.
> 
> 
> 
> 
> Dealing with this stuff in a cross-platform way is a really hard problem. Try 
> the new code out. You may find that it's better at this. 

Re: [Rdkit-discuss] RDKit Font weight

2017-10-18 Thread Greg Landrum
Hi Mark,

I'm afraid that a lot of the fine control that it looks like you want is
not going to be possible. But I will do what I can.

Your questions are all connected to the old, pure Python, drawing code.
We're not doing anything further with this and I'm encouraging people to
switch over to the new C++ drawing code. There are some functions in
rdkit.Chem.Draw that use this, but if you're interested in having a bit
more control over the options, you should use the MolDraw2DSVG or
MolDraw2DCairo classes for this.

A general point is that all of this stuff is "under documented". There is
some info on the RDKit blog, but the best way to figure out how to use it
is generally via searching the mailing list, asking here, or just
experimenting with the options that are there. I will eventually write docs
for this, but it's one of those things that can also be done by members of
the community.

A couple more detailed answers, in the context of using MolDraw2DSVG since
I think that's what you're looking to generate, are below.

On Wed, Oct 18, 2017 at 7:21 AM, mark  wrote:

> This outputs several files for various screen sizes of mobile I'm
> developing for.
>
> 1) How can I make the font weight bold?  or italic for that matter.  The
> sping/piddle docs list these with the font face and size but these are
> split out in the rdkit docs
>

At the moment there's no way to do this other than editing the SVG that
comes out of the rendering code. As long as you want all the text to be the
same, this is a straightforward string replacement operation. Finer control
than that is not currently possible.


> 2) I found http://www.rdkit.org/docs/api/rdkit.Chem.Draw.
> MolDrawing%27.DrawingOptions-class.html
> 
>  having
> looked at the code for MolDrawing, but there appears to be no documentation
> as regard what each of these options does. Where is this documentation?
>

non-existent, see above


> 3) Even with options.defaultColor = (1, 1, 1) non-carbon atoms display
> coloured (O red, N blue etc). But I need a monochrome image.  Can anyone
> confirm if monochrome images are possible please and how this is done?
>

Here's how you draw a molecule in black and white using the new code:
d = Draw.MolDraw2DSVG(300, 300)
d.drawOptions().useBWAtomPalette()
d.DrawMolecule(dm)
d.FinishDrawing()



> 4) In the attached image, you will notice that the non-carbon,
> non-hydrogen atoms are slightly out of place, too far down from exactly
> where they are expected to be drawn.  How can this be adjusted?  It appears
> not to matter what I set the font size to, they are always out of place.  I
> think this might be because of the fact the glyphs are aligned to the
> bottom of their containers in the svg.
>
>
>
Dealing with this stuff in a cross-platform way is a really hard problem.
Try the new code out. You may find that it's better at this. It should at
least have different pathologies. :-S


> Great kit!
>

Thanks!

-greg


>
> Thanks IA,
>
> Mark Lewis
>
>
>
>
>
>
> 
> --
> 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
>
>
--
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


[Rdkit-discuss] RDKit Font weight

2017-10-18 Thread mark
Hello

I've been struggling with rdkit tbh.  I've got over the macOS boost <1.65 brew 
issue, and found through sping how to set the bg colour of my output svg to 
transparent (sping.sourceforge.net/reference.html 
).
But brick wall questions are left, based on this simple code:

from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw.MolDrawing import MolDrawing
from rdkit.Chem.Draw.MolDrawing import DrawingOptions

## check 
http://www.rdkit.org/docs/api/rdkit.Chem.Draw.MolDrawing%27.DrawingOptions-class.html
#
options = DrawingOptions()
# options.defaultColor = (1, 1, 1)
options.atomLabelFontFace = 'sans'  # what are my options here?
options.bgColor = (-1, -1, -1)
options.defaultColor = (0, 0, 0)
options.selectColor = (1, 1, 1)
options.bondLineWidth = 2
options.colorBonds = False  # appears not to work for P, O, 
N etc.

# options.atomLabelFontSize = 12
i = 
Chem.MolFromInchi("InChI=1S/C20H25N3O/c1-4-23(5-2)20(24)14-9-16-15-7-6-8-17-19(15)13(11-21-17)10-18(16)22(3)12-14/h6-9,11,14,18,21H,4-5,10,12H2,1-3H3/t14-,18-/m1/s1")
Draw.MolToFile(i, "VAYOSLLFUXYJDT-RDTXWAMCSA-N-320.svg", (320,320), True, True, 
"svg", True, options=options)

# options.atomLabelFontSize = 13.5
i = 
Chem.MolFromInchi("InChI=1S/C20H25N3O/c1-4-23(5-2)20(24)14-9-16-15-7-6-8-17-19(15)13(11-21-17)10-18(16)22(3)12-14/h6-9,11,14,18,21H,4-5,10,12H2,1-3H3/t14-,18-/m1/s1")
Draw.MolToFile(i, "VAYOSLLFUXYJDT-RDTXWAMCSA-N-375.svg", (375,375), True, True, 
"svg", True, options=options)

# options.atomLabelFontSize = 15
i = 
Chem.MolFromInchi("InChI=1S/C20H25N3O/c1-4-23(5-2)20(24)14-9-16-15-7-6-8-17-19(15)13(11-21-17)10-18(16)22(3)12-14/h6-9,11,14,18,21H,4-5,10,12H2,1-3H3/t14-,18-/m1/s1")
Draw.MolToFile(i, "VAYOSLLFUXYJDT-RDTXWAMCSA-N-414.svg", (414,414), True, True, 
"svg", True, options=options)

# options.atomLabelFontSize = 22
i = 
Chem.MolFromInchi("InChI=1S/C20H25N3O/c1-4-23(5-2)20(24)14-9-16-15-7-6-8-17-19(15)13(11-21-17)10-18(16)22(3)12-14/h6-9,11,14,18,21H,4-5,10,12H2,1-3H3/t14-,18-/m1/s1")
Draw.MolToFile(i, "VAYOSLLFUXYJDT-RDTXWAMCSA-N-768.svg", (768,768), True, True, 
"svg", True, options=options)

# options.atomLabelFontSize = 24
i = 
Chem.MolFromInchi("InChI=1S/C20H25N3O/c1-4-23(5-2)20(24)14-9-16-15-7-6-8-17-19(15)13(11-21-17)10-18(16)22(3)12-14/h6-9,11,14,18,21H,4-5,10,12H2,1-3H3/t14-,18-/m1/s1")
Draw.MolToFile(i, "VAYOSLLFUXYJDT-RDTXWAMCSA-N-1025.svg", (1025,1025), True, 
True, "svg", True, options=options)


This outputs several files for various screen sizes of mobile I'm developing 
for.

1) How can I make the font weight bold?  or italic for that matter.  The 
sping/piddle docs list these with the font face and size but these are split 
out in the rdkit docs
2) I found 
http://www.rdkit.org/docs/api/rdkit.Chem.Draw.MolDrawing%27.DrawingOptions-class.html
 

 having looked at the code for MolDrawing, but there appears to be no 
documentation as regard what each of these options does. Where is this 
documentation?
3) Even with options.defaultColor = (1, 1, 1) non-carbon atoms display coloured 
(O red, N blue etc). But I need a monochrome image.  Can anyone confirm if 
monochrome images are possible please and how this is done?
4) In the attached image, you will notice that the non-carbon, non-hydrogen 
atoms are slightly out of place, too far down from exactly where they are 
expected to be drawn.  How can this be adjusted?  It appears not to matter what 
I set the font size to, they are always out of place.  I think this might be 
because of the fact the glyphs are aligned to the bottom of their containers in 
the svg.



Great kit!  

Thanks IA,

Mark Lewis





--
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