Trajectories
A list of frames (or a multi-frame file) gets a player, and optionally an energy/Fmax plot and force arrows.
For large molecular trajectories, use high_performance=True, style="minimal"
(CLI: --high-performance --style minimal). It keeps the same bond criteria and
prepares up to eight future frames off the UI thread. Initial buffering is shown
in the player; the option defaults to False and can be toggled in the sidebar.
Input frames are still loaded eagerly into the self-contained HTML, not streamed
without limit. Slice the Python input or use CLI -i 0:1000:5 to limit memory and
HTML size when needed.
The embedded water vibration is an illustrative animation with synthetic energies, not a reaction calculation. Its captions switch between the first and second halves of the trajectory.
Box annotations
This runnable example uses ASE's built-in water fixture. Four copies are enough to show a frame-scoped cue; they aren't a simulated reaction. The atom list is reordered in the last two frames to demonstrate map-based selection.
import json
from pathlib import Path
import numpy as np
from ase.build import molecule
from ase.io import write
from aseview import MolecularViewer
water = molecule("H2O")
water.arrays["atom_map"] = np.array([13, 14, 20])
frames = [water.copy(), water.copy(), water[[2, 0, 1]], water[[2, 0, 1]]]
cues = [{
"id": "water-group",
"selector": {"kind": "map", "array": "atom_map", "values": [13, 14, 20]},
"frames": {"start": 0, "stop": 2},
"text": "First two loaded frames",
"color": "#f59e0b",
}]
viewer = MolecularViewer(frames, annotations=cues)
viewer.save_html("annotated-water.html")
write("annotated-water.extxyz", frames)
Path("water-cues.json").write_text(json.dumps(cues), encoding="utf-8")
Open annotated-water.html: frames 0 and 1 have a box and caption; frames 2
and 3 don't. The selector resolves map labels in each frame rather than reusing
positions in the atom list. Extend stop to 4 to keep the group selected after
the reordering.
The same inputs work from the CLI:
python -m aseview annotated-water.extxyz -v molecular --annotations water-cues.json -o annotated-water-cli.html
python -m aseview annotated-water.extxyz -v molecular --annotations water-cues.json -i ::2 -o annotated-water-sliced.html
The sliced command loads original frames 0 and 2 as loaded frames 0 and 1.
Its [0, 2) cue is therefore active on both. Write ranges against the loaded
trajectory, not the unsliced file. With several input files, keep
-v molecular; the default for several files is still overlay viewing.
For input precedence, frame-local atoms.info["aseview_annotations"], caption
placement, validation, and unsupported modes, see the
box annotation API.
Fixed camera framing
By default, the camera fits the first loaded frame. For a trajectory whose atoms move outside that extent, use the opt-in all-frame fit:
"all" fits one fixed extent to all loaded frames; "first" is the default.
Neither setting refits on each playback step. Boxes follow the projected
atoms, but captions don't reserve extra space in the camera fit.
Energy and Fmax plot
show_energy_plot=True plots the energy of each frame (from the calculator or
atoms.info["energy"]). When frames carry forces, the largest atomic force
(Fmax) is drawn on a second axis; turn it off with show_force_max_plot=False.
Click the plot to jump to a frame.
Force arrows
force_scale is the arrow length per eV/Å.
Playback and export
- The player plays, pauses and scrubs frames;
fpssets the speed. - The toolbar saves a GIF (scale, frame step) and copies the current frame or
every frame as
xyz,extxyz,ciforPOSCAR. - From Python:
viewer.save_gif("md.gif", fps=15, step=2)(needs the export extra).
PNG export from the toolbar uses the current frame and camera. Python
save_png() starts a fresh view at loaded frame 0, for both browser and native
backends. GIF export includes annotations on sampled frames; step or
max_frames can skip a cue shorter than the sampling interval. Use step=1
without thinning if every cue must appear. Keep records separately when using
Copy structure, which isn't an annotation-preservation workflow.
The LiteViewer and grid view play trajectories too.