-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_free_energy.py
76 lines (67 loc) · 2.51 KB
/
calc_free_energy.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
68
69
70
71
72
73
74
75
#!/usr/bin/python
import pylab
from msmbuilder import io
import optparse
import numpy
def main(modeldir, gensfile, rcut=None):
mapdata=dict()
ass=io.loadh('%s/Assignments.Fixed.h5' % modeldir)
data=dict()
data['rmsd']=numpy.loadtxt('%s.rmsd.dat' % gensfile.split('.lh5')[0])
com=numpy.loadtxt('%s.vmd_com.dat' % gensfile.split('.lh5')[0], usecols=(1,))
data['com']=com[1:]
pops=numpy.loadtxt('%s/Populations.dat' % modeldir)
map=numpy.loadtxt('%s/Mapping.dat' % modeldir)
mapdata['rmsd']=[]
mapdata['com']=[]
for x in range(0, len(data['rmsd'])):
if map[x]!=-1:
mapdata['com'].append(data['com'][x])
mapdata['rmsd'].append(data['rmsd'][x])
#RMSD cutoff
cutoffs=numpy.arange(1,30,0.5)
bound_pops=[]
for type in mapdata.keys():
pylab.figure()
ohandle=open('%s/%s_msm_frees.dat' % (modeldir, type), 'w')
data=[]
for cutoff in cutoffs:
bound_pops=[]
for (state, x) in enumerate(mapdata['rmsd']):
if x < cutoff:
bound_pops.append(pops[state])
### calculate binding free energy from populations
if len(bound_pops)==0:
dG=100
else:
bound=numpy.sum(bound_pops)
unbound=1-bound
dG=-0.6*numpy.log(bound/unbound)
#dG=-0.6*numpy.log(bound/(unbound**2))
### calculate standard state correction, in ansgtroms here
boxvolume=244.80*(10**3)
v0=1600
corr=-0.6*numpy.log(boxvolume/v0)
dG_corr=dG+corr
if cutoff==float(rcut):
print cutoff, dG_corr
data.append(dG_corr)
ohandle.write('%s\t%s\n' % (cutoff, dG_corr))
pylab.plot(cutoffs, data, label=type)
pylab.legend()
pylab.ylim(-8, (-1)*corr)
pylab.show()
def parse_commandline():
parser = optparse.OptionParser()
parser.add_option('-d', '--modeldir', dest='modeldir',
help='msm directory')
parser.add_option('-g', '--gensfile', dest='gensfile',
help='gens files')
parser.add_option('-c', '--cutoff', dest='cutoff',
help='cutoff')
(options, args) = parser.parse_args()
return (options, args)
#run the function main if namespace is main
if __name__ == "__main__":
(options, args) = parse_commandline()
main(modeldir=options.modeldir, gensfile=options.gensfile, rcut=options.cutoff)