Trajectory Performance Analysis#
Task: Calculate the RMSD of a multi-frame trajectory against a reference structure and plot the results in a single workflow.
MolSysMT is optimized for speed. This recipe demonstrates how to process a trajectory with an explicit CPU resource policy and visualize structural stability.
import molsysmt as msm
from molsysmt import systems
import matplotlib.pyplot as plt
import numpy as np
# Load a solvated trajectory (Villin Headpiece)
topology = systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm']
trajectory = systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.dcd']
molecular_system = msm.convert([topology, trajectory], to_form='molsysmt.MolSys')
# Default for the working session; -1 means all processors available to it.
msm.configure.set_parallelization(parallel='auto', num_threads=-1)
1. Fast RMSD Calculation#
We calculate the root-mean-square deviation for the backbone atoms. This call uses at most four worker threads without changing the session default.
rmsd = msm.structure.get_rmsd(molecular_system, selection='backbone',
reference_structure_index=0,
parallel=True, num_threads=4)
structure_indices = np.arange(rmsd.shape[0])
print(f"Processed {len(rmsd)} frames.")
2. Plotting Stability#
Using standard plotting tools with MolSysMT data is straightforward.
plt.plot(structure_indices, msm.pyunitwizard.get_value(rmsd, to_unit='nm'))
plt.xlabel('Structure index')
plt.ylabel('RMSD (nm)')
plt.title('Structural Stability of Villin HP35')
plt.show()