Radius of gyration vs time¶

Uses MDAnalysis to compute the metric for protein2. The workflow mirrors the analysis scripts at https://github.com/JordiVillaFreixa/Pau_TFG_DAO/tree/main/analysis.

Table of contents¶

  • Radius of gyration vs time
  • Radius of gyration vs time
  • Step 1

Step 1¶

In [ ]:
from pathlib import Path
import os
import matplotlib.pyplot as plt
import MDAnalysis as mda
import pandas as pd

COURSE_DIR = Path(os.environ.get('COURSE_DIR','~/Concepcion26')).expanduser()
topo = COURSE_DIR / 'data' / 'complex' / 'protein2.pdb'
traj = COURSE_DIR / 'results' / '03-simulaciones-clasicas' / 'complex' / 'output_traj.dcd'
if not topo.exists() or not traj.exists():
    raise FileNotFoundError(f'Run Episode 3 scripts so {traj!s} exists')

u = mda.Universe(topo, traj)
protein = u.select_atoms('protein')
rg = []
time = []
for ts in u.trajectory:
    time.append(ts.time)
    rg.append(protein.radius_of_gyration())
df = pd.DataFrame({'Time (ps)': time, 'R_g (Å)': rg})
fig, ax = plt.subplots()
ax.plot(df['Time (ps)'], df['R_g (Å)'])
ax.set_xlabel('Time (ps)')
ax.set_ylabel('Radius of gyration (Å)')
ax.set_title('Radius of gyration trajectory')
ax.grid(True)
fig.tight_layout()
fig.savefig('rg.png')
print(df.head())