Episode 5 - Trajectory analysis with MDTraj¶

Simple track: alanine RMSD¶

In this notebook you analyze trajectories with MDAnalysis. You will compute alanine RMSD and validate the analysis workflow.

Table of contents¶

  • Simple track: alanine RMSD
  • Simple track: alanine RMSD
  • Step 1

Read the alanine trajectory with MDTraj, reimage it, and quantify RMSD metrics for the simple system.

Step 1¶

In [ ]:
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path

import mdtraj as md
import matplotlib.pyplot as plt
COURSE_DIR = Path(os.environ.get("COURSE_DIR", str(Path.home() / "Concepcion26"))).expanduser()


def main() -> None:
    parser = argparse.ArgumentParser(description="Analyse alanine dipeptide trajectory")
    parser.add_argument("-p", "--protein", default="alanine-dipeptide.pdb", help="PDB file")
    parser.add_argument("-t", "--trajectory", default="traj.dcd", help="Trajectory DCD file")
    parser.add_argument("-o", "--output", default="rmsd_alanine.png", help="Output figure")
    args = parser.parse_args()

    out_dir = COURSE_DIR / "results" / "04-analisis-trayectorias" / "simple"
    out_dir.mkdir(parents=True, exist_ok=True)
    output_path = out_dir / args.output

    traj = md.load(args.trajectory, top=args.protein)
    rmsd = md.rmsd(traj, traj, frame=0)

    plt.plot(rmsd)
    plt.xlabel("Frame")
    plt.ylabel("RMSD (nm)")
    plt.title("Alanine dipeptide RMSD")
    plt.savefig(output_path, dpi=150)
    print("Written", output_path)


if __name__ == "__main__":
    main()