Dear Greg and David,

thank you for your responses. Sorry, for not being incomplete with information.
I'm using RDKit2019.03 under Windows using Anaconda3. I haven't found out yet 
how to update to the latest RDKit (2020.09?) version.

In a PyQt Application I want to list structures as images in a QTableWidget and 
therefore don't want to save them as files first.
That's why I'm using Draw.MolToQPixmap(mol)
But maybe, as Greg suggests, there are even better ways with using 
Draw.MolToImage() or using the Draw.MolDraw2DCairo() or Draw.MolDraw2DSVG()?

I did some comparison.
Apparently, it is a Draw.MolToQPixmap(mol) specific problem. In small images a 
smaller font it would be better, but I haven't found yet to set the font size. 
https://rdkit.org/docs/source/rdkit.Chem.Draw.MolDrawing.html should tell me, 
but probably I'm not using it correctly.

It is better with Draw.MolToFile.
In the "fantasy" molecule
smiles = ' FC1OC2N3C4[Si]5=C6B7C(C=CC6=CC4=CC2=CC1)C=CC=C7C=C5C=C3'
only Si is slightly off horizontally. The other labels seem ok.


from rdkit.Chem import Draw
def smiles_to_png(smiles, ffname):
    mol = Chem.MolFromSmiles(smiles)
    try:
        img = Draw.MolToFile(mol,ffname,size=(400,300))
    except Exception as e:
        print(e)

smiles = ' FC1OC2N3C4[Si]5=C6B7C(C=CC6=CC4=CC2=CC1)C=CC=C7C=C5C=C3'
smiles_to_png(smiles,"Test.png")

I only get a warning, but I'm not sure whether this is connected to the offet 
of the labels.
Warning: unable to load font metrics from dir 
C:\Users\Anaconda3\envs\my-rdkit-env\lib\site-packages\rdkit\sping\PIL\pilfonts

Thanks,
Theo.

PS.
I assume I cannot attach files to the mailing list. Nevertheless I will try.
1. Screenshot from PyQt application with Draw.MolToQPixmap
2. Result from above code with Draw.MolToFile


Am 21.10.2020 um 05:51 schrieb Greg Landrum:
> Hi Theo,
>
> The atom label placement in drawings turns out to be very tricky to do in a 
> cross platform way.
> You're using the RDKit's old drawing code which we haven't been maintaining 
> for a while now, I'd recommend either switching to using one of the 
> convenience functions likes Draw.MolToImage() or using the 
> Draw.MolDraw2DCairo() or Draw.MolDraw2DSVG() classes directly.
> I can maybe help with the decision which to use: once you've generated an 
> image of the molecule, what do you want to do with it?
>
> -greg
>
> On Tue, Oct 20, 2020 at 1:32 PM theozh <the...@gmx.net 
> <mailto:the...@gmx.net>> wrote:
>
>     Dear RDKit-ers,
>
>     this sounds like a simple problem, however, I haven't found a link to the 
> corresponding documentation.
>
>     When I draw a structure with:
>
>     from.rdkit.Chem import Draw
>
>     Draw.MolToQPixmap(mol)
>
>     The non-Carbon atom labels are not centered to the bonds, but typically 
> shifted downwards.
>     How to center them also vertically?
>
>     https://rdkit.org/docs/source/rdkit.Chem.Draw.MolDrawing.html
>     Here I don't see how to center atom labels vertically. Am I missing 
> something?
>
>     Thanks for hints and the right link,
>     Theo.
>
>
>
>
>
>
>     _______________________________________________
>     Rdkit-discuss mailing list
>     Rdkit-discuss@lists.sourceforge.net 
> <mailto: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

Reply via email to