def combine_trj_without_water(trj_names,top_names): print "loaded TRJ: ",trj_names print "loaded TOP: ",top_names trj=md.load_mdcrd(trj_names[0], top_names[0]) #We load the first traj atom_index=[] #atoms # that will be kept in the new traj for el in trj.top.atoms: #We select the atom that are not water if str(el.residue)[0:3]!='HOH': atom_index.append(el.index) trj=trj.atom_slice(atom_index) #We keep only the non water atom for trj_temp_name, top_temp_name in zip(trj_names[1:],top_names[1:]): #We concatenate the trj: trj_temp=md.load_mdcrd(trj_temp_name, top_temp_name) # we load them trj_temp=trj_temp.atom_slice(atom_index) # we remove water trj.join(trj_temp) # we join them to the main trj return(trj)
def test_ComparetoMDtraj(self): import mdtraj as md traj = pt.load(filename="./data/Tc5b.x", top="./data/Tc5b.top") m_top = md.load_prmtop("./data/Tc5b.top") m_traj = md.load_mdcrd("./data/Tc5b.x", m_top) m_traj.xyz = m_traj.xyz * 10 # convert `nm` to `Angstrom` unit arr0 = pt.rmsd(traj, ref=0) arr1 = pt.rmsd(traj, ref=0) arr2 = pt.rmsd(traj, ) a_md0 = md.rmsd(m_traj, m_traj, 0) aa_eq(arr0, arr1) aa_eq(arr0, arr2) aa_eq(arr0, a_md0) arr0 = pt.rmsd(traj, ref=-1) arr1 = pt.rmsd(traj, ref=-1) a_md = md.rmsd(m_traj, m_traj, -1) aa_eq(arr0, arr1) aa_eq(arr0, a_md) mask = ":3-18@CA,C" atm = traj.top(mask) arr0 = pt.rmsd(traj, ref=-1, mask=mask) arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1) arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) arr0 = pt.rmsd(fa, ref=-1, mask=mask) arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1) arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) mask = "!@H=" atm = fa.top(mask) arr0 = pt.rmsd(fa, ref=4, mask=mask) a_md = md.rmsd(m_traj, m_traj, 4, atm.indices) # exclude 0-th frame for ref aa_eq(arr0, a_md)
def test_ComparetoMDtraj(self): import mdtraj as md traj = pt.load(filename=tc5b_trajin, top=tc5b_top) m_top = md.load_prmtop(tc5b_top) m_traj = md.load_mdcrd(tc5b_trajin, m_top) m_traj.xyz = m_traj.xyz * 10 # convert `nm` to `Angstrom` unit arr0 = pt.rmsd(traj, ref=0) arr1 = pt.rmsd(traj, ref=0) arr2 = pt.rmsd(traj, ) a_md0 = md.rmsd(m_traj, m_traj, 0) aa_eq(arr0, arr1) aa_eq(arr0, arr2) aa_eq(arr0, a_md0) arr0 = pt.rmsd(traj, ref=-1) arr1 = pt.rmsd(traj, ref=-1) a_md = md.rmsd(m_traj, m_traj, -1) aa_eq(arr0, arr1) aa_eq(arr0, a_md) mask = ":3-18@CA,C" atm = traj.top(mask) arr0 = pt.rmsd(traj, ref=-1, mask=mask) arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1) arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) arr0 = pt.rmsd(fa, ref=-1, mask=mask) arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1) arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) mask = "!@H=" atm = fa.top(mask) arr0 = pt.rmsd(fa, ref=4, mask=mask) a_md = md.rmsd(m_traj, m_traj, 4, atm.indices) # exclude 0-th frame for ref aa_eq(arr0, a_md)
def load_trj(filename, top): try: return md.load(filename, top=top) except (IOError, TypeError): pass try: return md.load_netcdf(filename, top=top) except (IOError, TypeError): pass try: return md.load_mdcrd(filename, top=top) except (IOError, TypeError): print('Trajectory format not recognized. Exiting.') exit()
def singlepoint(topol, trajs): energies = [] for traj in trajs: top_file = topol #traj = sys.argv[2] #collection of mdcrd/coordiantes #load each frame and use it as a coordinate #mdtraj_top = mdtraj.load_prmtop(top_file) mdtraj_dcdfile = mdtraj.load_mdcrd(traj, top=top_file) nframes = len(mdtraj_dcdfile) #create a folder to store the crds if not os.path.exists("rst7_sire_files"): os.makedirs("rst7_sire_files") #print("reading the mdcrd file... %s frames" %(nframes)) for framenumber in range(0, nframes): #create a Sire system rst_file = "rst7_sire_files/%i.rst7" % framenumber mdtraj_dcdfile[framenumber].save_amberrst7( "rst7_sire_files/%i.rst7" % (framenumber)) amber = Amber() molecules, space = amber.readCrdTop(rst_file, top_file) system = createSystem(molecules) # Define forcefields system = setupForcefields(system, space) #print(framenumber , system.energy())#.value()) energies.append(system.energy().value()) #print("removing folder...") cmd = "rm -r rst7_sire_files" os.system(cmd) minimum = min(energies) new_energies = [] for val in energies: print(val) new_val = val - minimum # if new_val <1000 : new_energies.append(new_val) new_energies.append(new_val) #print(len(new_energies)) outputenergy = open('energySinglepoint.dat', 'w') for energy in new_energies: outputenergy.write(str(energy) + '\n') return [energy for energy in new_energies]
return system if __name__ == "__main__": energies=[] for traj in sys.argv[2:]: top_file = sys.argv[1] #topology file #traj = sys.argv[2] #collection of mdcrd/coordiantes #load each frame and use it as a coordinate #mdtraj_top = mdtraj.load_prmtop(top_file) mdtraj_dcdfile = mdtraj.load_mdcrd(traj,top=top_file) nframes= len(mdtraj_dcdfile) #create a folder to store the crds if not os.path.exists("rst7_sire_files"): os.makedirs("rst7_sire_files") print("reading the mdcrd file... %s frames" %(nframes)) for framenumber in range(0, nframes): #create a Sire system rst_file = "rst7_sire_files/%i.rst7" % framenumber mdtraj_dcdfile[framenumber].save_amberrst7("rst7_sire_files/%i.rst7" %(framenumber)) amber = Amber() molecules, space = amber.readCrdTop(rst_file, top_file) system=createSystem(molecules)
Results are plotted as a graph (interactions_frames.png) and saved as a .csv file (interactions_frames.csv) If the script is being run on the complex using ejm_49, please use the --ejm_49 option to calculate cation-pi interactions. This script must be used within a production simulation folder, as it reads the Usage: python atomic_distances.py [--ejm_49] ''' parser = argparse.ArgumentParser() parser.add_argument("--ejm_49", help="add cation-pi interactions for ligand ejm_49", action="store_true") args = parser.parse_args() #Load trajectory print("Loading trajectory...") traj = md.load_mdcrd('production_short.mdcrd', top='solvated_complex.prmtop', stride=1) print("Calculating atomic distances...") #Note: See project paper for reasoning of cutoff distance used for various interactions #Common Van Der Waals' Contacts: #Cutoff of 4.0 angstroms used for VDW contacts #Calculate distance between Val92 atom CG2 (sidechain C) and ligand atom C10 (pyridine) in each frame vdw_pyridine1_val92 = traj.top.select("resid 91 and name CG2") vdw_pyridine1_mol289 = traj.top.select("resid 288 and name C10") vdw_pyridine1_indices = np.array( [vdw_pyridine1_val92[0], vdw_pyridine1_mol289[0]], ndmin=2) vdw_pyridine1 = md.compute_distances(traj, vdw_pyridine1_indices) #Apply cutoff and only save distances within cutoff range