pythonjupyter-notebookdisplayobjectrdkit

IPython.display: how to change width, height and resolution of a displayed image


I am displaying an image of a molecule using IPython.display in Jupyter.

Using display() to show the image

The resolution of the image is quite low. Is there a way to specify the width and height of the displayed image and its resolution? I googled it and could not find anything. All I need is something like this:

display(moleSmilemol, format='svg', width=1000, height=1000)

Any pointers would be appreciated.

Update: I could add custom css, which will blow up the picture that was generate, but it is still low quality. I am interested increasing the quality of the picture and its size too. So something deeper than CSS is needed.


Solution

  • Try changing the variables in the rdkit.Chem.Draw.IPythonConsole module:

    from rdkit.Chem.Draw import IPythonConsole
    
    IPythonConsole.molSize = (800, 800)   # Change image size
    IPythonConsole.ipython_useSVG = True  # Change output to SVG
    mol = Chem.MolFromSmiles('N#Cc1cccc(-c2nc(-c3cccnc3)no2)c1')
    display(mol)
    

    Otherwise, you need to use the rdMolDraw2D module to create the drawings yourself with the parameters you require.