<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Contact Trajectories
Sometimes you're interested in how contacts evolve in a trajectory, frame-by-frame. Contact Map Explorer provides the ContactTrajectory class for this purpose.
We'll look at this using a trajectory of a specific inhibitor during its binding process to GSK3B. This system is also studied in the notebook on contact concurrences (with very similar initial discussion).
Step1:  First, we'll use MDTraj's atom selection language to split out the protein and the ligand, which has residue name YYG in the input files. We're only interested in contacts between the protein and the ligand (not contacts within the protein). We'll also only look at heavy atom contacts.
Step2:  Making an accessing a contact trajectory
Contact trajectories have the same keyword arguments as other contact objects
Step3:  Once the ContactTrajectory has been made, contacts for individual frames can be accessed either by taking the index of the ContactTrajectory itself, or by getting the list of contact (e.g., all the residue contacts frame-by-frame) and selecting the frame of interest.
Step4:  Advanced Python indexing is also allowed. In this example, note how the most common partners for YYG change! This is also what we see in the contact concurrences example.
Step5:  We can easily turn the ContactTrajectory into ContactFrequency
Step6:  Rolling Contact Frequencies
A ContactTrajectory keeps all the time-dependent information about the contacts, whereas a ContactFrequency, as plotted above, loses all of it. What about something in between? For this, we have a RollingContactFrequency, which acts like a rolling average. It creates a contact frequency over a certain window of frames, with a certain step size between each window.
This can be created either with the RollingContactFrequency object, or, more easily, with the ContactTrajectory.rolling_frequency() method.
Step7:  Now we'll plot each windowed frequency, and we will see the transition as some contacts fade out and others grow in.
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from contact_map import ContactTrajectory, RollingContactFrequency
import mdtraj as md
traj = md.load("data/gsk3b_example.h5")
print(traj)  # to see number of frames; size of system
Explanation: Contact Trajectories
Sometimes you're interested in how contacts evolve in a trajectory, frame-by-frame. Contact Map Explorer provides the ContactTrajectory class for this purpose.
We'll look at this using a trajectory of a specific inhibitor during its binding process to GSK3B. This system is also studied in the notebook on contact concurrences (with very similar initial discussion).
End of explanation
topology = traj.topology
yyg = topology.select('resname YYG and element != "H"')
protein = topology.select('protein and element != "H"')
Explanation: First, we'll use MDTraj's atom selection language to split out the protein and the ligand, which has residue name YYG in the input files. We're only interested in contacts between the protein and the ligand (not contacts within the protein). We'll also only look at heavy atom contacts.
End of explanation
contacts = ContactTrajectory(traj, query=yyg, haystack=protein)
Explanation: Making an accessing a contact trajectory
Contact trajectories have the same keyword arguments as other contact objects
End of explanation
contacts[0].residue_contacts.most_common()
contacts.residue_contacts[0].most_common()
Explanation: Once the ContactTrajectory has been made, contacts for individual frames can be accessed either by taking the index of the ContactTrajectory itself, or by getting the list of contact (e.g., all the residue contacts frame-by-frame) and selecting the frame of interest.
End of explanation
for contact in contacts[50:80:4]:
    print(contact.residue_contacts.most_common()[:3])
Explanation: Advanced Python indexing is also allowed. In this example, note how the most common partners for YYG change! This is also what we see in the contact concurrences example.
End of explanation
freq = contacts.contact_frequency()
fig, ax = plt.subplots(figsize=(5.5,5))
freq.residue_contacts.plot_axes(ax=ax)
Explanation: We can easily turn the ContactTrajectory into ContactFrequency:
End of explanation
RollingContactFrequency(contacts, width=30, step=14)
rolling_frequencies = contacts.rolling_frequency(window_size=30, step=14)
rolling_frequencies
Explanation: Rolling Contact Frequencies
A ContactTrajectory keeps all the time-dependent information about the contacts, whereas a ContactFrequency, as plotted above, loses all of it. What about something in between? For this, we have a RollingContactFrequency, which acts like a rolling average. It creates a contact frequency over a certain window of frames, with a certain step size between each window.
This can be created either with the RollingContactFrequency object, or, more easily, with the ContactTrajectory.rolling_frequency() method.
End of explanation
fig, axs = plt.subplots(3, 2, figsize=(12, 10))
for ax, freq in zip(axs.flatten(), rolling_frequencies):
    freq.residue_contacts.plot_axes(ax=ax)
Explanation: Now we'll plot each windowed frequency, and we will see the transition as some contacts fade out and others grow in.
End of explanation
<END_TASK>