In an earlier thread, I reported that I could not get Jupyter to render
except from the outermost level of the notebook. For instance, the
following code would not render Benzene:
----------
from rdkit import Chem
from rdkit.Chem import rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG, display
m = Chem.MolFromSmiles("c1ccccc1")
def render_mol(m):
rdDepictor.Compute2DCoords(m)
drawer = rdMolDraw2D.MolDraw2DSVG(400, 200)
drawer.DrawMolecule(m)
drawer.FinishDrawing()
svg = drawer.GetDrawingText().replace('svg:','')
SVG(svg)
render_mol(m)
----------
Googling around for something else, I accidentally found out how to make
this work. Namely, replace the last line in render_mol() with:
display(SVG(svg))
In other words, use the IPython.display.display function. This function
will render to the screen from anywhere in your notebook code. You'll note
I have imported it in the above excerpt.
The suggestion at the time was to use MolsToGridImage(), which is a great
facility, but it might not always be what you want. So I was happy to find
this.
-P.
------------------------------------------------------------------------------
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