Rhodopsin in motion
Charts
Scientific
Scrub or click through a real molecular dynamics trajectory, linked frame-for-frame to an RMSD chart, with click-to-inspect and a residue-range highlight – all in-place.
A bundled 1 ns molecular dynamics trajectory of rhodopsin (51 frames), loaded with mdtraj and displayed with nglview. A single shared reactive.value (current_frame) is the one source of truth for “what frame are we on”: the frame slider, a click anywhere on the RMSD chart, and playback (animate=True) all write to it, and three separate effects read it to move the 3D viewer, the chart’s reference line, and nothing else – every update is in place, so the camera and the chart’s zoom are untouched.


Run it
git clone --depth 1 https://github.com/posit-dev/py-shinywidgets
cd py-shinywidgets/website/gallery/showcases/rhodopsin-in-motion
uv run --with mdtraj shiny run app.pySource: app.py · Open in Shinylive
Try this
- Drag the Frame slider (or press its play button): the structure and the chart’s dashed reference line move together.
- Click anywhere on the RMSD chart: the frame jumps there, in both the viewer and the slider.
- Switch Representation (cartoon/licorice/spacefill/surface), or drag Highlight residues: the structure restyles without resetting the frame or the camera.
- Click an atom in the 3D structure: the sidebar’s Picked atom card identifies it (residue name, number, chain).
Accessors demonstrated
rmsd_plot.clicked()– the clicked point’s(x, y)on the RMSD chart;xis used directly as a frame number.structure.read("picked")– nglview’s ownpickedtrait, read via.read()(the taught fallback for any synced trait on a renderer output, replacingreactive_read(x.widget, ...)) sincerender_nglviewhas no dedicated accessors;Nonethen an atom record once something has been clicked.