Amber masthead
Filler image AmberTools21 Amber20 Manuals Tutorials Force Fields Contacts History
Filler image

Useful links:

Amber Home
Download Amber
Installation
Amber Citations
GPU Support
Updates
Mailing Lists
For Educators
File Formats
10.6 Jupyter Notebooks and Python

AMBER Tutorial

10.6.5 Trajectory rendering and movie making with NGLView

By Hai Nguyen (BSD 2-clause)

What is NGLView?

NGLView is a viewer for molecular structures and trajectories in Jupyter notebook.

Requirement

  • AmberTools >= 16
  • If you allow AMBER to install Python distribution from Miniconda, you have most needed packages (except NGLView and moviepy) for this tutorial.

  • Install NGLView development version:

    amber.conda install nglview==0.5.1 -c ambermd
    
  • Install moviepy to generate movie from image files

    # OSX user: install matplotlib via conda to make it work properly with moviepy
      # amber.conda install matplotlib
    
      amber.pip install moviepy
      amber.conda install freeimage
    
  • You know how to use Linux command line. If not, please check basic AMBER tutorial
  • You know how to open a Jupyter notebook

    amber.jupyter notebook notebook.ipynb
      # where `notebook.ipynb` is the name of your notebook.
    

Note: If you did not have amber.{pip, conda}, you can just use pip, conda or jupyter commands

How to follow this tutorial?

  • Just copy and paste commands to your notebook, then hit "Ctrl-Enter"

Create trajectory viewer

In [1]:
import pytraj as pt
import nglview as nv
print(pt.__version__, nv.__version__)
('1.0.4', '0.5-rc.0')
In [2]:
# create pytraj's Trajectory, require supported formats (.nc, .dcd, .pdb, .trr, ...)
traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB)

# perform superimpose to 1st frame to remove translation and rotation
traj.superpose(mask='@CA', ref=0)

traj
Out[2]:
pytraj.Trajectory, 51 frames: 
Size: 0.000000 (GB)
<Topology: 5547 atoms, 349 residues, 1 mols, PBC with box type = ortho>
           
In [3]:
# create NGL viewer
view = nv.show_pytraj(traj)
view
In [4]:
view.render_image()
In [5]:
view._display_image()
Out[5]: