bfee2 2.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bfee2 might be problematic. Click here for more details.

Files changed (65) hide show
  1. BFEE2/__init__.py +0 -0
  2. BFEE2/commonTools/__init__.py +0 -0
  3. BFEE2/commonTools/commonSlots.py +48 -0
  4. BFEE2/commonTools/fileParser.py +327 -0
  5. BFEE2/commonTools/ploter.py +218 -0
  6. BFEE2/doc/Doc.pdf +0 -0
  7. BFEE2/doc/__init__.py +1 -0
  8. BFEE2/gui.py +2136 -0
  9. BFEE2/inputGenerator.py +2857 -0
  10. BFEE2/postTreatment.py +502 -0
  11. BFEE2/templates_gromacs/000.colvars.template +37 -0
  12. BFEE2/templates_gromacs/000.generate_tpr_sh.template +31 -0
  13. BFEE2/templates_gromacs/000.mdp.template +70 -0
  14. BFEE2/templates_gromacs/001.colvars.template +76 -0
  15. BFEE2/templates_gromacs/001.generate_tpr_sh.template +31 -0
  16. BFEE2/templates_gromacs/001.mdp.template +70 -0
  17. BFEE2/templates_gromacs/001.readme.template +1 -0
  18. BFEE2/templates_gromacs/002.colvars.template +101 -0
  19. BFEE2/templates_gromacs/002.generate_tpr_sh.template +31 -0
  20. BFEE2/templates_gromacs/002.mdp.template +70 -0
  21. BFEE2/templates_gromacs/003.colvars.template +125 -0
  22. BFEE2/templates_gromacs/003.generate_tpr_sh.template +36 -0
  23. BFEE2/templates_gromacs/003.mdp.template +70 -0
  24. BFEE2/templates_gromacs/004.colvars.template +148 -0
  25. BFEE2/templates_gromacs/004.generate_tpr_sh.template +37 -0
  26. BFEE2/templates_gromacs/004.mdp.template +70 -0
  27. BFEE2/templates_gromacs/005.colvars.template +170 -0
  28. BFEE2/templates_gromacs/005.generate_tpr_sh.template +38 -0
  29. BFEE2/templates_gromacs/005.mdp.template +70 -0
  30. BFEE2/templates_gromacs/006.colvars.template +192 -0
  31. BFEE2/templates_gromacs/006.generate_tpr_sh.template +39 -0
  32. BFEE2/templates_gromacs/006.mdp.template +70 -0
  33. BFEE2/templates_gromacs/007.colvars.template +210 -0
  34. BFEE2/templates_gromacs/007.generate_tpr_sh.template +40 -0
  35. BFEE2/templates_gromacs/007.mdp.template +69 -0
  36. BFEE2/templates_gromacs/007_eq.colvars.template +169 -0
  37. BFEE2/templates_gromacs/007_eq.generate_tpr_sh.template +64 -0
  38. BFEE2/templates_gromacs/007_min.mdp.template +58 -0
  39. BFEE2/templates_gromacs/008.colvars.template +42 -0
  40. BFEE2/templates_gromacs/008.generate_tpr_sh.template +31 -0
  41. BFEE2/templates_gromacs/008.mdp.template +70 -0
  42. BFEE2/templates_gromacs/008_eq.generate_tpr_sh.template +31 -0
  43. BFEE2/templates_gromacs/BFEEGromacs.py +1244 -0
  44. BFEE2/templates_gromacs/__init__.py +0 -0
  45. BFEE2/templates_gromacs/find_min_max.awk +27 -0
  46. BFEE2/templates_namd/__init__.py +0 -0
  47. BFEE2/templates_namd/configTemplate.py +1094 -0
  48. BFEE2/templates_namd/fep.tcl +299 -0
  49. BFEE2/templates_namd/scriptTemplate.py +149 -0
  50. BFEE2/templates_namd/solvate.tcl +9 -0
  51. BFEE2/templates_namd/solvate_mem.tcl +9 -0
  52. BFEE2/templates_namd/updateCenters.py +311 -0
  53. BFEE2/templates_readme/Readme_Gromacs_Geometrical.txt +25 -0
  54. BFEE2/templates_readme/Readme_NAMD_Alchemical.txt +20 -0
  55. BFEE2/templates_readme/Readme_NAMD_Geometrical.txt +34 -0
  56. BFEE2/templates_readme/__init__.py +1 -0
  57. BFEE2/third_party/__init__.py +0 -0
  58. BFEE2/third_party/py_bar.py +335 -0
  59. BFEE2/version.py +2 -0
  60. bfee2-2.5.0.data/scripts/BFEE2Gui.py +18 -0
  61. bfee2-2.5.0.dist-info/LICENSE +677 -0
  62. bfee2-2.5.0.dist-info/METADATA +76 -0
  63. bfee2-2.5.0.dist-info/RECORD +65 -0
  64. bfee2-2.5.0.dist-info/WHEEL +5 -0
  65. bfee2-2.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,311 @@
1
+ # Read eq.histogramX.dat and update Centers in *.in files
2
+ # This step is optional but may improve the convergence
3
+
4
+ import os, sys, re
5
+ import numpy as np
6
+
7
+ def isGeometric():
8
+ """Check the route of the simulation, True for geometric,
9
+ False for alchemical.
10
+
11
+ Returns:
12
+ bool: the route of the free-energy calculation. True for geometric,
13
+ False for alchemical
14
+ """
15
+
16
+ if os.path.exists('../fep.tcl'):
17
+ return False
18
+ else:
19
+ return True
20
+
21
+
22
+ def parseDat(filename):
23
+ """Parse a dat (histogram) file and return the most probable CV value
24
+
25
+ Args:
26
+ filename (str): the dat file to be parsed with
27
+
28
+ Returns:
29
+ float: the most probable CV value
30
+ """
31
+
32
+ data = np.loadtxt(filename)
33
+ CVs = data[:,0]
34
+ counts = data[:,1]
35
+
36
+ maxCV = -1
37
+ maxCount = -1
38
+ for i, j in zip(CVs, counts):
39
+ if j > maxCount:
40
+ maxCV = i
41
+ maxCount = j
42
+ return maxCV
43
+
44
+ def findOptimalCVs():
45
+ """ read *.dat files generated through equilibration
46
+ and find out the most probable values of CVs
47
+
48
+ Returns:
49
+ list[Float]: the most probable values of RMSD, eulerTheta, eulerPhi, eulerPsi, polarTheta, polarPhi, r
50
+ """
51
+
52
+ optimalCVs = []
53
+ files = [
54
+ 'output/eq.histogram1.dat',
55
+ 'output/eq.histogram2.dat',
56
+ 'output/eq.histogram3.dat',
57
+ 'output/eq.histogram4.dat',
58
+ 'output/eq.histogram5.dat',
59
+ 'output/eq.histogram6.dat',
60
+ 'output/eq.histogram7.dat'
61
+ ]
62
+
63
+ for file in files:
64
+ optimalCVs.append(parseDat(file))
65
+
66
+ return optimalCVs
67
+
68
+ def readCenters(filename, CVs):
69
+ """ find the value of centers of provided CVs in a *.in file
70
+
71
+ Args:
72
+ filename (str): a Colvars config file
73
+ CVs (List[str]): a list, showing the CVs whose centers are to be get
74
+
75
+ Returns:
76
+ List[float]: centers of the provided CVs
77
+ """
78
+
79
+ # whether parsing a harmonic block
80
+ # either None or the index of the corresponding CV
81
+ inBlock = None
82
+
83
+ # the CV values
84
+ CVValues = [0 for i in range(len(CVs))]
85
+
86
+ with open(filename, 'r') as colvarsFile:
87
+ for line in colvarsFile.readlines():
88
+ splitedLine = line.strip().split()
89
+
90
+ if inBlock is not None:
91
+ if line.strip().lower().startswith('centers'):
92
+ if inBlock != -1:
93
+ CVValues[inBlock] = float(splitedLine[1])
94
+
95
+ if splitedLine[0] == '}':
96
+ inBlock = None
97
+
98
+ if line.strip().lower().startswith('harmonic'):
99
+ inBlock = -1
100
+
101
+ if line.strip().lower().startswith('colvars'):
102
+ for index, CV in enumerate(CVs):
103
+ if splitedLine[1].lower() == CV.lower():
104
+ inBlock = index
105
+
106
+ return CVValues
107
+
108
+ def changeCenters(filename, CVs, newCenters):
109
+ """ change Centers of harmonic restraints in a *.in file
110
+
111
+ Args:
112
+ filename (str): a Colvars config file
113
+ CVs (List[str]): a list, showing the Centers of which harmonic blocks are to be replaced
114
+ newCenters (List[float]): a list, containing the new values of Centers
115
+ """
116
+
117
+ # whether parsing a harmonic block
118
+ # either None or the index of the corresponding CV
119
+ inBlock = None
120
+ with open(filename, 'r') as oldColvarsFile:
121
+ # Python cannot modify text file in place
122
+ with open(filename + '.tmp', 'w') as newColvarsFile:
123
+ for line in oldColvarsFile.readlines():
124
+ splitedLine = line.strip().split()
125
+
126
+ if inBlock is None:
127
+ newColvarsFile.write(line)
128
+ else:
129
+ if not line.strip().lower().startswith('centers'):
130
+ newColvarsFile.write(line)
131
+ else:
132
+ # 'colvars' not in CVs
133
+ if inBlock == -1:
134
+ newColvarsFile.write(line)
135
+ else:
136
+ newColvarsFile.write(f' Centers {newCenters[inBlock]}\n')
137
+
138
+ if len(splitedLine) > 0:
139
+ if splitedLine[0] == '}':
140
+ inBlock = None
141
+
142
+ if line.strip().lower().startswith('harmonic'):
143
+ inBlock = -1
144
+
145
+ if line.strip().lower().startswith('colvars'):
146
+ for index, CV in enumerate(CVs):
147
+ if splitedLine[1].lower() == CV.lower():
148
+ inBlock = index
149
+
150
+ os.remove(filename)
151
+ os.rename(filename + '.tmp', filename)
152
+
153
+ def changeABFRange(filename, CVs, newCenters, originalCenters):
154
+ """ change lowerboundary, upperboundary, lowerWalls, upperWalls of ABF in a *.in file
155
+
156
+ Args:
157
+ filename (str): a Colvars config file
158
+ CVs (List[str]): a list, showing the corresponding options of which CV blocks are to be replaced
159
+ newCenters (List[float]): a list, containing the new values of Centers of these CVs
160
+ originalCenters (List[float]): a list, containing the original values of Centers of these CVs
161
+ """
162
+
163
+ # whether parsing a harmonic block
164
+ # either None or the index of the corresponding CV
165
+ inBlock = None
166
+ with open(filename, 'r') as oldColvarsFile:
167
+ # Python cannot modify text file in place
168
+ with open(filename + '.tmp', 'w') as newColvarsFile:
169
+ for line in oldColvarsFile.readlines():
170
+ splitedLine = line.strip().split()
171
+
172
+ if inBlock is None:
173
+ newColvarsFile.write(line)
174
+ else:
175
+ if (not line.strip().lower().startswith('lowerboundary')) and \
176
+ (not line.strip().lower().startswith('upperboundary')) and \
177
+ (not line.strip().lower().startswith('lowerwalls')) and \
178
+ (not line.strip().lower().startswith('upperwalls')):
179
+ newColvarsFile.write(line)
180
+ else:
181
+ # 'name' not in CVs
182
+ if inBlock == -1:
183
+ newColvarsFile.write(line)
184
+ else:
185
+ if line.strip().lower().startswith('lowerboundary'):
186
+ newColvarsFile.write(
187
+ f' Lowerboundary {float(splitedLine[1]) + newCenters[inBlock] - originalCenters[inBlock]}\n'
188
+ )
189
+ elif line.strip().lower().startswith('upperboundary'):
190
+ newColvarsFile.write(
191
+ f' Upperboundary {float(splitedLine[1]) + newCenters[inBlock] - originalCenters[inBlock]}\n'
192
+ )
193
+ elif line.strip().lower().startswith('lowerwalls'):
194
+ newColvarsFile.write(
195
+ f' LowerWalls {float(splitedLine[1]) + newCenters[inBlock] - originalCenters[inBlock]}\n'
196
+ )
197
+ elif line.strip().lower().startswith('upperwalls'):
198
+ newColvarsFile.write(
199
+ f' UpperWalls {float(splitedLine[1]) + newCenters[inBlock] - originalCenters[inBlock]}\n'
200
+ )
201
+ else:
202
+ print("Selected CV(s) not for free-energy calculation!")
203
+
204
+ if len(splitedLine) > 0:
205
+ if splitedLine[0] == '}':
206
+ inBlock = None
207
+
208
+ if len(splitedLine) > 0:
209
+ if splitedLine[0].lower() == 'colvar' or line.strip().lower().startswith('harmonicwalls'):
210
+ inBlock = -1
211
+
212
+ if line.strip().lower().startswith('name') or splitedLine[0].lower() == 'colvars':
213
+ for index, CV in enumerate(CVs):
214
+ if splitedLine[1].lower() == CV.lower():
215
+ inBlock = index
216
+
217
+ os.remove(filename)
218
+ os.rename(filename + '.tmp', filename)
219
+
220
+ def updateAlchemicalFiles():
221
+ """Update the Centers of *.in files based on equilibration
222
+ """
223
+
224
+ files = [
225
+ './colvars2.in',
226
+ '../001_MoleculeBound/colvars.in',
227
+ '../002_RestraintBound/colvars_forward.in',
228
+ '../002_RestraintBound/colvars_backward.in'
229
+ ]
230
+
231
+ for file in files:
232
+ if not os.path.exists(file):
233
+ print(f'File {file} does not exist!')
234
+ continue
235
+ changeCenters(
236
+ file,
237
+ [
238
+ 'eulerTheta', 'eulerPhi', 'eulerPsi', 'polarTheta', 'polarPhi', 'r'
239
+ ],
240
+ findOptimalCVs()[1:]
241
+ )
242
+ print(f'File {file} updated!')
243
+
244
+ # if re-eqilibrated
245
+ if os.path.exists('./000.1_eq2_re-eq.conf'):
246
+ confFiles = [
247
+ '../001_MoleculeBound/001.1_fep_backward.conf',
248
+ '../001_MoleculeBound/001_fep_doubleWide.conf',
249
+ '../002_RestraintBound/002.1_ti_backward.conf',
250
+ ]
251
+ for confFile in confFiles:
252
+ if not os.path.exists(confFile):
253
+ print(f'File {confFile} does not exist!')
254
+ continue
255
+ with open(confFile,'r') as readFile:
256
+ data=readFile.read()
257
+ data = re.sub('../000_eq/output/eq.coor', '../000_eq/output/eq2.coor', data)
258
+ data = re.sub('../000_eq/output/eq.vel', '../000_eq/output/eq2.vel', data)
259
+ data = re.sub('../000_eq/output/eq.xsc', '../000_eq/output/eq2.xsc', data)
260
+ with open(confFile,'w') as writeFile:
261
+ writeFile.write(data)
262
+ print(f'File {confFile} updated!')
263
+
264
+ def updateGeometricFiles():
265
+ """Update the Centers of *.in files based on equilibration
266
+ """
267
+
268
+ CVNames = ['eulerTheta', 'eulerPhi', 'eulerPsi', 'polarTheta', 'polarPhi']
269
+ optimalCVValues = findOptimalCVs()[1:6]
270
+ originalCVValues = readCenters('../007_r/colvars_eq.in', CVNames)
271
+
272
+ # in geometrical route, there may be many windows
273
+ folders = [
274
+ '../002_EulerTheta',
275
+ '../003_EulerPhi',
276
+ '../004_EulerPsi',
277
+ '../005_PolarTheta',
278
+ '../006_PolarPhi',
279
+ '../007_r'
280
+ ]
281
+
282
+ for fIndex, folder in enumerate(folders):
283
+ # *.in in folder
284
+ files = []
285
+ for file in os.listdir(folder):
286
+ if file.endswith('.in') or file.endswith('.in.amd'):
287
+ files.append(os.path.join(folder, file))
288
+
289
+ for inFile in files:
290
+ changeCenters(
291
+ inFile,
292
+ CVNames[:fIndex],
293
+ optimalCVValues[:fIndex]
294
+ )
295
+
296
+ changeABFRange(
297
+ inFile,
298
+ CVNames[:fIndex+1],
299
+ optimalCVValues[:fIndex+1],
300
+ originalCVValues[:fIndex+1]
301
+ )
302
+ print(f'File {inFile} updated!')
303
+
304
+ if __name__ == '__main__':
305
+
306
+ if isGeometric():
307
+ updateGeometricFiles()
308
+ print('All the *.in files updated for the Geometrical route!')
309
+ else:
310
+ updateAlchemicalFiles()
311
+ print('All the *.in files updated for the Alchemical route!')
@@ -0,0 +1,25 @@
1
+ To calculate the binding free energy:
2
+
3
+ 1.1. run 000_eq/000_generate_tpr.sh
4
+ 1.2. run 000_eq/000_eq.tpr
5
+ 2.1. run 001_RMSD_bound/001_generate_tpr.sh
6
+ 2.2. run 001_RMSD_bound/001_RMSD_bound.tpr
7
+ 3.1. run 002_euler_theta/002_generate_tpr.sh
8
+ 3.2. run 002_euler_theta/002_euler_theta.tpr
9
+ 4.1. run 003_euler_phi/003_generate_tpr.sh
10
+ 4.2. run 003_euler_phi/003_euler_phi.tpr
11
+ 5.1. run 004_euler_psi/004_generate_tpr.sh
12
+ 5.2. run 004_euler_psi/004_euler_psi.tpr
13
+ 6.1. run 005_polar_theta/005_generate_tpr.sh
14
+ 6.2. run 005_polar_theta/005_polar_theta.tpr
15
+ 7.1. run 006_polar_phi/006_generate_tpr.sh
16
+ 7.2. run 006_polar_phi/006_polar_phi.tpr
17
+ 8.1. run 007_r/007.1_generate_eq_tpr.sh
18
+ 8.2. run 007_r/007_r.eq.tpr
19
+ 8.3. run 007_r/007.2_generate_tpr.sh
20
+ 8.4 run 007_r/007_r.tpr
21
+ 9.1. run 008_RMSD_unbound/008.1_generate_eq_tpr.sh
22
+ 9.2. run 008_RMSD_unbound/008_RMSD_unbound.eq.tpr
23
+ 9.3. run 008_RMSD_unbound/008.2_generate_tpr.sh
24
+ 9.4. run 008_RMSD_unbound/008_RMSD_unbound.tpr
25
+ 10. do post-treatment using BFEE
@@ -0,0 +1,20 @@
1
+ To calculate the binding free energy:
2
+
3
+ 1.1. run 000_eq/000.1_eq.conf
4
+ 1.2. (optionally) run 000_eq/000.3_updateCenters.py
5
+ 2.1. run 001_MoleculeBound/001.1_fep_backward.conf
6
+ 2.2. run 001_MoleculeBound/001.2_fep_forward.conf
7
+ 3.1. run 002_RestraintBound/002.1_ti_backward.conf
8
+ 3.2. run 002_RestraintBound/002.2_ti_forward.conf
9
+ 4.1. CHARMM user:
10
+ (if you didn't link BFEE with VMD before generating inputs)
11
+ run 002.3_removeProtein.tcl using VMD
12
+ Amber user:
13
+ run 002.3_removeProtein.cpptraj using cpptraj
14
+ 4.2 run 000_eq/000.2_eq_ligandOnly.conf
15
+ 4.3. run 003_MoleculeUnbound/003.1_fep_backward.conf
16
+ 4.4. run 003_MoleculeUnbound/003.2_fep_forward.conf
17
+ 5.1. run 004_RestraintUnbound/004.1_ti_backward.conf
18
+ 5.2. run 004_RestraintUnbound/004.2_ti_forward.conf
19
+ (steps 2-5 can be done in parallel)
20
+ 6. do post-treatment using BFEE
@@ -0,0 +1,34 @@
1
+ To calculate the binding free energy:
2
+
3
+ 1.1 run 000_eq/000.1_eq.conf
4
+ 1.2. (optionally) run 000_eq/000.2_updateCenters.py
5
+ (If this is done, then there is usually no need to change restraining centers
6
+ after steps 3.x.)
7
+ 2. run 001_RMSDBound/001_abf_1.conf
8
+ 3.1. run 002_EulerTheta/002_abf_1.conf
9
+ 3.2. change restraining center of "eulerTheta" in
10
+ 003_EulerPhi/colvars_1.in to
11
+ the CV value corresponding to dG=0 in
12
+ 002_EulerTheta/output/abf_1.czar.pmf,
13
+ 3.3. run 003_EulerPhi/003_abf_1.conf
14
+ 3.4. similarly, change "eulerTheta" and "eulerPhi" in
15
+ 004_EulerPsi/colvars_1.in
16
+ 3.5. run 004_EulerPsi/004_abf_1.conf
17
+ 3.6. change 005_PolarTheta/colvars_1.in correspondingly
18
+ 3.7. run 005_PolarTheta/005_abf_1.conf
19
+ 3.8. change 006_PolarPhi/colvars_1.in correspondingly
20
+ 3.9. run 006_PolarPhi/006_abf_1.conf
21
+ 3.10. change 007_r/colvars_eq.in and 007_r/colvars_1.in correspondingly
22
+ 3.11. (if you didn't link BFEE with VMD before generating inputs)
23
+ run 007_r/007.0_solvate.tcl using VMD
24
+ 3.12. run 007_r/007.1_eq.conf
25
+ 3.13. run 007_r/007.2_abf_1.conf
26
+ 4.1. CHARMM user:
27
+ (if you didn't link BFEE with VMD before generating inputs)
28
+ run 008_RMSDUnbound/008.0_removeProtein.tcl using VMD
29
+ Amber user:
30
+ run 008.0_removeProtein.cpptraj using cpptraj
31
+ 4.2. run 008_RMSDUnbound/008.1_eq.conf
32
+ 4.3. run 008_RMSDUnbound/008.2_abf_1.conf
33
+ (steps 2-4 can be done in parallel)
34
+ 5. do post-treatment using BFEE
@@ -0,0 +1 @@
1
+
File without changes