-
Notifications
You must be signed in to change notification settings - Fork 4
/
bedamflat_async_re.py
96 lines (78 loc) · 2.91 KB
/
bedamflat_async_re.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sys
import time
import math
import random
import logging
from async_re import async_re
from bedamtempt_async_re import bedamtempt_async_re_job
class bedamflat_async_re_job(bedamtempt_async_re_job):
def _setLogger(self):
self.logger = logging.getLogger("async_re.bedamflat_async_re")
def _checkInput(self):
bedamtempt_async_re_job._checkInput(self)
def _extractLast_lambda_BindingEnergy_TotalEnergy(self,repl,cycle):
"""
Extracts binding energy from Impact output
"""
output_file = "r%s/%s_%d.out" % (repl,self.basename,cycle)
datai = self._getImpactData(output_file)
nf = len(datai[0])
nr = len(datai)
# [nr-1]: last record
# [nf-2]: lambda (next to last item)
# [nf-1]: binding energy (last item)
# [2]: total energy item (0 is step number and 1 is temperature)
#
# (lambda, binding energy,flattening energy, total energy)
return (datai[nr-1][nf-4],datai[nr-1][nf-3],datai[nr-1][nf-1],datai[nr-1][2])
def _getPot(self,repl,cycle):
(lmb, u, eflat, etot) = self._extractLast_lambda_BindingEnergy_TotalEnergy(repl,cycle)
# removes lambda*u from etot to get e0. Note that this is the lambda from the
# output file not the current lambda.
if float(lmb) >= 0.5 :
lmb_d = 2.0*(1-float(lmb))
else:
lmb_d = 2.0*float(lmb)
e0 = float(etot) - float(lmb)*float(u) + lmb_d*eflat;
return (e0,float(u),lmb_d,eflat)
def _getPar(self,repl):
sid = self.status[repl]['stateid_current']
lmb = float(self.stateparams[sid]['lambda'])
tempt = float(self.stateparams[sid]['temperature'])
kb = 0.0019872041
beta = 1./(kb*tempt)
if lmb >= 0.5 :
lmb_d = 2.0*(1-lmb)
else :
lmb_d = 2.0*lmb
return (beta,lmb,lmb_d)
def _reduced_energy(self,par,pot):
# par: list of parameters
# pot: list of potentials
# This is for temperature/binding potential beta*(U0+lambda*u)
beta = par[0]
lmb = par[1]
lmb_d = par[2]
e0 = pot[0]
u = pot[1]
eflat = pot[3]
return beta*(e0 + lmb*u -lmb_d*eflat)
if __name__ == '__main__':
# Parse arguments:
usage = "%prog <ConfigFile>"
if len(sys.argv) != 2:
print "Please specify ONE input file"
sys.exit(1)
commandFile = sys.argv[1]
print ""
print "===================================="
print "BEDAM Asynchronous Replica Exchange "
print "===================================="
print ""
print "Started at: " + str(time.asctime())
print "Input file:", commandFile
print ""
sys.stdout.flush()
rx = bedamflat_async_re_job(commandFile, options=None)
rx.setupJob()
rx.scheduleJobs()