Hi,
I finally decided to try the new C++ drawing code and I found some
issues with it. I'll try to descibe my problems.
First, lets start with a code that works perfectly:
from rdkit import Chem
from rdkit.Chem.AllChem import Compute2DCoords
from rdkit.Chem.Draw import rdMolDraw2D
m = Chem.MolFromSmiles('O=C(C)Oc1ccccc1C(=O)O')
Compute2DCoords(m)
drawer = rdMolDraw2D.MolDraw2DCairo(500, 500)
drawer.DrawMolecule(m,highlightAtoms=m.GetSubstructMatch(Chem.MolFromSmarts('c1ccccc1')))
drawer.FinishDrawing()
with open('aspirin_a.png','wb') as f:
f.write(drawer.GetDrawingText())
This code produces the attached 'aspirin_a.png' image, that looks perfect.
Now, apart from the `DrawMolecule` there is also `DrawMolecules`
function exposed by the `MolDraw2DCairo` module. So what will happen
when I use it to render the same molecule?
from rdkit import Chem
from rdkit.Chem.AllChem import Compute2DCoords
from rdkit.Chem.Draw import rdMolDraw2D
m = Chem.MolFromSmiles('O=C(C)Oc1ccccc1C(=O)O')
Compute2DCoords(m)
drawer = rdMolDraw2D.MolDraw2DCairo(500, 500)
drawer.DrawMolecules([m],highlightAtoms=[m.GetSubstructMatch(Chem.MolFromSmarts('c1ccccc1'))])
drawer.FinishDrawing()
with open('aspirin_b.png','wb') as f:
f.write(drawer.GetDrawingText())
The image is different - only atoms are highlighted, bonds between
atoms are not (see the attached 'aspirin_b.png') image.
OK, but who would use `DrawMolecules` to render a single compound
anyway? I think it's meant to render multiple compounds at once. The
'old' drawing code has a function called `MolsToGridImage` to do this.
And it has a `molsPerRow` parameter which makes it easy to define a
shape of the grid. I couldn't find a similar function in the 'new'
drawing code so it looks like using `DrawMolecules` is the only way to
render multiple mols at once. Let's try that:
from rdkit import Chem
from rdkit.Chem.AllChem import Compute2DCoords
from rdkit.Chem.Draw import rdMolDraw2D
m1 = Chem.MolFromSmiles('O=C(C)Oc1ccccc1C(=O)O')
Compute2DCoords(m1)
m2 = Chem.MolFromSmiles('c1cccnc1O')
Compute2DCoords(m2)
drawer = rdMolDraw2D.MolDraw2DCairo(500, 500)
drawer.DrawMolecules([m1, m2])
drawer.FinishDrawing()
with open('mols.png','wb') as f:
f.write(drawer.GetDrawingText())
As a result I get an image (mols.png, attached) of two compounds: one
on top of another. This is definitely not something I would expect to
get. I understand that the function just takes coordinates from
molecules and I can always transalte them (is there a function in
rdkit to translate mol coordinates by a vector?) but I think this
should be done internally by the function or there should be a new
`MolsToGridImage` function defined for the new code that would do
this.
I tried doing the same with `MolDraw2DSVG` but I got the same results.
So summing up my problems with the new drawing code:
- `DrawMolecules` doesn't highlight bonds in the same way as the
`DrawMolecule` does
- There is no equivalent of the `MolsToGridImage` where I can define
the shape of the grid of molecules at least nothing documented in
http://www.rdkit.org/Python_Docs/rdkit.Chem.Draw.rdMolDraw2D.MolDraw2D-class.html
- `DrawMolecules` does nothing to layout molecules in such a way that
they don't obscure each other
Regards,
Michał Nowotka
------------------------------------------------------------------------------
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