Working with trajectories

Working with trajectories#

Running FRETraj with Jupyter has the advantage that we can easily work with trajectories and other multi-model structures. As we saw in the previous notebook, FRETraj uses mdtraj to load single and multi-frame objects. For demonstrative purposes, we work here with an extract of an MD trajectory from our DNA hairpin. A more detailed notebook with the full trajectory is available at here.

import mdtraj as md
import fretraj as ft
from matplotlib import pyplot as plt
import seaborn as sns
import os
example_dir = '../../src/fretraj/examples/'
The burst submodule could not be imported

First, we load multiple snapshots of the DNA hairpin from a 1\(\,\mu\)s MD trajectory as well as the associated labeling parameters.

traj = md.load(os.path.join(example_dir+'DNA_hairpin.xtc'), 
               top=os.path.join(example_dir+'DNA_hairpin.pdb'),
               stride=10)
labels = ft.cloud.labeling_params(os.path.join(example_dir+'DNA_hairpin_labels.json'), verbose=False)
print(f'timestep: {traj.timestep/1000 :.0f} ns')
print(f'length: {traj.time[-1]/1000 :.0f} ns')
timestep: 100 ns
length: 1000 ns

Next, we calculate ACVs along the trajectory (here every 100 ns, for simplicity).

frames = range(int(traj.n_frames/2))
acv_D = ft.cloud.Volume.from_frames(traj, 'Cy3-20-C5', labels, frames)
acv_A = ft.cloud.Volume.from_frames(traj, 'Cy5-44-P1', labels, frames)

Likewise, we compute a mean FRET efficiency per snapshot and combine them into a FRET trajectory.

fret = ft.cloud.FRET.from_volumes(acv_D, acv_A, 'Cy3-Cy5', labels)
fret_traj = ft.cloud.Trajectory(fret, timestep=traj.timestep)
fret_traj.dataframe
<R_DA> (A) <E_DA> <R_DA_E> (A) R_attach (A) R_mp (A) time (ps)
0 51.0 0.58 51.2 44.4 48.2 0.0
1 51.1 0.58 51.2 43.5 48.4 100000.0
2 49.8 0.61 50.2 42.9 47.1 200000.0
3 50.6 0.59 50.8 43.8 47.9 300000.0
4 54.7 0.50 54.1 47.0 52.2 400000.0

Launch Binder 🚀 to visualize the multi-ACV trajectory.

acv_D_traj = ft.cloud.create_acv_traj(acv_D)
acv_A_traj = ft.cloud.create_acv_traj(acv_A)
ft.jupyter.nglview_trajectory_ACV(traj, acv_D_traj['FV'], acv_A_traj['FV'], acv_D_traj['CV'], acv_A_traj['CV'])