Interactive WebGL trajectory widget

Note: this feature requires a 'running' notebook, connected to a live kernel. It will not work with a staticly rendered display. For an introduction to the IPython interactive widget system and its capabilities, see this talk by Brian Granger http://player.vimeo.com/video/79832657#t=30m

Let's start by just loading up a PDB file from the RCSB


In [ ]:
from __future__ import print_function
import mdtraj as md

traj = md.load_pdb('http://www.rcsb.org/pdb/files/2M6K.pdb')
print(traj)

To enable these features, we first need to run enable_notebook to initialize the required javascript.


In [ ]:
from mdtraj.html import TrajectoryView, enable_notebook
enable_notebook()

The WebGL viewer engine is called iview, and is introduced in the following paper: Li, Hongjian, et al. "iview: an interactive WebGL visualizer for protein-ligand complex." BMC Bioinformatics 15.1 (2014): 56.


In [ ]:
# Controls:
#  - default mouse to rotate.
#  - ctrl to translate
#  - shift to zoom (or use wheel)
#  - shift+ctrl to change the fog
#  - double click to toggle full screen

widget = TrajectoryView(traj, secondaryStructure='ribbon')
widget

We can even animate through the trajectory simply by updating the widget's frame attribute


In [ ]:
import time
for i in range(traj.n_frames):
    widget.frame = i
    time.sleep(0.1)

In [ ]: