Skip to content

Trajectory Animation

Visualize molecular dynamics trajectories with animation, energy plots, and max-force traces.

Live Demo


Basic Usage

from ase.io import read
from aseview import MolecularViewer

trajectory = read("md_trajectory.xyz", index=":")
viewer = MolecularViewer(trajectory)
viewer.show()
aseview md_trajectory.xyz

Frame Selection

Index Result
-i : All frames
-i 0:10 Frames 0-9
-i ::2 Every 2nd frame
-i -1 Last frame only
-i -20: Last 20 frames

Energy and Force-Max Plot

Display energy synchronized with animation:

viewer = MolecularViewer(trajectory, showEnergyPlot=True)
viewer.show()

Energy is extracted from atoms.get_potential_energy() or atoms.info['energy']. When force arrays are available, the same plot can also show the per-frame maximum force:

viewer = MolecularViewer(
    trajectory,
    showEnergyPlot=True,
    showForceMaxPlot=True,
)
viewer.show()

showForceMaxPlot only affects the plotted fmax trace. Use showForces=True to draw force vectors on atoms.


Force Vectors

Display force vectors on atoms:

viewer = MolecularViewer(trajectory, showForces=True, forceScale=2.0)
viewer.show()

Animation Controls

Control Description
Play/Pause Toggle animation
Frame slider Jump to frame
Copy format chip Cycle copy format: xyz, extxyz, cif, POSCAR
Copy frame Copy current frame using the selected format
Copy all Copy entire trajectory using the selected format

extxyz and POSCAR include cell and fixed/move-mask constraint data when present. cif includes cell data but ignores constraints.


Saving

viewer = MolecularViewer(trajectory, showEnergyPlot=True)
viewer.save_html("trajectory.html")