This tutorial shows how to select parts of a structure and apply different styles. It also shows how to add labels and how to zoom in on a selection.
import py3Dmol
This example also shows how to set the size of the viewer.
viewer = py3Dmol.view(query='pdb:5WOG', width=400, height=400)
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
Here we select chain A and apply a cartoon style.
viewer.setStyle({'chain':'A'},{'cartoon': {'color': 'orange'}})
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
Use a list to select to multiple chains.
viewer.setStyle({'chain':['A','B']},{'cartoon': {'color': 'orange'}}) # alpha subunits of hemoglobin
viewer.addLabel('alpha subunits', {'fontColor':'orange', 'backgroundColor':'lightgray'},
{'chain': ['A','B']})
viewer.setStyle({'chain':['C','D']},{'cartoon': {'color': 'blue'}}) # beta subunits of hemoglobin
viewer.addLabel('beta subunits', {'fontColor':'blue', 'backgroundColor':'lightgray'},
{'chain': ['C','D']})
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
Here we display all water molecules as spheres.
viewer.setStyle({'resn': 'HOH'}, {'sphere':{'radius':0.5}})
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
And turn waters off again by resetting their style.
viewer.setStyle({'resn': 'HOH'}, {})
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
Show heme as spheres.
viewer.setStyle({'resn': 'HEM'},{'sphere': {'colorscheme': 'greenCarbon'}})
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
Here we select the heme molecule in chain A and color its carbons red. We also adjust the stick radius. Finally, we zoom into a specific heme residue in chain A.
viewer.setStyle({'chain': 'A', 'resn': 'HEM'},{'stick': {'colorscheme': 'redCarbon', 'radius': 0.2}})
viewer.zoomTo({'chain': 'A', 'resn': 'HEM'})
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
In the following example we display the HIS-87 side chain that interacts with iron in heme.
viewer.setStyle({'chain': 'A', 'resi': '87'},{'stick': {'colorscheme': 'redCarbon'}})
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
We display the iron atom as a green sphere.
viewer.setStyle({'chain': 'A', 'elem': 'Fe'}, {'sphere': {'color': 'green'}})
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
Finally, we add labels to HIS-87 and HEM.
viewer.addResLabels({'chain': 'A', 'resi': '87'})
viewer.addResLabels({'chain': 'A', 'resn': 'HEM'})
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
Here we select all residues within 5 A of the HEM in chain A.
# reset styles and remove labels
viewer.removeAllLabels()
viewer.setStyle({'line':{}})
# select by distance
selection = {'resn':'HEM', 'chain':'A', 'byres':'true', 'expand': 5}
# set styles
viewer.setStyle(selection,{'stick':{'colorscheme':'orangeCarbon'}})
viewer.setStyle({'chain': 'A', 'resn': 'HEM'},{'sphere': {'colorscheme': 'lightgreenCarbon'}})
viewer.zoomTo(selection)
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