Path B - Module 47: Trajectory Management (Slicing)#
In an industrial pipeline, you might simulate hundreds of different PETase mutants. Storing every single structure of every simulation is inefficient. You need to know how to filter, slice, and sub-sample your data to keep only the scientifically relevant parts.
In this module, you will learn to manage trajectory fragments using MolSysMT.
import molsysmt as msm
from molsysmt import systems
# Load a simulation trajectory of our enzyme
villin_traj = systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.dcd']
villin_topo = systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5msm']
molsys = [villin_topo, villin_traj]
1. Temporal Slicing#
You can extract specific time windows from your trajectory. For example, let’s keep only the last 10 structures, where the system is presumably equilibrated.
n_structures = msm.get(molsys, element='system', n_structures=True)
print(f"Total simulation structures: {n_structures}")
# Extract the equilibrated part (last 10 structures)
equilibrated_traj = msm.extract(molsys, structure_indices=range(n_structures-10, n_structures))
print(f"Equilibrated structures: {msm.get(equilibrated_traj, element='system', n_structures=True)}")
2. Striding (Data Reduction)#
To generate a movie or a quick report, you can take every 10th structure. This reduces the file size by 90% while maintaining the overall narrative of the motion.
# Sub-sample the trajectory taking 1 structure every 10
short_traj = msm.extract(molsys, structure_indices=range(0, n_structures, 10))
print(f"Reduced trajectory structures: {msm.get(short_traj, element='system', n_structures=True)}")
3. Merging Trajectory Fragments#
If your supercomputer job crashed and you had to restart it, you can join the two resulting files into a single virtual object.
# Simulate two parts of a trajectory; coordinate-only parts may share one topology
part_a = msm.extract(molsys, structure_indices=range(0, 10))
part_b = msm.extract(molsys, structure_indices=range(10, 20))
# Concatenate them
full_run = msm.concatenate_structures([part_a, part_b])
print(f"Total concatenated structures: {msm.get(full_run, element='system', n_structures=True)}")
Tier-1 XYZ, DCD, and XTC conversion routes have exhaustive coordinate-trajectory reports. Atom selections are materialized in canonical increasing order, while structure_indices keeps the requested order; target formats that cannot carry a value report the omission explicitly.
🏆 Path B Challenge: The Data Curator#
Create a trajectory that contains only the first 10 and the last 10 structures of the PETase simulation.
Check if the Structure IDs are reindexed or if they keep their original time labels.
Use
msm.get(..., structure_id=True)to verify.
Managing data size is critical for industrial efficiency. In Module 48, we will learn how to process files that are larger than your RAM using Iterators.