The four core analyses that handle 80% of molecular dynamics workflows. Master these patterns and your agent can tackle most trajectory analysis tasks.
Radius of Gyration (Rg)
Question answered: How compact is this structure?
from warp_md import System, RgPlan
system = System.from_pdb( "protein.pdb" )
traj = system.open_trajectory( "trajectory.xtc" )
plan = RgPlan(
selection = system.select( "name CA" ),
mass_weighted = False # or True for mass-weighted Rg
)
rg = plan.run(traj, system, device = "auto" )
print ( f "Shape: { rg.shape } " ) # (n_frames,)
print ( f "Mean Rg: { rg.mean() :.2f} Å" )
Output : 1D array with one Rg value per frame. Simple, clean, and GPU-accelerated.
Root Mean Square Deviation (RMSD)
Question answered: How much has the structure changed from the reference?
from warp_md import RmsdPlan
plan = RmsdPlan(
selection = system.select( "backbone" ),
reference = "topology" , # compare against initial structure
align = True # superimpose before measuring
)
rmsd = plan.run(traj, system, device = "auto" )
print ( f "Final RMSD: { rmsd[ - 1 ] :.2f} Å" )
Reference Options
Alignment
Reference What It Compares Against "topology"Initial PDB/GRO coordinates "frame0"First trajectory frame
alignBehavior trueSuperimpose before RMSD (recommended) falseRaw RMSD without fitting
Mean Square Displacement (MSD)
Question answered: How far are molecules diffusing?
from warp_md import MsdPlan
plan = MsdPlan(
selection = system.select( "resname SOL and name OW" ),
group_by = "resid" , # treat each water molecule as a unit
)
time, msd = plan.run(traj, system, device = "auto" )
print ( f "Time points: { len (time) } " )
print ( f "MSD shape: { msd.shape } " )
Advanced MSD Options
plan = MsdPlan(
selection = system.select( "resname SOL" ),
group_by = "resid" ,
axis = [ 0.0 , 0.0 , 1.0 ], # project onto z-axis
frame_decimation = ( 100 , 100 ), # start at frame 100, stride 100
lag_mode = "multi_tau" , # bounded memory for long trajectories
)
Mode Description When to Use "auto"FFT if fits memory, else multi-tau Default (let warp-md decide) "multi_tau"Log-spaced lags, bounded memory Long trajectories "ring"Exact up to max_lag Short-time validation "fft"Exact all lags Short trajectories
Radial Distribution Function (RDF)
Question answered: What’s the local structure around each atom?
from warp_md import RdfPlan
plan = RdfPlan(
sel_a = system.select( "resname SOL and name OW" ),
sel_b = system.select( "resname SOL and name OW" ),
bins = 200 ,
r_max = 10.0 ,
pbc = "orthorhombic"
)
r, g, counts = plan.run(traj, system)
print ( f "First peak at r = { r[g.argmax()] :.2f} Å" )
Output :
r: bin centers (Å)
g: g(r) values (normalized radial distribution)
counts: raw pair counts
Complete Example: All Four at Once
from warp_md import System, Trajectory
from warp_md import RgPlan, RmsdPlan, MsdPlan, RdfPlan
# Load system and trajectory
system = System.from_pdb( "solvated_protein.pdb" )
traj = Trajectory.open_xtc( "production.xtc" , system)
# Define selections
protein = system.select( "protein" )
backbone = system.select( "backbone" )
water_o = system.select( "resname SOL and name OW" )
# Run all four analyses
rg = RgPlan(protein).run(traj, system)
rmsd = RmsdPlan(backbone, reference = "topology" , align = True ).run(traj, system)
time, msd = MsdPlan(water_o, group_by = "resid" ).run(traj, system)
r, g, _ = RdfPlan(water_o, water_o, bins = 200 , r_max = 10.0 ).run(traj, system)
# Results
print ( f "Rg: { rg.mean() :.2f} ± { rg.std() :.2f} Å" )
print ( f "RMSD: { rmsd.mean() :.2f} ± { rmsd.std() :.2f} Å" )
print ( f "RDF first peak: { r[g.argmax()] :.2f} Å" )
Four comprehensive analyses in 15 lines. GPU-accelerated when available.
JSON Config for Batch Analysis
{
"version" : "warp-md.agent.v1" ,
"run_id" : "protein-analysis" ,
"system" : { "path" : "solvated_protein.pdb" },
"trajectory" : { "path" : "production.xtc" },
"device" : "auto" ,
"output_dir" : "outputs" ,
"analyses" : [
{
"name" : "rg" ,
"selection" : "protein" ,
"mass_weighted" : false
},
{
"name" : "rmsd" ,
"selection" : "backbone" ,
"reference" : "topology" ,
"align" : true
},
{
"name" : "msd" ,
"selection" : "resname SOL and name OW" ,
"group_by" : "resid" ,
"lag_mode" : "multi_tau"
},
{
"name" : "rdf" ,
"sel_a" : "resname SOL and name OW" ,
"sel_b" : "resname SOL and name OW" ,
"bins" : 200 ,
"r_max" : 10.0
}
]
}
warp-md run config.json --stream ndjson
Use GPU Set device="auto" to use CUDA when available. Typical speedups: 8-15x for Rg/RDF/MSD.
Chunk Frames For large trajectories, adjust chunk_frames to optimize memory: plan.run(traj, system, device = "cuda" , chunk_frames = 1000 )
Multi-tau for MSD Use lag_mode="multi_tau" for long trajectories to avoid memory issues.
Batch Analyses Load trajectory once, run multiple analyses. Use config runner for complex workflows.
See Also