def calculate_rmsf(trajfiles, topfile, plot=True, ref=0, mask='@CA', name='default'): ''' This function returns a numpy.ndarray object that contains rmsf information of the atoms in the mask. Arguments: - trajfiles: trajectory file or list of trajecrory files(see formats in the bottom part). - topfile: topology file used to read the trajectories(see formats in the bottom part). - ref: frame used as a reference while the RMSF is calculated(integer). - mask: string that indicates with cpptraj format the mask for the calculation (default: "@Ca"). - plot: if True, plots a RMSF plot(default: True). - name: Name of the dataset provided. Will apear in the title in the plot. Returns: numpy.ndarray Formats that accept: Amber Trajectory .crd Amber NetCDF .nc Amber Restart .rst7 Amber NetCDF .ncrst Charmm DCD .dcd PDB .pdb Mol2 .mol2 Scripps .binpos Gromacs .trr SQM Input .sqm ''' if name == 'default': if type(trajfiles) == list: name = trajfiles[0].split('/')[-1] else: name = trajfiles.split('/')[-1] MD = pt.iterload(trajfiles, topfile).superpose(trajfiles, ref=ref) rmsf = pt.rmsf(MD, mask) if plot: mpl.rcParams['font.size'] = 15 plt.figure(figsize=(12, 5)) plt.plot(rmsf.T[1]) plt.xlabel('{} number'.format(mask), fontsize=20) plt.ylabel('RMSF ($\AA$)', fontsize=20) plt.xlim((0, len(rmsf))) plt.title('{} RMSF'.format(name), fontsize=25) return rmsf.T[1]
def test_RMSF_with_options(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch( traj, ''' atomicfluct @CA byres out fluct.agr''') state.run() data = pt.rmsf(traj, '@CA', options='byres') aa_eq(data, state.data[-1].values)
def get_rms(traj_path): traj = load_traj(traj_path) rmsd = pt.rmsd(traj, ref=0, mask='@CA,C,N') df_rmsd = pd.DataFrame(rmsd, columns=['RMSD']) rmsf = pt.rmsf(traj) df_rmsf = pd.DataFrame(rmsf, columns=['ATOM', 'RMSF']) return df_rmsd, df_rmsf
def test_RMSF(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch(traj, ''' rms first average crdset MyAvg run rms ref MyAvg atomicfluct out fluct.agr''') state.run() t0 = traj[:] pt.superpose(t0, ref=0) avg = pt.mean_structure(t0) pt.superpose(t0, ref=avg) data = pt.rmsf(t0) aa_eq(data, state.data[-1].values)
def test_RMSF(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") state = pt.load_batch(traj, ''' rms first average crdset MyAvg run rms ref MyAvg atomicfluct out fluct.agr''') state.run() t0 = traj[:] pt.superpose(t0, ref=0) avg = pt.mean_structure(t0) pt.superpose(t0, ref=avg) data = pt.rmsf(t0) aa_eq(data, state.data[-1].values)
def main(traj, pdb): ''' 计算RMSD/RMSF Parameters ---------- traj: MD轨迹 Pytraj对象 pdb: PDB ID字符串 ''' print('\nStart RMSD/RMSF Analysis...') data_rmsd_first = pt.rmsd(traj, ref=0, mask="@CA") # 计算αC原子RMSD Ref=0以第一帧为参考 command = "awk '$4 ~ /MOL/ {print $5}' ./" + pdb + 'comsolvate.pdb' # 提取位于残基后的配体分子序号 temp = os.popen(command) mol_resnum = str(temp.readlines()[-1]).strip() res_mask = ':1-' + mol_resnum + '@CA' data_rmsf = pt.rmsf(traj, mask=res_mask, options='byres') # 计算RMSF 所有非水分子 # 保存数据 print('RMSD Data:') print(data_rmsd_first) with open('./pynalysis/rmsd_rmsf/rmsd.dat', 'w') as rmsdfile: for rmsd in data_rmsd_first[:]: rmsdfile.write(str(rmsd) + '\n') rmsdfile.close() print('rmsd.dat saved.', end='\n') print('RMSF Data:') print(data_rmsf) with open('./pynalysis/rmsd_rmsf/rmsf.dat', 'w') as rmsffile: for rmsfdata in data_rmsf[:]: rmsffile.write(str(rmsfdata[1]) + '\n') rmsffile.close() print('rmsf.dat saved.', end='\n') print('\n\nRMSD/RMSF Analysis Complete.') print(''.center(80, '*'))