-
Notifications
You must be signed in to change notification settings - Fork 7
/
mda_rmsf_fix.py
67 lines (48 loc) · 1.9 KB
/
mda_rmsf_fix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! Calculate Root Mean Square Fluctuation (RMSF).
#! _author : Ropón-Palacios G.
#! _date : Feb 27, 2022.
#! _e-mail : [email protected]
#! Requerid MDAnalysis v 2.0.0 or later
import optparse
import subprocess
import MDAnalysis as mda
import numpy as np
import pandas as pd
from MDAnalysis.analysis import rms, align
disclaimer="""<MDAnalysis RMSD Tool>"""
parser = optparse.OptionParser(description=disclaimer)
#! INPUTS options
parser.add_option("--coord", help="coord [GRO, PSF, PARM7]", type=str)
parser.add_option("--traj", help="traj [XTC, DCD, NETCDF or DRT]", type=str)
parser.add_option("--sel", help="syntaxis-based in MDAnalysis [\"protein and name CA\"]", type=str,action='store')
#! OUTPUT options
parser.add_option("--ofile", help="type output name [rgyr_prot_nameCA.dat]", type=str)
options, args = parser.parse_args()
#! Load trajectory
universe = mda.Universe(options.coord, options.traj)
#! Define routine
def rmsf(traj, seltext1, ofile):
u1 = traj
#! Align Traj
average = align.AverageStructure(u1, u1, select=options.sel, ref_frame=0).run()
ref = average.results.universe
aligner = align.AlignTraj(u1, ref, select=options.sel).run() # in_memory=True).run()
bb = u1.select_atoms(seltext1)
r = rms.RMSF(bb).run()
resids = bb.resids
rmsf = r.rmsf
#larray = np.array((resids,rmsf))
df = pd.DataFrame({"resid":resids, "rmsf":rmsf})
df.to_csv(ofile, index=False, sep="\t")
#! rmsf to beta PDB
u1.add_TopologyAttr('tempfactors') # add empty attribute for all atoms
protein = u1.select_atoms('protein') # select protein atoms
for residue, r_value in zip(protein.residues, r.rmsf):
residue.atoms.tempfactors = r_value
protein.write("rmsf_to_beta.pdb")
print ("file RMSF write to: ", ofile)
#! Call routine
selAtoms = options.sel
ofile = options.ofile
rmsf(universe, selAtoms, ofile)
print ("RMSF calculations finished!!!")