This tutorial demonstrates how to visualize 3D structures using the py3Dmol Jupyter Notebook widget. Here we show how to download structures from the PDB as well as read local structure files.
3Dmol.js: molecular visualization with WebGL, N. Rego, D. Koes, Bioinformatics (2015) 31, 1322–1324
Also, check out the py3Dmol tutorial for additional features.
import py3Dmol
py3Dmol downloads PDB structures using the compressed binary MMTF file format from https://mmtf.rcsb.org. Prepend the 'pdb:" prefix to the 4-letter PDB ID.
Downloading PDB structures in MMTF format has the following advantages:
viewer = py3Dmol.view(query='pdb:5MXB')
# setting styles will be covered in the next tutorial
viewer.setStyle({'cartoon': {'color': 'spectrum'}})
viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})
viewer.zoomTo()
viewer.show()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
List of supported file formats
A disadvantage of reading local PDB files is the absence of bond order information. Compare the small molecules below with the downloaded version above.
structure = open('5mxb.pdb','r').read()
viewer = py3Dmol.view()
viewer.addModel(structure,'pdb')
viewer.setStyle({'cartoon': {'color': 'spectrum'}})
viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})
viewer.zoomTo()
viewer.show()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol