Skip to content
Jupyter widget to interactively view molecular structures and trajectories
Jupyter Notebook JavaScript Python TypeScript CSS Shell
Branch: master
Clone or download

Latest commit

Latest commit 0ad4c4e Dec 28, 2019


Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update May 15, 2019
binder Update environment.yml (#843) Aug 17, 2019
devtools ENH: test Oct 10, 2019
docs Update Oct 4, 2019
examples Update Dec 28, 2019
js Bump eslint from 3.19.0 to 6.6.0 in /js (#861) Nov 8, 2019
nglview Add `principal_axes` as an alias of `axes` Dec 18, 2019
notebooks Notebook Aug 17, 2019
.coveragerc [WIP] using base64 to encode numpy array to send to JS (#67) Apr 29, 2016
.gitattributes [setup|package] added versioneer to extract version numbers from git … Feb 23, 2016
.gitignore added js/node_modules to gitignore Oct 3, 2017
.travis.yml ENH test Oct 10, 2019 changelog for v1.0 [ci skip] Oct 31, 2017 Officially support ipywigets 7 (#682) Aug 19, 2017
Dockerfile Update Dockerfile Jul 23, 2017
Dockerfile-jupyterlab Docker container for nglview with jupyterlab (#653) Jul 23, 2017
LICENSE initial commit Nov 9, 2015 include lab Nov 27, 2016 Update Sep 15, 2019
circle.yml Docker container for nglview with jupyterlab (#653) Jul 23, 2017 Update Apr 25, 2019
nglview.gif improve gif quality for README (#242) Jun 4, 2016
nglview.png Update readme: png file (#129) May 8, 2016
nightwatch.json ENH: nightwatch (again) (#639) Jul 18, 2017
pip-requirements-test.txt Gridbox enhancement (#838) Jul 24, 2019 add show_iodata May 3, 2019
setup.cfg [versioning] fix updating of for sdist/build_py commands;… Jan 9, 2017 QCElemental Integration (#860) Nov 8, 2019 projX: Interative molecular projection visualization, Guillermo Pérez… Feb 25, 2017 - Update write_html: Jun 30, 2019

Citation | Installation | Example | Usage | Command line | API doc | Interface classes | Website | Acknowledgment

DOI Build Status Coverage Status

Try nglview online: Binder

An IPython/Jupyter widget to interactively view molecular structures and trajectories. Utilizes the embeddable NGL Viewer for rendering. Support for showing data from the file-system, RCSB PDB, simpletraj and from objects of analysis libraries mdtraj, pytraj, mdanalysis, ParmEd, rdkit, ase, HTMD, biopython, cctbx, pyrosetta, schrodinger's Structure

Should work with Python 3. If you experience problems, please file an issue.

Ask question about usage? Please post here


Table of contents


Released version

  • Available on conda-forge channel

    conda install nglview -c conda-forge
    # might need: jupyter-nbextension enable nglview --py --sys-prefix
    # if you already installed nglview, you can `upgrade`
    conda upgrade nglview --force
    # might need: jupyter-nbextension enable nglview --py --sys-prefix
  • Available on PyPI

   pip install nglview
   jupyter-nbextension enable nglview --py --sys-prefix


If you are using notebook v5.0, you need to increase the iopub_data_rate_limit to visualize big structure (e.g: solvated system)

jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000

Development version

Requirement: ipywidgets >= 7.0, notebook >= 4.2

The development version can be installed directly from github:

notebook user

    git clone
    cd nglview
    python install
    # if you edit files in ./js folder, make sure to rebuild the code
    cd js
    npm install

    # probably need to activate widgetsnbextension
    # python -m ipykernel install --sys-prefix
    # jupyter nbextension enable --py --sys-prefix widgetsnbextension
    # jupyter nbextension enable --py --sys-prefix nglview
    # tested with ipywidgets 5.2.2, notebook 4.2.1


Showcase from users

Please check user examples. Feel free to contribute.


Open a notebook

jupyter notebook

and issue

import nglview
view = nglview.show_pdbid("3pqr")  # load "3pqr" from RCSB PDB and display viewer widget

A number of convenience functions are available to quickly display data from the file-system, RCSB PDB, simpletraj and from objects of analysis libraries mdtraj, pytraj, mdanalysis, ParmEd, rdkit, HTMD, biopython.

Function Description
show_file(path) Shows any NGL supported file formats (pdb, gro, mol2, sdf, dx, ..) in path
show_pdbid(pdbid) Shows pdbid fetched from RCSB PDB
show_simpletraj(struc_path, traj_path) Shows structure & trajectory loaded with simpletraj
show_mdtraj(traj) Shows MDTraj trajectory traj
show_pytraj(traj) Shows PyTraj trajectory traj
show_parmed(structure) Shows ParmEd structure
show_mdanalysis(univ) Shows MDAnalysis Universe or AtomGroup univ
show_rdkit(mol) Shows rdkit rdkit.Chem.rdchem.Mol
show_ase(atoms) Shows ase Atoms
show_asetraj(traj) Shows ase trajectory traj
show_pymatgen(struct) Shows pymatgen Structure
show_htmd(mol) Shows HTMD Molecules
show_biopython(mol) Shows Biopython structural entities
show_iotbx(mol) Shows cctbx's iotbx structure
show_rosetta(pose) Shows pyrosetta's Pose
show_iodata(obj) Shows iodata's IOData
show_psi4(obj) Shows psi4's Molecule
show_qcelementary Shows QCelementary's Molecule
show_openbabel Shows openbabel's OMol
show_prody Shows prody's Ensemble or AtomGroup



view.add_representation('cartoon', selection='protein')

# or shorter
view.add_surface(selection="protein", opacity=0.3)

# specify color
view.add_cartoon(selection="protein", color='blue')

# specify residue
view.add_licorice('ALA, GLU')

# clear representations

# update parameters for ALL cartoons of component 0 (default)
view.update_cartoon(opacity=0.4, component=0)

# remove ALL cartoons of component 0 (default)
view.remove_cartoon(opacity=0.4, component=0)

# Not using default representation
view = nv.show_file('your.pdb', default=False)

And many more, please check NGL website

Representations can also be changed by overwriting the representations property of the widget instance view. The available type and params are described in the NGL Viewer documentation.

view.representations = [
    {"type": "cartoon", "params": {
        "sele": "protein", "color": "residueindex"
    {"type": "ball+stick", "params": {
        "sele": "hetero"

The widget constructor also accepts a representation argument:

initial_repr = [
    {"type": "cartoon", "params": {
        "sele": "protein", "color": "sstruc"

view = nglview.NGLWidget(struc, representation=initial_repr)


# set the frame number
view.frame = 100
# parameters for the NGL stage object
    # "percentages, "dist" is distance too camera in Angstrom
    "clipNear": 0, "clipFar": 100, "clipDist": 10,
    # percentages, start of fog and where on full effect
    "fogNear": 0, "fogFar": 100,
    # background color
    "backgroundColor": "black",

# note: NGLView accepts both origin camel NGL keywords (e.g. "clipNear")
# and snake keywords (e.g "clip_near")
# parameters to control the `delay` between snapshots
# change `step` to play forward (positive value) or backward (negative value)
# note: experimental code
view.player.parameters = dict(delay=0.04, step=-1)
# update camera type = 'orthographic'
# change background color
view.background = 'black'


# adding new trajectory
# traj could be a `pytraj.Trajectory`, `mdtraj.Trajectory`, `MDAnalysis.Universe`, 
# `parmed.Structure`, `htmd.Molecule` or derived class of `nglview.Trajectory`

# change representation
view[0].add_cartoon(...) # equal to view.add_cartoon(component=0)
view[1].add_licorice(...) # equal to view.add_licorice(component=1)

Add extra component

# Density volumes (MRC/MAP/CCP4, DX/DXBIN, CUBE)
# Or adding derived class of `nglview.Structure`

# add component from url
# NOTE: Trajectory is a special case of component.


# coot mouse style (

Interaction controls

Movie making

Require: moviepy (pip install moviepy)

from import MovieMaker
movie = MovieMaker(view, output='my.gif', in_memory=True)

Embed widget


API doc

Command line

# open a notebook and import nglview

# Require installing pytraj (PR for other backends is welcome)
# open notebook, load `my.pdb` to pytraj's trajectory then display `view`
nglview my.pdb

# load density data
nglview my.ccp4

# open notebook, create trajectory with given topology `my.parm7` and trajecotry file ``,
# then display `view`
nglview my.parm7 -c

# load all trajectories with filename ending with 'nc'
# make sure to use quote " "
nglview my.parm7 -c "*.nc"

# open notebook, copy content from ``

# create a remote notebook
# just follow its instruction
nglview my.pdb --remote
nglview my.parm7 -c --remote
nglview mynotebook.ipynb --remote

# demo (don't need pytraj)
nglview demo

# specify web browser
nglview my.pdb --browser=google-chrome





Talks about NGL and nglview


Join us here

Projects integrating NGLView

(Feel free to make a PR to add/remove your project here)

  • AMBER - A package of programs for molecular dynamics simulations of proteins and nucleic acids
  • mbuild - A hierarchical, component based molecule builder
  • deepchem - Deep-learning models for Drug Discovery and Quantum Chemistry
  • htmd - High throughput molecular dynamics simulations
  • Moleidoscope - Molecular kaleidoscope
  • ssbio - Tools for enabling structural systems biology
  • hublib - hublib is a Python library for the HUBzero science gateway platform.
  • molPX: ipython API to visualize MD-trajectories along projected trajectories
  • nanoribbon
  • ase: Atomic Simulation Environment
  • pida: Software for analyzing multiple protein-protein interaction docking solutions,
  • pytim
  • MobleyLab/drug-computing Educational materials for, and related to, UC Irvine's Drug Discovery Computing Techniques course.
  • pyiron: an integrated development environment for implementing, testing, and running simulations in computational materials science.
  • BioSimSpace: An interoperable framework for biomolecular simulation
  • pyrod: PyRod - Tracing water molecules in molecular dynamics simulations
  • kugupu: kugupu - a molecular network generator to study charge transport pathways in amorphous materials
  • pnab: proto-Nucleic Acid Builder



If you would like to acknowledge our work, feel free to cite:

Hai Nguyen, David A Case, Alexander S Rose; NGLview - Interactive molecular graphics for Jupyter notebooks, Bioinformatics, , btx789,


Generally MIT, see the LICENSE file for details.

You can’t perform that action at this time.