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):
    drawer = rdMolDraw2D.MolDraw2DSVG(400, 200)
    svg = drawer.GetDrawingText().replace('svg:','')


Googling around for something else, I accidentally found out how to make
this work. Namely, replace the last line in render_mol() with:


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

Check out the vibrant tech community on one of the world's most 
engaging tech sites,!
Rdkit-discuss mailing list

Reply via email to