def run(self): u_coord = MDA.Universe(self.args.reference_path, self.args.coordinate_path) u_ref = MDA.Universe(self.args.reference_path) R_tot = RMS.RMSD(u_coord, u_ref) R_A = RMS.RMSD(u_coord, u_ref, select="bynum 1-70") R_B = RMS.RMSD(u_coord, u_ref, select="bynum 71-140") R_C = RMS.RMSD(u_coord, u_ref, select="bynum 141-210") for R in [R_tot, R_A, R_B, R_C]: R.run() tot_arr = R_tot.rmsd[:, 2] a_arr = R_A.rmsd[:, 2] b_arr = R_B.rmsd[:, 2] c_arr = R_C.rmsd[:, 2] time = R_tot.rmsd[:, 1] full_arr = numpy.vstack((time, tot_arr, a_arr, b_arr, c_arr)) numpy.save('output', full_arr)
def delta_proc(init, targ, traj, top = "/nfs/homes/tcolburn/Projects/Beckstein/Mhp1/top/2x79_r10_g470.psf", direction = "i2occ2o", label = "TC"): initial = mda.Universe(top, init) target = mda.Universe(top, targ) if type(traj) is str: trajectory = mda.Universe(top, traj) else: trajectory = traj r_init = rms.RMSD(trajectory, initial, select='name CA and protein') r_init.run() r_init.save("r_init_" + label) r_targ = rms.RMSD(trajectory, target, select='name CA and protein') r_targ.run() r_targ.save("r_targ" + label) rmsd_init = r_init.rmsd.T rmsd_targ = r_targ.rmsd.T del_rmsd = rmsd_init[2] - rmsd_targ[2] time = rmsd_init[1] return del_rmsd, time
def rmsd_traj(traj, ref, title): R = rms.RMSD(traj.select_atoms('name CA'), ref.select_atoms('name CA')).run() R = R.rmsd.T frame = R[0] time = R[1] plt.subplots(figsize=(10, 5)) fig = plt.plot(time / 1000, R[2], linewidth=0.2) plt.ylabel('RMSD ($\AA$)') plt.xlabel('time (ns)') plt.title(title) plt.show() return R, fig
def RMSD(u, PU_directory_output): # calcule le RMSD de la PU print("Processing RMSD...") Rmsd = rms.RMSD(u) Rmsd.run() rmsd = Rmsd.rmsd.T # utilisation de la transposée pour l'affichage time = rmsd[1] plt.figure() ax2 = plt.subplot(111) ax2.plot(time, rmsd[2], 'g-', label="RMSD") ax2.legend(loc="best") ax2.set_title("RMSD") ax2.set_xlabel("Time (ps)") ax2.set_ylabel(r"RMSD ($\AA$)") ax2.figure.savefig(PU_directory_output + "RMSD.png") print("Done!")
def test_rmsd_matrix_with_superimposition(self, ens1): conf_dist_matrix = encore.confdistmatrix.conformational_distance_matrix( ens1, encore.confdistmatrix.set_rmsd_matrix_elements, selection="name CA", pairwise_align=True, weights='mass', n_jobs=1) reference = rms.RMSD(ens1, select="name CA") reference.run() for i, rmsd in enumerate(reference.rmsd): assert_almost_equal( conf_dist_matrix[0, i], rmsd[2], decimal=3, err_msg= "calculated RMSD values differ from the reference implementation" )
import MDAnalysis as mda import matplotlib.pyplot as plt from MDAnalysis.analysis import align from MDAnalysis.analysis import rms import pandas as pd x = mda.Universe('AT3_3UIM_model1.B99990004_filt.pdb') a = mda.Universe('outI.pdb') align.AlignTraj(a,x,select='backbone or (resid 8 and name CB and resname ALA)',filename='aligned_AT3.I.pdb',match_atoms=True,dt=16).run() R = rms.RMSD(a,x,select='backbone or (resid 8 and name CB and resname ALA)') R.run() df = pd.DataFrame(R.rmsd,columns=['Frames','Time (ns)','backbone or (resid 8 and name CB and resname ALA)']) df.to_csv('rmsd_AT3.I.csv', index=False) fig = df.plot(x='Frames', y=['backbone or (resid 8 and name CB and resname ALA)'],kind='hist', figsize=(20, 16), fontsize=60, color=['#000004FF'], edgecolor="white", legend=False, xticks=[4,5,6,7]) fig.set_xlabel(r'RMSD ($\AA$)') for item in ([fig.title, fig.xaxis.label, fig.yaxis.label] + fig.get_xticklabels() + fig.get_yticklabels()): item.set_fontsize(60) fig.figure.savefig('rmsd_AT3.I.pdf')
def atom_rmsd(gro, trr, out, atom_name='AU', **kwargs): """Computes time resolved rmsd of atom group identified by atom name. rmsd(t) = sqrt(1/N*sum_i=1^N w_i*(x_i(t)-x_i^rev)^2) see https://www.mdanalysis.org/mdanalysis/documentation_pages/analysis/rms.html Units in output textfile are default MDAnalysis units. https://www.mdanalysis.org/mdanalysis/documentation_pages/units.html Parameters ---------- gro: str GROMACS gro coordinates file trr: str GROMACS trr trajectory file with N frames out: str output text file atom_name: str, optional defaults: 'AU' **kwargs: keyword arguments forwarded to MDAnalysis.analysis.rms.RMSD Output ------ out text file contains time [ps] and rmsd [Ang] in column vectors. """ comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() logger = logging.getLogger("%s:rank[%i/%i]" % (__name__, rank, size)) mda_trr = mda.Universe(gro, trr) atom_group = mda_trr.atoms[mda_trr.atoms.names == atom_name] rmsd_atom_group = mda_rms.RMSD(atom_group, ref_frame=0, **kwargs) # in the standard case #ranks > #frames, N = len(mda_trr.trajectory) span = N // size # special treatment for more ranks than frames if span < 1: # less frames than ranks span = 1 n1 = rank * span n2 = (rank + 1) * span if rank >= N: # treatment for rank > N n1 = 0 n2 = 0 # in this case, just return empty time_resolved_rdf elif rank == size - 1: # treatment for last rank if N >= size n2 = N if n2 > n1: logger.info("RMSD for frame %i to %i." % (n1, n2)) rmsd_atom_group.run(start=n1, stop=n2) data = rmsd_atom_group.rmsd[:, 1:] # time and rmsd in column vectors else: data = np.array([]) # format of rmsd: # rmsdT = rmsd_atom_group.rmsd.T # frame = rmsdT[0] # time = rmsdT[1] # rmsd = rmsdT[2] data_list = comm.gather(data, root=0) if rank == 0: filtered_data_list = [l for l in data_list if len(l) > 0] data = np.vstack(filtered_data_list) np.savetxt( out, data, fmt='%.8e', header='\n'.join(( '{modulename:s}, {username:s}@{hostname:s}, {timestamp:s}'. format( modulename=__name__, username=getpass.getuser(), hostname=socket.gethostname(), timestamp=str(datetime.datetime.now()), ), 'https://www.mdanalysis.org/mdanalysis/documentation_pages/analysis/rms.html', 'rmsd(t) = sqrt(1/N*sum_i=1^N w_i*(x_i(t)-x_i^rev)^2)', 'time [ps], rmsd [Ang]')))
def setup(self, select, weights): self.u = MDAnalysis.Universe(PSF, DCD) self.RMSD_inst = rms.RMSD(atomgroup=self.u, reference=None, select=select, weights=weights)
BCA = md.Universe('/home/cod33/foldon/templates/reference/BCA.pdb') BAC = md.Universe('/home/cod33/foldon/templates/reference/BAC.pdb') CAB = md.Universe('/home/cod33/foldon/templates/reference/CAB.pdb') CBA = md.Universe('/home/cod33/foldon/templates/reference/CBA.pdb') epsilons = ['0.20','0.21','0.22','0.23','0.24','0.25'] state = ['bound', 'unbound'] file_coords = ['MOVIE/movie.000000000.pdb','testout.xtc'] perms = [ABC,ACB,BCA,BAC,CAB,CBA] todos= [] for eps in epsilons: for stat in state: coords = md.Universe(os.path.join(eps, stat, file_coords[0]),os.path.join(eps,stat,file_coords[1])) for perm in perms: rmsd = rms.RMSD(coords,perm) rmsd_A = rms.RMSD(coords,perm,select='bynum 1-70') rmsd_B = rms.RMSD(coords,perm,select='bynum 71-140') rmsd_C = rms.RMSD(coords,perm,select='bynum 141-210') for R in [rmsd,rmsd_A,rmsd_B,rmsd_C]: R.run() full_arr = np.vstack((rmsd.rmsd[:,1],rmsd.rmsd[:,2],rmsd_A.rmsd[:,2],rmsd_B.rmsd[:,2],rmsd_C.rmsd[:,2])) todos.append(full_arr) np.save('todos',todos) #ok so todos has shape (96,5,10001). it goes bound, unbound by increments of six. #bound_25 = np.min(todos[0:6], axis=0) #unbound_25 = np.min(todos[6:12], axis=0) #bound_27 = np.min(todos[12:18], axis=0) #unbound_27 = np.min(todos[18:24], axis=0) #bound_29 = np.min(todos[24:30], axis=0) #unbound_29 = np.min(todos[30:36], axis=0)
min_rmsd_dcd_path = os.path.join(models_directory, target, 'min_rmsd_pairs.dcd') dcdw = DCD.DCDWriter(min_rmsd_dcd_path, u.atoms.numberOfAtoms()) # Each template will be added to the list uniques if it is further than # 0.2 Angstroms (RMSD) from the nearest template. uniques = [] min_rmsd = [] for (t, template) in enumerate(valid_templates): # Add the first template to the list of uniques if t == 0: uniques.append(template) continue # Cluster using CA atoms rmsd_obj = rms.RMSD(u, select='name CA') rmsd_obj.run(start=0, stop=t, ref_frame=t) rmsd = rmsd_obj.rmsd.swapaxes(0, 1)[2] min_rmsd.append(min(rmsd)) if min_rmsd[-1] < cutoff: if min_rmsd_option: dcdw.write(u.trajectory[t]) # write the current template # find the index of the nearest neighbor min_rmsd_index = list(rmsd).index(min_rmsd[-1]) dcdw.write( u.trajectory[min_rmsd_index]) # write the nearest neighbor u.trajectory[t] # go back to the current template continue else: uniques.append(template)
#!/usr/bin/env python #Corinn 17.5.25 #this should convert output data to numpy array, calculate RMSDs six times, take the minimum. import MDAnalysis as md import MDAnalysis.analysis.rms as rms import numpy as np import matplotlib.pyplot as plt import os file_coords = ['MOVIE/movie.000000000.pdb', 'testout.xtc'] todos = [] ref = md.Universe(os.path.join(file_coords[0])) coords = md.Universe(os.path.join(file_coords[0]), os.path.join(file_coords[1])) rmsd = rms.RMSD(coords, ref) rmsd_A = rms.RMSD(coords, ref, select='bynum 1-70') rmsd_B = rms.RMSD(coords, ref, select='bynum 91-161') rmsd_C = rms.RMSD(coords, ref, select='bynum 182-252') for R in [rmsd, rmsd_A, rmsd_B, rmsd_C]: R.run() full_arr = np.vstack((rmsd.rmsd[:, 1], rmsd.rmsd[:, 2], rmsd_A.rmsd[:, 2], rmsd_B.rmsd[:, 2], rmsd_C.rmsd[:, 2])) print(full_arr.shape) #todos.append(full_arr) #todoss = np.array(todos) np.save('todos.npy', full_arr) #ok so todos has shape (96,5,10001). it goes bound, unbound by increments of six. #bound_25 = np.min(todos[0:6], axis=0) #unbound_25 = np.min(todos[6:12], axis=0) #bound_27 = np.min(todos[12:18], axis=0)
#fig = plt.figure() ax = plt.subplot(111) ax.plot(ts.frame, rmsf, 'r--', lw=2, label="all") #plt.plot(ts, rmsf) ax.legend(loc="best") ax.set_xlabel("time (ps)") ax.set_ylabel(r"rmsf ($\AA$)") ax.figure.savefig("rmsf_all_t300i50.png") plt.draw() print(ts) ######################################## ############# RMSD ################## rd = rms.RMSD(al, filename=sys.argv[3]) rd.run() rd.save() rmsd = rd.rmsd.T time = rmsd[1] import seaborn.apionly as sns plt.style.use('ggplot') sns.set_style('ticks') fig = plt.figure(figuresize=(6, 6)) ax = fig.add_subplot(111) ax.plot(time, rmsd[2], 'b--', linewidth=2, label="All") ax.fill_between(protein.atoms.ids, R.rmsf, color="red", alpha=0.1)
references = [] for name in structure_names: u = md.Universe('isolated_289/new_' + name + '_fixed.pdb') references.append(u) ## Do smth for k, ref in enumerate(references): ## change folder name here folder = 'data/charmm36m/2us/' for i, j in enumerate(range(ind_start, ind_end)): struct = folder + 'chain.pdb' traj = folder + 'chain_{}.xtc'.format(j + 1) print(k, traj) sys.stdout.flush() system = md.Universe(struct, traj) R = rms.RMSD(system, reference=ref, select='not name H*') #R = rms.RMSD(system, reference=ref, select='backbone and not type H', groupselections=[state_selection]) R.run() rmsd_ = R.rmsd.T # transpose makes it easier for plotting local_rmsd[i, k] = rmsd_[2] #local_rmsd[i, k] = rmsd_[3] comm.barrier() ## Gather data comm.Gather(local_rmsd, rmsd, root=0) ## save or print if rank == 0: print(rmsd.shape) npy_file = '1_rmsd/charmm36m/rmsd_2us'
if symmetry: r = rmsd.symmrmsd(selection.atoms.positions, ref_positions, atomicmap, atomicmap, A, A) else: r = rmsd.rmsd(selection.atoms.positions, ref_positions, atomicmap, atomicmap) time.append(ts.time) rmsds.append(r) rmsd_nosymm.append( rmsd.rmsd(selection.atoms.positions, ref_positions, atomicmap, atomicmap)) # Check rmsd_nosymm is the same as rms.RMDS rmsd_mda = rms.RMSD(traj, ref, select="backbone", groupselections=["resname LIG"], ref_frame=iframe) R = rmsd_mda.run(verbose=True, step=step) assert np.allclose(rmsd_nosymm, R.results.rmsd[:, -1]) plt.plot(time, rmsds, label="symmrmsd") plt.plot(time, rmsd_nosymm, label="rmsd") plt.plot(time, R.results.rmsd[:, -1], label="mda") plt.xlabel("Time") plt.ylabel("RMSD") plt.legend() plt.savefig("rmsd.png")
import MDAnalysis.analysis.rms as rms import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt u = md.Universe('MOVIE/movie.000000000.pdb','testout.xtc') ref = md.Universe('/home/cod33/foldon/templates/references/1rfo_beads.pdb') #A = u.A.atoms #B = u.B.atoms #C = u.C.atoms #A_nterm = A[0:10] #A_cterm = A[-10:] #B_nterm = B[0:10] #B_cterm = B[-10:] #C_nterm = C[0:10] #C_cterm = C[-10:] A_nterm = rms.RMSD(u,ref,select='bynum 0-5') A_cterm = rms.RMSD(u,ref,select='bynum 65-70') B_nterm = rms.RMSD(u,ref,select='bynum 70-75') B_cterm = rms.RMSD(u,ref,select='bynum 135-140') C_nterm = rms.RMSD(u,ref,select='bynum 140-145') C_cterm = rms.RMSD(u,ref,select='bynum 205-210') for obj in [A_nterm,A_cterm,B_nterm,B_cterm,C_nterm,C_cterm]: obj.run() full_arr=[A_nterm.rmsd[:,0],A_nterm.rmsd[:,2],A_cterm.rmsd[:,2],B_nterm.rmsd[:,2],B_cterm.rmsd[:,2],C_nterm.rmsd[:,2],C_cterm.rmsd[:,2]] np.save('terms.npy',full_arr)