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.

themennice
  • 177
  • 1
  • 9
  • I don't know much about this, but look at these results they might lead to a solution: https://www.google.com/search?q=ipython+display.display+change+size – tralph3 Dec 14 '20 at 08:22
  • @tralph3 yes, I have seen those and did not find anything relevant to my case. Thank you though! – themennice Dec 14 '20 at 08:38

1 Answers1

2

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.

Oliver Scott
  • 1,673
  • 8
  • 17
  • 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]? – themennice Dec 16 '20 at 22:13
  • 1
    The best place to look is probably the [source code](https://github.com/rdkit/rdkit/blob/master/rdkit/Chem/Draw/IPythonConsole.py) (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](https://www.rdkit.org/docs/source/rdkit.Chem.Draw.rdMolDraw2D.html#rdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions). for example to add atom indices to the image you could do: `IPythonConsole.drawOptions.addAtomIndices = True`. – Oliver Scott Dec 17 '20 at 10:51