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 |
|
|
|
Also include distance-guessed bonds in the bond graph used for wrap grouping |
|
|
|
Explicit center to wrap around. Usually leave as |
|
|
|
Unit-cell representation for triclinic boxes: |
Common variations#
# Wrap around a ligand instead of the whole protein
mol.wrap("resname LIG")
# Topology file is missing some bonds (e.g. small molecules in a plain PDB) —
# merge in distance-guessed bonds so the wrap groups stay intact
mol.wrap("protein", guessBonds=True)
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. For triclinic boxes you can also choose how the cell is wrapped with theunitcellparameter —"rectangular"(default, a parallelepiped),"triclinic", or"compact"(minimum-volume shape, handy for visualizing truncated octahedra or rhombic dodecahedra).wrapoperates on all frames in place.Molecules that are already centered in the box will be re-wrapped (the operation is applied regardless).