Skip to main content

AlignPlan

Align trajectory frames by superposition to a reference structure.

Constructor

from warp_md import AlignPlan

plan = AlignPlan(
    selection,
    reference_mode="first",
    mass_weighted=False
)
selection
Selection
required
Atoms to use for alignment (typically backbone or C-alpha)
reference_mode
str
default:"first"
Reference structure:
  • "first": First frame
  • "average": Average structure
  • Integer: Specific frame index
mass_weighted
bool
default:"False"
Use mass-weighted alignment

run() Method

Returns: Modified trajectory with all atoms aligned

Example

import warp_md as wmd

system = wmd.System("protein.pdb")
traj = wmd.open_trajectory("md.xtc", system)

# Align on backbone
backbone = system.select("backbone")
plan = wmd.AlignPlan(backbone, reference_mode="first")
aligned_traj = plan.run(traj, system)

# Write aligned trajectory
wmd.write_trajectory("aligned.xtc", aligned_traj, system)
Alignment is essential before RMSD or RMSF calculations to remove overall rotation and translation.

AutoImagePlan

Automatically image molecules into the primary simulation box.

Constructor

plan = AutoImagePlan(
    anchor_selection=None,
    center=True
)
anchor_selection
Selection
Molecule to keep centered (e.g., protein). If None, uses largest molecule
center
bool
default:"True"
Center anchor in the box

Example

# Fix periodic boundary artifacts
protein = system.select("protein")

plan = wmd.AutoImagePlan(
    anchor_selection=protein,
    center=True
)

imaged_traj = plan.run(traj, system)

# Now molecules are properly wrapped
wmd.write_trajectory("imaged.nc", imaged_traj, system)
Always apply imaging before visualization or analysis to avoid broken molecules across periodic boundaries.

CenterTrajectoryPlan

Center a selection in the simulation box.

Constructor

plan = CenterTrajectoryPlan(
    selection,
    mass_weighted=True
)
selection
Selection
required
Atoms to center on
mass_weighted
bool
default:"True"
Use center of mass (True) or geometric center (False)

Example

# Center protein in box
protein = system.select("protein")

plan = wmd.CenterTrajectoryPlan(protein, mass_weighted=True)
centered_traj = plan.run(traj, system)

StripPlan

Remove atoms from trajectory.

Constructor

plan = StripPlan(selection_to_keep)
selection_to_keep
Selection
required
Atoms to retain (all others will be removed)

Example

# Strip water and ions for smaller trajectory
protein_ligand = system.select("protein or resname LIG")

plan = wmd.StripPlan(protein_ligand)
stripped_traj = plan.run(traj, system)

# Create new system without water
stripped_system = system.select_atoms(protein_ligand)
wmd.write_trajectory("protein_only.xtc", stripped_traj, stripped_system)
Stripping solvent can reduce file sizes by 10-50x for analysis and visualization.

Python Helper Functions

from warp_md.analysis import (
    align,
    autoimage,
    center,
    strip
)

# High-level alignment
aligned_traj = align(
    traj,
    system,
    mask="backbone",
    ref=0  # Reference frame index
)

# Auto-imaging
imaged_traj = autoimage(
    traj,
    system,
    anchor="protein"
)

# Centering
centered_traj = center(
    traj,
    system,
    mask="protein"
)

# Stripping
stripped_traj = strip(
    traj,
    system,
    mask="protein or resname LIG"
)

Combined Workflow Example

import warp_md as wmd
from warp_md.analysis import autoimage, center, align, strip

# Load trajectory
system = wmd.System("system.prmtop")
traj = wmd.open_trajectory("production.nc", system)

print(f"Original trajectory: {traj.n_frames} frames, {system.n_atoms()} atoms")

# Step 1: Fix periodic boundaries
traj = autoimage(traj, system, anchor="protein")

# Step 2: Center on protein
traj = center(traj, system, mask="protein")

# Step 3: Align on backbone
traj = align(traj, system, mask="backbone", ref="average")

# Step 4: Strip solvent
traj = strip(traj, system, mask="protein or resname LIG")

print(f"Processed trajectory: {traj.n_frames} frames")

# Save
processed_system = system.select_atoms(
    system.select("protein or resname LIG")
)
wmd.write_trajectory("processed.xtc", traj, processed_system)
processed_system.write_pdb("processed.pdb")

print("Workflow complete!")

Frame Selection During Processing

# Process only equilibrated frames
equil_frames = range(1000, 10000)  # Skip first 1000 frames

backbone = system.select("backbone")
plan = wmd.AlignPlan(backbone, reference_mode="first")
aligned = plan.run(
    traj,
    system,
    frame_indices=equil_frames
)

Additional Transform Plans

Additional trajectory transform plans are available:
  • ImagePlan — Apply periodic boundary imaging
  • ReplicateCellPlan — Replicate unit cell in 3D
  • XtalSymmPlan — Apply crystallographic symmetry operations
  • SuperposePlan — Superpose selection onto reference
  • TranslatePlan — Translate coordinates by vector
  • RotatePlan — Rotate coordinates around axis
  • ScalePlan — Scale coordinates
  • TransformPlan — Apply arbitrary transformation matrix
  • MeanStructurePlan — Calculate mean structure
  • MakeStructurePlan — Create structure from coordinates
  • AverageFramePlan — Average coordinates across frames
Use warp-md list-plans --category transforms to see detailed parameters for all transform plans.

Build docs developers (and LLMs) love