Hi Francesca,
that molecule has been depicted using its existing 3D coordinates.
That's because you only compute 2D coordinates if the molecules does not
have any:
if not mc.GetNumConformers():
rdDepictor.Compute2DCoords(mc)
If the molecule already has a 3D conformation, those coordinates will be
preserved.
If you remove the if clause you will recompute 2D coordinates even when
there are already 3D coordinates, and you will get a depiction that looks
nicer in the notebook.
You probably also want to remove explicit Hs in that case.
Cheers,
p.
On Fri, Jul 23, 2021 at 11:00 AM Francesca Magarotto -
[email protected] <[email protected]>
wrote:
> Hi,
> I've got some problems generating the correct images of the molecules.
> I'm new to Python and RDKit, so maybe I did something wrong.
> Could someone help me and correct the code?
> I've got a cluster of five compounds and I want to display them, but with
> Draw.MolsToGridImage(mols) I didn't obtain correct images.
> I've searched for another method, but I obtain again this image...
>
> #now display structures from one of the clusters
> from rdkit.Chem import Draw
> from rdkit.Chem.Draw import IPythonConsole
>
> m1 = ms[99]
> m2 = ms[18]
> m3 = ms[19]
> m4 = ms[58]
> m5 = ms[60]
> mols=(m1,m2,m3,m4,m5)
> smile1 = Chem.MolToSmiles(m1)
> from rdkit import Chem
> from rdkit.Chem.Draw import IPythonConsole
> from rdkit.Chem import rdDepictor
> from rdkit.Chem.Draw import rdMolDraw2D
> from IPython.display import SVG
>
> def moltosvg(mol, molSize = (300,300), kekulize = True):
> mc = Chem.Mol(mol.ToBinary())
> if kekulize:
> try:
> Chem.Kekulize(mc)
> except:
> mc = Chem.Mol(mol.ToBinary())
> if not mc.GetNumConformers():
> rdDepictor.Compute2DCoords(mc)
> drawer = rdMolDraw2D.MolDraw2DSVG(molSize[0],molSize[1])
> drawer.DrawMolecule(mc)
> drawer.FinishDrawing()
> svg = drawer.GetDrawingText()
> return svg.replace('svg:','')
> SVG(moltosvg(m1))
>
> _______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss