-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfep.tcl
208 lines (175 loc) · 5.23 KB
/
fep.tcl
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##############################################################
# FEP SCRIPT
# Jerome Henin <[email protected]>
#
# Changes:
# 2010-04-24: added runFEPmin
# 2009-11-17: changed for NAMD 2.7 keywords
# 2008-06-25: added TI routines
# 2007-11-01: fixed runFEP to handle backwards transformations
# (i.e. dLambda < 0)
##############################################################
##############################################################
# Example NAMD input:
#
# source fep.tcl
#
# alch on
# alchFile system.fep
# alchCol B
# alchOutFreq 10
# alchOutFile system.fepout
# alchEquilSteps 500
#
# set nSteps 5000
# set init {0 0.05 0.1}
# set end {0.9 0.95 1.0}
#
# runFEPlist $init $nSteps
# runFEP 0.1 0.9 0.1 $nSteps
# runFEPlist $end $nSteps
##############################################################
##############################################################
# proc runFEPlist { lambdaList nSteps }
#
# Run n FEP windows joining (n + 1) lambda-points
##############################################################
proc runFEPlist { lambdaList nSteps } {
# Keep track of window number
global win
if {![info exists win]} {
set win 1
}
set l1 [lindex $lambdaList 0]
foreach l2 [lrange $lambdaList 1 end] {
print [format "Running FEP window %3s: Lambda1 %-6s Lambda2 %-6s \[dLambda %-6s\]"\
$win $l1 $l2 [expr $l2 - $l1]]
firsttimestep 0
alchLambda $l1
alchLambda2 $l2
run $nSteps
set l1 $l2
incr win
}
}
##############################################################
# proc runFEP { start stop dLambda nSteps }
#
# FEP windows of width dLambda between values start and stop
##############################################################
proc runFEP { start stop dLambda nSteps } {
set epsilon 1e-15
if { ($stop < $start) && ($dLambda > 0) } {
set dLambda [expr {-$dLambda}]
}
if { $start == $stop } {
set ll [list $start $start]
} else {
set ll [list $start]
set l2 [increment $start $dLambda]
if { $dLambda > 0} {
# A small workaround for numerical rounding errors
while { [expr {$l2 <= ($stop + $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
} else {
while { [expr {$l2 >= ($stop - $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
}
}
runFEPlist $ll $nSteps
}
##############################################################
##############################################################
proc runFEPmin { start stop dLambda nSteps nMinSteps temp} {
set epsilon 1e-15
if { ($stop < $start) && ($dLambda > 0) } {
set dLambda [expr {-$dLambda}]
}
if { $start == $stop } {
set ll [list $start $start]
} else {
set ll [list $start]
set l2 [increment $start $dLambda]
if { $dLambda > 0} {
# A small workaround for numerical rounding errors
while { [expr {$l2 <= ($stop + $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
} else {
while { [expr {$l2 >= ($stop - $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
}
}
if { $nMinSteps > 0 } {
alchLambda $start
alchLambda2 $start
minimize $nMinSteps
reinitvels $temp
}
runFEPlist $ll $nSteps
}
##############################################################
##############################################################
proc runTIlist { lambdaList nSteps } {
# Keep track of window number
global win
if {![info exists win]} {
set win 1
}
foreach l $lambdaList {
print [format "Running TI window %3s: Lambda %-6s " $win $l ]
firsttimestep 0
alchLambda $l
run $nSteps
incr win
}
}
##############################################################
##############################################################
proc runTI { start stop dLambda nSteps } {
set epsilon 1e-15
if { ($stop < $start) && ($dLambda > 0) } {
set dLambda [expr {-$dLambda}]
}
if { $start == $stop } {
set ll [list $start $start]
} else {
set ll [list $start]
set l2 [increment $start $dLambda]
if { $dLambda > 0} {
# A small workaround for numerical rounding errors
while { [expr {$l2 <= ($stop + $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
} else {
while { [expr {$l2 >= ($stop - $epsilon) } ] } {
lappend ll $l2
set l2 [increment $l2 $dLambda]
}
}
}
runTIlist $ll $nSteps
}
##############################################################
# Increment lambda and try to correct truncation errors around
# 0 and 1
##############################################################
proc increment { lambda dLambda } {
set epsilon 1e-15
set new [expr { $lambda + $dLambda }]
if { [expr $new > - $epsilon && $new < $epsilon] } {
return 0.0
}
if { [expr ($new - 1) > - $epsilon && ($new - 1) < $epsilon] } {
return 1.0
}
return $new
}