simple workaround to display 3d structures in a notebook


Easily displaying pdb structures using 3dmol without py3dmol

3dmol.js is a lightweight javascript library for displaying 3d molecules. py3Dmol is a great tool for embedding an interactive 3Dmol.js viewer in a Jupyter notebook.

If for some reason one cannot install py3dmol, it is also possible to display 3d structures by instantiating a viewer for 3dmol.js using IPython's display module, or by using jupyter's HTML cell magic.

In [11]:
from IPython.display import display, HTML
In [19]:
def disp3d(pdb):
    js="<script src='' async></script> <div style='height: 400px; width: 400px; position: relative;' class='viewer_3Dmoljs' data-pdb='{}' data-backgroundcolor='0xffffff' data-style='stick'></div>".format(pdb)
In [22]:
In [21]:

Jupyter's HTML cell magic does exactly the same thing.

In [23]:
<script src="" async></script>     
         <div style="height: 400px; width: 400px; position: relative;" class='viewer_3Dmoljs' data-pdb='2POR' data-backgroundcolor='0xffffff' data-style='stick'></div>       

Leave a comment

Your email address will not be published. Required fields are marked *