Citation | Installation | Example | Usage | Command line | API doc | Interface classes | Website | Acknowledgment
Try nglview online:
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
Installation
Released version
pip install nglview
Jupyterlab: nglview
works best with jupyterlab >= 3.0 and no further steps needed.
Known to work versions
Notes
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 https://github.com/arose/nglview
cd nglview
python setup.py install
cd js
npm install
Example
Showcase from users
Usage
Open a notebook
jupyter notebook
and issue
import nglview
view = nglview.show_pdbid("3pqr")
view
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_qcelemental | Shows QCelementary's Molecule |
show_openbabel | Shows openbabel's OMol |
show_prody | Shows prody's Ensemble or AtomGroup |
API
Representations
view.add_representation('cartoon', selection='protein')
view.add_cartoon(selection="protein")
view.add_surface(selection="protein", opacity=0.3)
view.add_cartoon(selection="protein", color='blue')
view.add_licorice('ALA, GLU')
view.clear_representations()
view.update_cartoon(opacity=0.4, component=0)
view.remove_cartoon(opacity=0.4, component=0)
view = nv.show_file('your.pdb', default=False)
view.center()
view.add_rope()
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)
view
Properties
view.frame = 100
view.stage.set_parameters(**{
"clipNear": 0, "clipFar": 100, "clipDist": 10,
"fogNear": 0, "fogFar": 100,
"backgroundColor": "black",
})
view.player.parameters = dict(delay=0.04, step=-1)
view.camera = 'orthographic'
view.background = 'black'
Trajectory
view.add_trajectory(traj)
view[0].add_cartoon(...)
view[1].add_licorice(...)
view.add_component('my.ccp4')
view.add_component('rcsb://1tsu.pdb')
Mouse
view.stage.set_parameters(mouse_preset='coot')
Interaction controls
Movie making
Require: moviepy (pip install moviepy
)
from nglview.contrib.movie import MovieMaker
movie = MovieMaker(view, output='my.gif', in_memory=True)
movie.make()
Embed widget
embed
API doc
Command line
nglview
nglview my.pdb
nglview my.ccp4
nglview my.parm7 -c traj.nc
nglview my.parm7 -c "*.nc"
nglview myscript.py
nglview my.pdb --remote
nglview my.parm7 -c traj.nc --remote
nglview mynotebook.ipynb --remote
nglview demo
nglview my.pdb --browser=google-chrome
FAQ
Q&A
Website
Talks
Talks about NGL and nglview
Contributing
Join us here
Projects integrating NGLView
(Feel free to make a PR to add/remove your project here. Thanks.)
- 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
- opencadd: A Python library for structural cheminformatics
- teachopencadd: TeachOpenCADD: a teaching platform for computer-aided drug design (CADD) using open source packages and data
- query.libretexts.org: query.libretexts.org
- datamol: A python library to work with molecules.
- dynophores: Dynamic pharmacophore modeling of molecular interactions
- pychemcurv: Discrete and local curvature applied to chemistry and chemical reactivity
- AutoSolvate: Automated workflow for generating quantum chemistry calculation of explicitly solvated molecules
- plipify: PLIPify: Protein-Ligand Interaction Frequencies across Multiple Structures
- Melodia: Differential Geometry of Proteins Backbones
- pyrosetta_viewer3d: Display PackedPose objects, Pose objects, or PDB files within a Jupyter notebook and Google Colab
- py4vasp: Python interface for VASP
- eminus: A plane wave density functional theory code.
- MolSysMT: Molecular Systems Multi-Tool
Acknowledgment
Cite
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, https://doi.org/10.1093/bioinformatics/btx789
License
Generally MIT, see the LICENSE file for details.