Visualize forces#

You will learn: how to render per-atom force vectors in VMD on top of a trajectory frame — useful when debugging a crash and the cause isn’t obvious from coordinates alone.

Prerequisites:

  • A trajectory (output.xtc) and a matching forces file (forces.xtc) produced by setting trajforcefile: "forces.xtc" in the ACEMD input.

  • VMD installed and on PATH.

Setup#

Forces are written into an XTC by ACEMD when trajforcefile is set. Format-wise, an XTC normally holds coordinates — ACEMD reuses it to store force vectors instead.

from acemd.utils import view_forces
from moleculekit.molecule import Molecule

mol = Molecule("structure.prmtop")
mol.read("output.xtc")
view_forces(mol, "forces.xtc", step=0)

step=0 picks the first frame; bump it to look at later frames.

VMD opens with the molecule plus an arrow per atom — direction and length follow the force vector.

Parameters that matter#

view_forces() accepts:

  • step — trajectory frame index to visualise.

  • threshold (default 500) — atoms with force magnitude (in kcal/mol/Å) below this are not drawn. Raise to declutter; lower to see weaker forces.

  • normalize (default True) — when true, every drawn arrow is rendered at unit length so a few huge forces don’t dominate the view. The default is what you want for finding the source of a crash.

  • scalef (default 100) — divisor applied to each force vector before drawing. Larger scalef → shorter arrows. Has no effect when normalize=True because the subsequent unit-vector step cancels it; only set it when you have switched normalize=False to draw arrows whose lengths actually encode force magnitude.

Reading the picture#

Wait a moment for VMD to finish drawing — the per-atom arrows are added one at a time and the scene is slow to converge. The bigger the arrow, the larger the force. Atoms surrounded by abnormally long arrows are where the simulation is breaking down — look at their immediate neighbours for the clash, mis-parameterised residue, or extrapolating NNP atom.

See also#