NGLView
raw JSON → 4.0.1 verified Mon Apr 27 auth: no python
NGLView provides an IPython/Jupyter widget to interactively view molecular structures and trajectories using the NGL Viewer. It supports various file formats (PDB, SDF, MOL2, XYZ, etc.) and integrates with MDTraj, MDAnalysis, and OpenMM. Version 4.0.1 supports Python >=3.7. Development is active on GitHub.
pip install nglview Common errors
error ModuleNotFoundError: No module named 'nglview' ↓
cause NGLView is not installed.
fix
pip install nglview or conda install -c conda-forge nglview error Error displaying widget: model not found ↓
cause JupyterLab extension not installed or nglview-js-widgets missing.
fix
In JupyterLab:
jupyter labextension install nglview-js-widgets and restart Jupyter. error Javascript Error: Cannot read property 'on' of undefined ↓
cause Outdated or mismatched ipywidgets version.
fix
Upgrade ipywidgets:
pip install --upgrade ipywidgets and jupyter nbextension enable --py widgetsnbextension. Warnings
gotcha In JupyterLab, you must install the labextension separately: `jupyter labextension install nglview-js-widgets` or use `conda install -c conda-forge nglview` which includes it. ↓
fix For JupyterLab, run: `jupyter labextension install nglview-js-widgets` or use conda.
gotcha If the widget does not render, you may need to enable the notebook extension: `jupyter nbextension enable nglview --py --sys-prefix`. ↓
fix Run: `jupyter nbextension enable nglview --py --sys-prefix`
breaking Version 3.x had breaking changes in the widget API (e.g., `widget.NGLWidget` renamed, asynchronous initialization). Code written for 2.x may not work in 3.x. ↓
fix Update code to use `nglview.NGLWidget` and handle async initialization with `view._init_signals()` if needed.
gotcha Trajectory loading with `add_trajectory()` may fail if the topology file is not provided or mismatched. ↓
fix Always provide topology via `traj.add_topology()` or pass topology file to `show_mdtraj()` / `show_mdanalysis()`.
Install
pip install nglview[notebook] Imports
- nglview wrong
Nonecorrectimport nglview as nv
Quickstart
import nglview as nv
import os
# Use a built-in example (PDB ID 1CRN)
view = nv.show_pdbid("1CRN")
view
# To view a local file:
# view = nv.show_file("protein.pdb")