Amber masthead
Filler image AmberTools23 Amber22 Manuals Tutorials Force Fields Contacts History
Filler image

Useful links:

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

AMBER Tutorial

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.


  • 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)

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)
In [4]:
In [5]: