[Rdkit-discuss] Solved! (was, Re: Fwd: Jupyter renders only from the outermost level?)
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: Peter S. S. <sh...@gm...> - 2016-10-14 21:21:16
|
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. |