How to wrap trajectories#
Goal#
Re-image atoms into the central periodic box so that molecules appear whole rather than split across box boundaries.
Minimal example#
from moleculekit.molecule import Molecule
mol = Molecule("topology.psf")
mol.read("trajectory.xtc")
# Wrap and center the box on the protein
mol.wrap("protein")
Parameters that matter#
Parameter |
Type |
Default |
What it does |
|---|---|---|---|
|
|
|
Atom selection that defines the center of the wrapping box |
|
|
|
Use bonds from the loaded topology file |
|
|
|
Fall back to distance-based bond guessing if |
Common variations#
# Wrap around a ligand instead of the whole protein
mol.wrap("resname LIG")
# Topology file has complete bonds — skip guessing for speed
mol.wrap("protein", guessBonds=False)
Gotchas#
Wrapping requires a valid
mol.boxarray (one column per frame). Ifmol.boxis all zeros,wraplogs a warning and returns without modifying coordinates — the originalmolis unchanged.Non-orthorhombic (triclinic) boxes use
mol.boxanglesin addition tomol.box; make sure both are read from the trajectory.wrapoperates on all frames in place.Molecules that are already centered in the box will be re-wrapped (the operation is applied regardless).