def test_gyration_radius(): stack = strucio.load_structure(join(data_dir("structure"), "1l2y.mmtf")) radii = struc.gyration_radius(stack) # Compare with results from MDTraj exp_radii = \ [7.30527532, 7.34189463, 7.21863721, 7.29877736, 7.25389752, 7.22292189, 7.20646252, 7.27215909, 7.30437723, 7.30455437, 7.37979331, 7.14176259, 7.20674397, 7.27594995, 7.31665835, 7.29850786, 7.34378951, 7.2642137, 7.20727158, 7.16336879, 7.3479218, 7.19362027, 7.24841519, 7.29229237, 7.15243826, 7.31285673, 7.22585756, 7.25467109, 7.3493648, 7.34203588, 7.3310182, 7.29236536, 7.20527373, 7.33138918, 7.2284936, 7.40374312, 7.24856173, 7.25581809] assert radii.tolist() == pytest.approx(exp_radii, abs=2e-2) # Same for atom array instead of stack array = stack[0] radius = struc.gyration_radius(array) assert radius == pytest.approx(exp_radii[0], abs=2e-2)
print(" ... writing frame[1] ... ") frame_1 = template_model.copy() frame_1.coord = trajectory[1].coord save_structure("frame_1_coord.pdb", frame_1) save_structure("frame_1.pdb", trajectory[1]) print(" ... done ... ") print(" ... writing end frame ...") frame_end = template_model.copy() frame_end.coord = trajectory[-1].coord save_structure("frame_end_coord.pdb", frame_end) save_structure("frame_end.pdb", trajectory[-1]) print(" ... done ... ") rmsd_overall = struc.rmsd(trajectory[0], trajectory) radius_overall = struc.gyration_radius(trajectory) # kinase left trajectory_kinase_left, transform = struc.superimpose( trajectory_kinase_left[0], trajectory_kinase_left) rmsd_kinase_left = struc.rmsd(trajectory_kinase_left[0], trajectory_kinase_left) radius_kinase_left = struc.gyration_radius(trajectory_kinase_left) # kinase right trajectory_kinase_right, transform = struc.superimpose( trajectory_kinase_right[0], trajectory_kinase_right) rmsd_kinase_right = struc.rmsd(trajectory_kinase_right[0], trajectory_kinase_right) radius_kinase_right = struc.gyration_radius(trajectory_kinase_right)
ax.set_ylabel("RMSD (Angstrom)") figure.tight_layout() ######################################################################## # As we can see the simulation seems to converge already in the # beginning of the simulation. After a few ps the RMSD stays in a range # of approx. 2 - 3 Angstrom. However it seems like there are two kinds # of quasi-dicrete states as the two plateaus suggest. For further # investigation we would require more simulation time. # # In order to better evaluate the unfolding of our miniprotein in the # course of simulation, we calculate and plot the radius of gyration # (a measure for the protein radius). radius = struc.gyration_radius(trajectory) figure = plt.figure(figsize=(6,3)) ax = figure.add_subplot(111) ax.plot(time, radius, color=biotite.colors["dimorange"]) ax.set_xlim(0,1000) ax.set_xlabel("Time (ps)") ax.set_ylabel("Radius of gyration (Angstrom)") figure.tight_layout() ######################################################################## # From this perspective, the protein seems really stable. # The radius does merely fluctuate in a range of approx. 0.5 Angstrom # during the entire simulation. # # Let's have a look at single amino acids:
def rmsf_plot(topology, xtc_traj, start_frame=None, stop_frame=None, write_dat_files=None): # Gromacs does not set the element symbol in its PDB files, # but Biotite guesses the element names from the atom names, # emitting a warning template = strucio.load_structure(topology) # The structure still has water and ions, that are not needed for our # calculations, we are only interested in the protein itself # These are removed for the sake of computational speed using a boolean # mask protein_mask = struc.filter_amino_acids(template) template = template[protein_mask] residue_names = struc.get_residues(template)[1] xtc_file = XTCFile() xtc_file.read(xtc_traj, atom_i=np.where(protein_mask)[0], start=start_frame, stop=stop_frame + 1) trajectory = xtc_file.get_structure(template) time = xtc_file.get_time() # Get simulation time for plotting purposes trajectory = struc.remove_pbc(trajectory) trajectory, transform = struc.superimpose(trajectory[0], trajectory) rmsd = struc.rmsd(trajectory[0], trajectory) figure = plt.figure(figsize=(6, 3)) ax = figure.add_subplot(111) ax.plot(time, rmsd, color=biotite.colors["dimorange"]) ax.set_xlim(time[0], time[-1]) ax.set_ylim(0, 2) ax.set_xlabel("Time (ps)") ax.set_ylabel("RMSD (Å)") figure.tight_layout() radius = struc.gyration_radius(trajectory) figure = plt.figure(figsize=(6, 3)) ax = figure.add_subplot(111) ax.plot(time, radius, color=biotite.colors["dimorange"]) ax.set_xlim(time[0], time[-1]) ax.set_ylim(14.0, 14.5) ax.set_xlabel("Time (ps)") ax.set_ylabel("Radius of gyration (Å)") figure.tight_layout() # In all models, mask the CA atoms ca_trajectory = trajectory[:, trajectory.atom_name == "CA"] rmsf = struc.rmsf(struc.average(ca_trajectory), ca_trajectory) figure = plt.figure(figsize=(6, 3)) ax = figure.add_subplot(111) res_count = struc.get_residue_count(trajectory) ax.plot(np.arange(1, res_count + 1), rmsf, color=biotite.colors["dimorange"]) ax.set_xlim(1, res_count) ax.set_ylim(0, 1.5) ax.set_xlabel("Residue") ax.set_ylabel("RMSF (Å)") figure.tight_layout() if write_dat_files == True: # Write RMSD *.dat file frames = np.array(range(start_frame - 1, stop_frame), dtype=int) frames[0] = 0 df = pd.DataFrame(data=rmsd, index=frames, columns=["RMSD Values"]) df.index.name = 'Frames' df.to_csv('rmsd.dat', header=True, index=True, sep='\t', mode='w') # Write RMSF *.dat file df1 = pd.DataFrame(data=rmsf, index=residue_names, columns=["RMSF Values"]) df1.index.name = 'Residues' df1.to_csv('rmsf.dat', header=True, index=True, sep='\t', mode='w') plt.show()