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

1

6

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.

Miki answered 14/12, 2020 at 8:6 Comment(2)
I don't know much about this, but look at these results they might lead to a solution: google.com/search?q=ipython+display.display+change+sizePublic
@Public yes, I have seen those and did not find anything relevant to my case. Thank you though!Miki
N
3

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.

Nathalienathan answered 14/12, 2020 at 11:10 Comment(2)
Thank you for your answer, it helped me a lot! Is there a reference page where I can see what else I could configure with IPythonConsole.[attribute]?Miki
The best place to look is probably the source code (lines 36-45), I don't think it is documented anywhere. Note that the drawOptions variable is a good way to specify more complex drawing options via rdMolDraw2D.DrawOptions() see here. for example to add atom indices to the image you could do: IPythonConsole.drawOptions.addAtomIndices = True.Nathalienathan

© 2022 - 2024 — McMap. All rights reserved.