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,1094 @@
1
+ # generate NAMD/Gromacs/Colvars config files
2
+
3
+ import numpy as np
4
+
5
+ class configTemplate:
6
+ ''' generate NAMD/Gromacs/Colvars config files
7
+ In the Colvars config file, ndx and xyz files are used to indicate the group of atoms
8
+ The non-hydrogen atoms of protein are labeled as 'protein' in complex.ndx
9
+ The non-hydrogen atoms of ligand are labeled as 'ligand' in complex.ndx
10
+ The non-hydrogen atoms of user-defined reference are labeled as 'reference' in complex.ndx '''
11
+
12
+ def __init__(self):
13
+ pass
14
+
15
+ def namdConfigTemplate(
16
+ self,
17
+ forceFieldType,
18
+ forceFieldFiles,
19
+ topFile,
20
+ coorFile,
21
+ NAMDRestartCoor,
22
+ NAMDRestartVel,
23
+ NAMDRestartXsc,
24
+ PBCCondition,
25
+ outputPrefix,
26
+ temperature,
27
+ numSteps,
28
+ cvFile = '',
29
+ cvDefinitionFile = '',
30
+ CVRestartFile = '',
31
+ fepFile = '',
32
+ fepWindowNum = 20,
33
+ fepForward = True,
34
+ fepDoubleWide = False,
35
+ fepMinBeforeSample = False,
36
+ membraneProtein = False,
37
+ OPLSMixingRule = False,
38
+ GaWTM = False,
39
+ CUDASOAIntegrator = False,
40
+ timestep = 2.0
41
+ ):
42
+ """the namd config file template
43
+
44
+ Args:
45
+ forceFieldType (str): 'charmm' or 'amber'
46
+ forceFieldFiles (list of str): name of charmm force field files
47
+ topFile (str): name of the topology file (psf, parm)
48
+ coorFile (str): name of the coordinate file (pdb, rst)
49
+ NAMDRestartCoor (str): name of namd binary restart coor file (if restart from a previous simulation)
50
+ NAMDRestartVel (str): name of namd binary restart vel file
51
+ NAMDRestartXsc (str): name of namd restart xsc file
52
+ PBCCondition (np.array, 2*3): PBC vector, ((lengthX, lengthY, lengthZ),(centerX, centerY, centerZ))
53
+ outputPrefix (str): prefix of output file
54
+ temperature (float): temperature of the simulation
55
+ numSteps (int): number of steps of the simulation
56
+ cvFile (str): name of Colvars file. Defaults to ''.
57
+ cvDefinitionFile (str, optional): name of a TCL file defining new CVs. Defaults to ''.
58
+ CVRestartFile (str, optional): name of Colvars restart file. Defaults to ''.
59
+ fepFile (str, optional): name of fep file, indicating which atoms will be generated/removed
60
+ (if run alchemical simulation). Defaults to ''.
61
+ fepWindowNum (int, optional): number of fep windows. Defaults to 20.
62
+ fepForward (bool, optional): whether this is a forward fep simulation. Defaults to True.
63
+ fepDoubleWide (bool, optional): whether this is a double-wide fep simulation. Defaults to False.
64
+ fepMinBeforeSample (bool, optional): whether do minimization before sampling in each FEP window.
65
+ Defaults to False.
66
+ membraneProtein (bool, optional): whether simulating a membrame protein. Defaults to False.
67
+ OPLSMixingRule (bool, optional): whether use the OPLS mixing rules. Defaults to False.
68
+ GaWTM (bool, optional): Whether this is an GaWTM-eABF simulation. Default to False
69
+ CUDASOAIntegrator (bool, optional): Whether CUDASOA integrator is used. Default to False
70
+ timestep (float, optional): timestep of the simulation. Default to 2.0
71
+
72
+ Returns:
73
+ str: a NAMD config string if succeed, and empty string otherwise
74
+ """
75
+
76
+ assert(forceFieldType == 'charmm' or forceFieldType == 'amber')
77
+
78
+ configString = f'\
79
+ coordinates {coorFile} \n'
80
+
81
+ # force field files
82
+ if forceFieldType == 'charmm':
83
+ configString += f'\
84
+ structure {topFile} \n\
85
+ paraTypeCharmm on \n'
86
+ for ff in forceFieldFiles:
87
+ configString += f'\
88
+ parameters {ff} \n'
89
+ elif forceFieldType == 'amber':
90
+ configString += f'\
91
+ parmFile {topFile} \n\
92
+ amber on \n'
93
+ else:
94
+ # error
95
+ return ''
96
+
97
+ # structure
98
+ if forceFieldType == 'charmm':
99
+ configString += f'\
100
+ exclude scaled1-4 \n\
101
+ 1-4scaling 1.0 \n\
102
+ switching on \n\
103
+ switchdist 10.0 \n\
104
+ cutoff 12.0 \n\
105
+ pairlistdist 14.0 \n'
106
+ elif forceFieldType == 'amber':
107
+ configString += f'\
108
+ exclude scaled1-4 \n\
109
+ 1-4scaling 0.83333333 \n\
110
+ switching on \n\
111
+ switchdist 8.0 \n\
112
+ cutoff 9.0 \n\
113
+ pairlistdist 11.0 \n'
114
+ else:
115
+ # error
116
+ return ''
117
+
118
+ # OPLS mixing rule
119
+ if OPLSMixingRule:
120
+ configString += f'\
121
+ vdwGeometricSigma yes \n'
122
+
123
+ if NAMDRestartCoor == '' and NAMDRestartVel == '' and NAMDRestartXsc == '' and isinstance(PBCCondition, np.ndarray):
124
+ # set temperature
125
+ configString += f'\
126
+ temperature {temperature} \n\
127
+ cellBasisVector1 {PBCCondition[0][0]} 0 0 \n\
128
+ cellBasisVector2 0 {PBCCondition[0][1]} 0 \n\
129
+ cellBasisVector3 0 0 {PBCCondition[0][2]} \n\
130
+ cellOrigin {PBCCondition[1][0]} {PBCCondition[1][1]} {PBCCondition[1][2]} \n'
131
+ elif NAMDRestartCoor != '' and NAMDRestartVel != '' and NAMDRestartXsc != '' and PBCCondition == '':
132
+ # restart from files
133
+ configString += f'\
134
+ bincoordinates {NAMDRestartCoor} \n\
135
+ binvelocities {NAMDRestartVel} \n\
136
+ ExtendedSystem {NAMDRestartXsc} \n'
137
+ else:
138
+ # error
139
+ return ''
140
+
141
+ # other parameters
142
+ configString += f'\
143
+ binaryoutput yes \n\
144
+ binaryrestart yes \n\
145
+ outputname {outputPrefix} \n\
146
+ dcdUnitCell yes \n\
147
+ outputenergies 5000 \n\
148
+ outputtiming 5000 \n\
149
+ outputpressure 5000 \n\
150
+ restartfreq 5000 \n\
151
+ XSTFreq 5000 \n\
152
+ dcdFreq 5000 \n\
153
+ hgroupcutoff 2.8 \n\
154
+ wrapAll off \n\
155
+ wrapWater on \n\
156
+ langevin on \n\
157
+ langevinDamping 1 \n\
158
+ langevinTemp {temperature} \n\
159
+ langevinHydrogen no \n\
160
+ langevinpiston on \n\
161
+ langevinpistontarget 1.01325 \n\
162
+ langevinpistonperiod 200 \n\
163
+ langevinpistondecay 100 \n\
164
+ langevinpistontemp {temperature} \n\
165
+ usegrouppressure yes \n\
166
+ PME yes \n\
167
+ PMETolerance 10e-6 \n\
168
+ PMEInterpOrder 4 \n\
169
+ PMEGridSpacing 1.0 \n\
170
+ timestep {timestep} \n\
171
+ fullelectfrequency 2 \n\
172
+ nonbondedfreq 1 \n\
173
+ rigidbonds all \n\
174
+ rigidtolerance 0.00001 \n\
175
+ rigiditerations 400 \n\
176
+ stepspercycle 10 \n\
177
+ splitpatch hydrogen \n\
178
+ margin 2 \n'
179
+
180
+ # membrane protein
181
+ if membraneProtein:
182
+ configString += f'\
183
+ useflexiblecell yes \n\
184
+ useConstantRatio yes \n'
185
+ else:
186
+ configString += f'\
187
+ useflexiblecell no \n\
188
+ useConstantRatio no \n'
189
+
190
+ # CUDASOA integrator
191
+ if CUDASOAIntegrator:
192
+ configString += f'\
193
+ CUDASOAIntegrate on \n'
194
+
195
+ # colvars definition
196
+ if cvFile != '':
197
+ configString += f'\
198
+ colvars on \n'
199
+ if not GaWTM:
200
+ configString += f'\
201
+ colvarsConfig {cvFile} \n'
202
+
203
+ if CVRestartFile != '':
204
+ configString += f'\
205
+ colvarsInput {CVRestartFile} \n'
206
+
207
+
208
+ if cvDefinitionFile != '':
209
+ configString += f'\
210
+ source {cvDefinitionFile} \n'
211
+
212
+ # fep
213
+ if fepFile == '':
214
+ if NAMDRestartCoor == '' and NAMDRestartVel == '' and NAMDRestartXsc == '':
215
+ configString += f'\
216
+ minimize 500 \n\
217
+ reinitvels {temperature} \n'
218
+ if not GaWTM:
219
+ configString += f'\
220
+ run {numSteps} \n'
221
+ else:
222
+ configString += f'\
223
+ accelMD on \n\
224
+ accelMDG on \n\
225
+ accelMDdihe on \n\
226
+ accelMDOutFreq 1000 \n\
227
+ accelMDGSigma0D 6.0 \n'
228
+ if CVRestartFile == '':
229
+ # new GaMD-WTM-eABF simulation
230
+ configString += f'\
231
+ accelMDGcMDSteps 500000 \n\
232
+ accelMDGcMDPrepSteps 100000 \n\
233
+ accelMDGEquiPrepSteps 100000 \n\
234
+ accelMDGEquiSteps 500000 \n\
235
+ for {{set stage 0}} {{$stage < 2}} {{incr stage}} {{ \n\
236
+ if {{$stage == 0}} {{ \n\
237
+ puts "Probing the GaMD parameters..." \n\
238
+ cv configfile {cvFile} \n\
239
+ run norepeat 1000000 \n\
240
+ }} elseif {{$stage == 1}} {{ \n\
241
+ puts "Starting eABF + GaMD..." \n\
242
+ cv reset \n\
243
+ cv configfile {cvFile + ".amd"} \n\
244
+ run norepeat {numSteps} \n\
245
+ }} \n\
246
+ }} \n'
247
+ else:
248
+ configString += f'\
249
+ accelMDGcMDSteps 0 \n\
250
+ accelMDGcMDPrepSteps 0 \n\
251
+ accelMDGEquiPrepSteps 0 \n\
252
+ accelMDGEquiSteps 0 \n\
253
+ accelMDGRestart on \n\
254
+ accelMDGRestartFile {CVRestartFile}.gamd \n\
255
+ colvarsConfig {cvFile + ".amd"} \n\
256
+ colvarsInput {CVRestartFile} \n\
257
+ run norepeat {numSteps} \n'
258
+
259
+ else:
260
+ # currently the alchemical route is somewhat hard-coded
261
+ # this will be improved in the future
262
+ configString += f'\
263
+ source ../fep.tcl \n\
264
+ alch on \n\
265
+ alchType FEP \n\
266
+ alchFile {fepFile} \n\
267
+ alchCol B \n\
268
+ alchOutFile {outputPrefix}.fepout \n\
269
+ alchOutFreq 50 \n\
270
+ alchVdwLambdaEnd 0.7 \n\
271
+ alchElecLambdaStart 0.5 \n\
272
+ alchEquilSteps 100000 \n'
273
+
274
+ if fepForward:
275
+ if not fepDoubleWide:
276
+ if fepMinBeforeSample:
277
+ # minimize before sampling
278
+ configString += f'\
279
+ runFEPmin 0.0 1.0 {1.0/fepWindowNum} 500000 1000 {temperature}\n'
280
+ else:
281
+ configString += f'\
282
+ runFEP 0.0 1.0 {1.0/fepWindowNum} 500000\n'
283
+
284
+ else:
285
+ # double wide simulation
286
+ configString += f'\
287
+ runFEP 0.0 1.0 {1.0/fepWindowNum} 500000 true\n'
288
+
289
+ else:
290
+ # backward
291
+ if not fepDoubleWide:
292
+ if fepMinBeforeSample:
293
+ # minimize before sampling
294
+ configString += f'\
295
+ runFEPmin 1.0 0.0 {-1.0/fepWindowNum} 500000 1000 {temperature}\n'
296
+ else:
297
+ configString += f'\
298
+ runFEP 1.0 0.0 {-1.0/fepWindowNum} 500000\n'
299
+
300
+ else:
301
+ # double wide simulation
302
+ configString += f'\
303
+ runFEP 1.0 0.0 {-1.0/fepWindowNum} 500000 true\n'
304
+
305
+ return configString
306
+
307
+ def gromacsMinimizeConfigTemplate(self):
308
+ """the gromacs config file template for minimization
309
+
310
+ Returns:
311
+ str: a Gromacs config string if succeed, and empty string otherwise
312
+ """
313
+ configString = f'\
314
+ integrator = steep \n\
315
+ emtol = 418.4 \n\
316
+ emstep = 0.01 \n\
317
+ nsteps = 20000 \n\
318
+ nstlist = 1 \n\
319
+ cutoff-scheme = Verlet \n\
320
+ ns_type = \n\
321
+ coulombtype = PME \n\
322
+ rcoulomb = 1.2 \n\
323
+ rvdw = 1.2 \n\
324
+ pbc = xyz \n'
325
+ return configString
326
+
327
+ def gromacsConfigTemplate(
328
+ self,
329
+ forceFieldType,
330
+ temperature,
331
+ numSteps,
332
+ membraneProtein = False,
333
+ generateVelocities = True
334
+ ):
335
+ """the gromacs config file template
336
+
337
+ Args:
338
+ forceFieldType (str): 'charmm' or 'amber'
339
+ temperature (float): temperature of the simulation
340
+ numSteps (int): number of steps of the simulation
341
+ membraneProtein (bool, optional): whether simulating a membrame protein. Defaults to False.
342
+ generateVelocities (bool, optional): whether generate velocities. Defaults to True.
343
+
344
+ Returns:
345
+ str: a Gromacs config string if succeed, and empty string otherwise
346
+ """
347
+
348
+ configString = f'\
349
+ integrator = md \n\
350
+ nsteps = {numSteps} \n\
351
+ dt = 0.002 \n\
352
+ nstxout = 5000 \n\
353
+ nstvout = 5000 \n\
354
+ nstenergy = 5000 \n\
355
+ nstlog = 5000 \n\
356
+ continuation = no \n\
357
+ constraint_algorithm = lincs \n\
358
+ constraints = h-bonds \n\
359
+ cutoff-scheme = Verlet \n\
360
+ nstlist = 10 \n\
361
+ coulombtype = PME \n'
362
+
363
+ if forceFieldType == 'charmm':
364
+ configString += f'\
365
+ rcoulomb = 1.2 \n\
366
+ rvdw = 1.2 \n\
367
+ rvdw-switch = 1.0 \n'
368
+
369
+ elif forceFieldType == 'amber':
370
+ configString += f'\
371
+ rcoulomb = 0.9 \n\
372
+ rvdw = 0.9 \n\
373
+ rvdw-switch = 0.8 \n'
374
+
375
+ configString += f'\
376
+ vdwtype = Cut-off \n\
377
+ vdw-modifier = force-switch \n\
378
+ DispCorr = EnerPres \n\
379
+ tcoupl = V-rescale \n\
380
+ tc-grps = System \n\
381
+ tau_t = 1 \n\
382
+ ref_t = {temperature} \n\
383
+ pbc = xyz \n\
384
+ pcoupl = C-rescale \n\
385
+ tau-p = 1 \n'
386
+
387
+ if not membraneProtein:
388
+ configString += f'\
389
+ ref-p = 1.01325 \n\
390
+ compressibility = 4.5e-5 \n\
391
+ refcoord-scaling = com \n\
392
+ pcoupltype = isotropic \n'
393
+
394
+ elif membraneProtein:
395
+ configString += f'\
396
+ ref-p = 1.01325 1.01325 \n\
397
+ compressibility = 4.5e-5 4.5e-5 \n\
398
+ refcoord-scaling = com \n\
399
+ pcoupltype = semiisotropic \n'
400
+
401
+ if generateVelocities:
402
+ configString += f'\
403
+ gen_vel = yes \n\
404
+ gen_temp = {temperature} \n\
405
+ gen_seed = -1 \n'
406
+
407
+ return configString
408
+
409
+
410
+ def cvRMSDTemplate(
411
+ self, setBoundary, lowerBoundary, upperBoundary, refFile,
412
+ extendedLagrangian = True, reflectingBoundary = False,
413
+ unit = 'namd'
414
+ ):
415
+ """RMSD CV template
416
+
417
+ Args:
418
+ setBoundary (bool): whether set boundary (for free-energy calculation)
419
+ lowerBoundary (float): lower boundary of free-energy calculaton
420
+ upperboundary (float): upper boundary of free-energy calculation
421
+ refFile (str): path to the reference file
422
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
423
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
424
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
425
+
426
+ Returns:
427
+ str: string of RMSD definition
428
+ """
429
+
430
+ if unit == 'namd':
431
+ scaleFactor = 1
432
+ elif unit == 'gromacs':
433
+ scaleFactor = 0.1
434
+
435
+ string = f'\
436
+ colvar {{ \n\
437
+ name RMSD \n'
438
+
439
+ if setBoundary:
440
+ string += f'\
441
+ width {0.05 * scaleFactor:.2f} \n\
442
+ lowerboundary {lowerBoundary * scaleFactor:.2f} \n\
443
+ upperboundary {upperBoundary * scaleFactor:.2f} \n'
444
+
445
+ if setBoundary and reflectingBoundary:
446
+ string += f'\
447
+ reflectingLowerboundary on \n\
448
+ reflectingUpperboundary on \n'
449
+
450
+ if extendedLagrangian:
451
+ string += f'\
452
+ subtractAppliedForce on \n\
453
+ expandboundaries on \n\
454
+ extendedLagrangian on \n\
455
+ extendedFluctuation {0.05 * scaleFactor:.2f} \n'
456
+
457
+ string += f'\
458
+ rmsd {{ \n\
459
+ atoms {{ \n\
460
+ indexGroup ligand \n\
461
+ }} \n\
462
+ refpositionsfile {refFile} \n\
463
+ }} \n\
464
+ }} \n'
465
+ return string
466
+
467
+ def cvAngleTemplate(
468
+ self, setBoundary, lowerBoundary, upperBoundary, angle,
469
+ refFile, oldDefinition = True, extendedLagrangian = True, reflectingBoundary = False
470
+ ):
471
+ """Eulaer and polar angle template
472
+
473
+ Args:
474
+ setBoundary (bool): whether set boundary (for free-energy calculation)
475
+ lowerBoundary (float): lower boundary of free-energy calculaton
476
+ upperBoundary (float): upper boundary of free-energy calculation
477
+ angle (str): 'eulerTheta', 'eulerPhi', 'eulerPsi', 'polarTheta' or 'polarPhi'
478
+ refFile (str): path to the reference file
479
+ oldDefinition (bool, optional): Whether use old definition of angles
480
+ for compatibility. Defaults to True
481
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
482
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
483
+ """
484
+
485
+ assert(
486
+ angle == 'eulerTheta' or angle == 'eulerPhi' or angle == 'eulerPsi' or \
487
+ angle == 'polarTheta' or angle == 'polarPhi'
488
+ )
489
+
490
+ if angle == 'eulerTheta' or angle == 'eulerPhi' or angle == 'eulerPsi':
491
+ if oldDefinition:
492
+ return self.cvEulerAngleTemplate(
493
+ setBoundary, lowerBoundary, upperBoundary, angle, refFile, extendedLagrangian, reflectingBoundary
494
+ )
495
+ else:
496
+ return self.newCvEulerAngleTemplate(
497
+ setBoundary, lowerBoundary, upperBoundary, angle, refFile, extendedLagrangian, reflectingBoundary
498
+ )
499
+ elif angle == 'polarTheta' or angle == 'polarPhi':
500
+ if oldDefinition:
501
+ return self.cvPolarAngleTemplate(
502
+ setBoundary, lowerBoundary, upperBoundary, angle, refFile, extendedLagrangian, reflectingBoundary
503
+ )
504
+ else:
505
+ return self.newCvPolarAngleTemplate(
506
+ setBoundary, lowerBoundary, upperBoundary, angle, refFile, extendedLagrangian, reflectingBoundary
507
+ )
508
+
509
+ def cvEulerAngleTemplate(
510
+ self, setBoundary, lowerBoundary, upperBoundary, angle,
511
+ refFile, extendedLagrangian = True, reflectingBoundary = False
512
+ ):
513
+ """Euler angle template
514
+
515
+ Args:
516
+ setBoundary (bool): whether set boundary (for free-energy calculation)
517
+ lowerBoundary (float): lower boundary of free-energy calculaton
518
+ upperboundary (float): upper boundary of free-energy calculation
519
+ angle (str): 'eulerTheta', 'eulerPhi' or 'eulerPsi'
520
+ refFile (str): path to the reference file
521
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
522
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
523
+
524
+ Returns:
525
+ string: string of Euler angle definition
526
+ """
527
+
528
+ assert(angle == 'eulerTheta' or angle == 'eulerPhi' or angle == 'eulerPsi')
529
+
530
+ string = f'\
531
+ colvar {{ \n\
532
+ name {angle} \n'
533
+
534
+ if angle == 'eulerTheta':
535
+ string += f'\
536
+ customFunction asin(2 * (q1*q3-q4*q2)) * 180 / 3.1415926\n'
537
+ elif angle == 'eulerPhi':
538
+ string += f'\
539
+ customFunction atan2(2*(q1*q2+q3*q4), 1-2*(q2*q2+q3*q3)) * 180 / 3.1415926\n'
540
+ elif angle == 'eulerPsi':
541
+ string += f'\
542
+ customFunction atan2(2*(q1*q4+q2*q3), 1-2*(q3*q3+q4*q4)) * 180 / 3.1415926\n'
543
+
544
+ if setBoundary:
545
+ string += f'\
546
+ width 1 \n\
547
+ lowerboundary {lowerBoundary:.1f} \n\
548
+ upperboundary {upperBoundary:.1f} \n'
549
+
550
+ if setBoundary and reflectingBoundary:
551
+ string += f'\
552
+ reflectingLowerboundary on \n\
553
+ reflectingUpperboundary on \n'
554
+
555
+ if extendedLagrangian:
556
+ string += f'\
557
+ subtractAppliedForce on \n\
558
+ expandboundaries on \n\
559
+ extendedLagrangian on \n\
560
+ extendedFluctuation 1 \n'
561
+
562
+ string += f'\
563
+ Orientation {{ \n\
564
+ name q \n\
565
+ atoms {{ \n\
566
+ indexGroup ligand \n\
567
+ centerReference on \n\
568
+ rotateReference on \n\
569
+ enableFitGradients no \n\
570
+ fittingGroup {{ \n\
571
+ indexGroup protein \n\
572
+ }} \n\
573
+ refpositionsfile {refFile} \n\
574
+ }} \n\
575
+ refpositionsfile {refFile} \n\
576
+ }} \n\
577
+ }} \n'
578
+
579
+ return string
580
+
581
+ def cvPolarAngleTemplate(
582
+ self, setBoundary, lowerBoundary, upperBoundary, angle,
583
+ refFile, extendedLagrangian = True, reflectingBoundary = False
584
+ ):
585
+ """Polar angle template
586
+
587
+ Args:
588
+ setBoundary (bool): whether set boundary (for free-energy calculation)
589
+ lowerBoundary (float): lower boundary of free-energy calculaton
590
+ upperboundary (float): upper boundary of free-energy calculation
591
+ angle (str): 'polarTheta' or 'polarPhi'
592
+ refFile (str): path to the reference file
593
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
594
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
595
+
596
+ Return:
597
+ str: string of polar angle definition
598
+ """
599
+
600
+ assert(angle == 'polarTheta' or angle == 'polarPhi')
601
+
602
+ string = f'\
603
+ colvar {{ \n\
604
+ name {angle} \n'
605
+
606
+ if angle == 'polarTheta':
607
+ string += f'\
608
+ customFunction acos(-i2) * 180 / 3.1415926\n'
609
+ elif angle == 'polarPhi':
610
+ string += f'\
611
+ customFunction atan2(i3, i1) * 180 / 3.1415926\n\
612
+ period 360 \n\
613
+ wrapAround 0.0 \n'
614
+
615
+ if setBoundary:
616
+ string += f'\
617
+ width 1 \n\
618
+ lowerboundary {lowerBoundary:.1f} \n\
619
+ upperboundary {upperBoundary:.1f} \n'
620
+
621
+ if setBoundary and reflectingBoundary:
622
+ string += f'\
623
+ reflectingLowerboundary on \n\
624
+ reflectingUpperboundary on \n'
625
+
626
+ if extendedLagrangian:
627
+ string += f'\
628
+ subtractAppliedForce on \n\
629
+ expandboundaries on \n\
630
+ extendedLagrangian on \n\
631
+ extendedFluctuation 1 \n'
632
+
633
+ string += f'\
634
+ distanceDir {{ \n\
635
+ name i \n\
636
+ group1 {{ \n\
637
+ indexGroup reference \n\
638
+ centerReference on \n\
639
+ rotateReference on \n\
640
+ enableFitGradients no \n\
641
+ fittingGroup {{ \n\
642
+ indexGroup protein \n\
643
+ }} \n\
644
+ refpositionsfile {refFile} \n\
645
+ }} \n\
646
+ group2 {{ \n\
647
+ indexGroup ligand \n\
648
+ centerReference on \n\
649
+ rotateReference on \n\
650
+ enableFitGradients no \n\
651
+ fittingGroup {{ \n\
652
+ indexGroup protein \n\
653
+ }} \n\
654
+ refpositionsfile {refFile} \n\
655
+ }} \n\
656
+ }} \n\
657
+ }} \n'
658
+ return string
659
+
660
+ def newCvEulerAngleTemplate(
661
+ self, setBoundary, lowerBoundary, upperBoundary, angle,
662
+ refFile, extendedLagrangian = True, reflectingBoundary = False
663
+ ):
664
+ """new definition Euler angle template, probably the pinning down the protein is not required
665
+
666
+ Args:
667
+ setBoundary (bool): whether set boundary (for free-energy calculation)
668
+ lowerBoundary (float): lower boundary of free-energy calculaton
669
+ upperboundary (float): upper boundary of free-energy calculation
670
+ angle (str): 'eulerTheta', 'eulerPhi' of 'eulerPsi'
671
+ refFile (str): path to the reference file
672
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
673
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
674
+
675
+ Returns:
676
+ string: string of Euler angle definition
677
+ """
678
+
679
+ assert(angle == 'eulerTheta' or angle == 'eulerPhi' or angle == 'eulerPsi')
680
+
681
+ string = f'\
682
+ colvar {{ \n\
683
+ name {angle} \n'
684
+
685
+ if setBoundary:
686
+ string += f'\
687
+ width 1 \n\
688
+ lowerboundary {lowerBoundary:.1f} \n\
689
+ upperboundary {upperBoundary:.1f} \n'
690
+
691
+ if setBoundary and reflectingBoundary:
692
+ string += f'\
693
+ reflectingLowerboundary on \n\
694
+ reflectingUpperboundary on \n'
695
+
696
+ if extendedLagrangian:
697
+ string += f'\
698
+ subtractAppliedForce on \n\
699
+ expandboundaries on \n\
700
+ extendedLagrangian on \n\
701
+ extendedFluctuation 1 \n'
702
+
703
+ string += f'\
704
+ {angle} {{ \n\
705
+ atoms {{ \n\
706
+ indexGroup ligand \n\
707
+ centerReference on \n\
708
+ rotateReference on \n\
709
+ centerToOrigin on \n\
710
+ enableFitGradients on \n\
711
+ fittingGroup {{ \n\
712
+ indexGroup protein \n\
713
+ }} \n\
714
+ refpositionsfile {refFile} \n\
715
+ }} \n\
716
+ refpositionsfile {refFile} \n\
717
+ }} \n\
718
+ }} \n'
719
+
720
+ return string
721
+
722
+ def newCvPolarAngleTemplate(
723
+ self, setBoundary, lowerBoundary, upperBoundary, angle,
724
+ refFile, extendedLagrangian = True, reflectingBoundary = False
725
+ ):
726
+ """new definition of Polar angle template, probably the pinning down the protein is not required
727
+
728
+ Args:
729
+ setBoundary (bool): whether set boundary (for free-energy calculation)
730
+ lowerBoundary (float): lower boundary of free-energy calculaton
731
+ upperboundary (float): upper boundary of free-energy calculation
732
+ angle (str): 'polarTheta' or 'polarPhi'
733
+ refFile (str): path to the reference file
734
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
735
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
736
+
737
+ Return:
738
+ str: string of polar angle definition
739
+ """
740
+
741
+ assert(angle == 'polarTheta' or angle == 'polarPhi')
742
+
743
+ string = f'\
744
+ colvar {{ \n\
745
+ name {angle} \n'
746
+
747
+ if angle == 'polarTheta':
748
+ string += f'\
749
+ customFunction acos(-sin(t / 180 * 3.1415926) * sin(p / 180 * 3.1415926)) * 180 / 3.1415926\n'
750
+ elif angle == 'polarPhi':
751
+ string += f'\
752
+ customFunction atan2(cos(t / 180 * 3.1415926), cos(p / 180 * 3.1415926) * sin(t / 180 * 3.1415926)) * 180 / 3.1415926\n\
753
+ period 360 \n\
754
+ wrapAround 0.0 \n'
755
+
756
+ if setBoundary:
757
+ string += f'\
758
+ width 1 \n\
759
+ lowerboundary {lowerBoundary:.1f} \n\
760
+ upperboundary {upperBoundary:.1f} \n'
761
+
762
+ if setBoundary and reflectingBoundary:
763
+ string += f'\
764
+ reflectingLowerboundary on \n\
765
+ reflectingUpperboundary on \n'
766
+
767
+ if extendedLagrangian:
768
+ string += f'\
769
+ subtractAppliedForce on \n\
770
+ expandboundaries on \n\
771
+ extendedLagrangian on \n\
772
+ extendedFluctuation 1 \n'
773
+
774
+ string += f'\
775
+ polarTheta {{ \n\
776
+ name t \n\
777
+ atoms {{ \n\
778
+ indexGroup ligand \n\
779
+ centerReference on \n\
780
+ rotateReference on \n\
781
+ centerToOrigin on \n\
782
+ fittingGroup {{ \n\
783
+ indexGroup protein \n\
784
+ }} \n\
785
+ refpositionsfile {refFile} \n\
786
+ }} \n\
787
+ }} \n\
788
+ polarPhi {{ \n\
789
+ name p \n\
790
+ atoms {{ \n\
791
+ indexGroup ligand \n\
792
+ centerReference on \n\
793
+ rotateReference on \n\
794
+ centerToOrigin on \n\
795
+ fittingGroup {{ \n\
796
+ indexGroup protein \n\
797
+ }} \n\
798
+ refpositionsfile {refFile} \n\
799
+ }} \n\
800
+ }} \n\
801
+ }} \n'
802
+ return string
803
+
804
+ def cvRTemplate(
805
+ self, setBoundary, lowerBoundary, upperBoundary,
806
+ extendedLagrangian = True, reflectingBoundary = False,
807
+ unit = 'namd'
808
+ ):
809
+ """r distance template
810
+
811
+ Args:
812
+ setBoundary (bool): whether set boundary (for free-energy calculation)
813
+ lowerBoundary (float): lower boundary of free-energy calculaton
814
+ upperboundary (float): upper boundary of free-energy
815
+ extendedLagrangian (bool, optional): Whether extended Lagrangian is added. Default to True
816
+ reflectingBoundary (bool, optional): Whether use reflecting boundaries, requires setBoundary on. Default to False
817
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
818
+
819
+ Returns:
820
+ str: string of distance r definition
821
+ """
822
+
823
+ if unit == 'namd':
824
+ scaleFactor = 1
825
+ elif unit == 'gromacs':
826
+ scaleFactor = 0.1
827
+
828
+ string = f'\
829
+ colvar {{ \n\
830
+ name r \n'
831
+ if setBoundary:
832
+ string += f'\
833
+ width {0.1 * scaleFactor:.2f} \n\
834
+ lowerboundary {lowerBoundary * scaleFactor:.2f} \n\
835
+ upperboundary {upperBoundary * scaleFactor:.2f} \n'
836
+
837
+ if setBoundary and reflectingBoundary:
838
+ string += f'\
839
+ reflectingLowerboundary on \n\
840
+ reflectingUpperboundary on \n'
841
+
842
+ if extendedLagrangian:
843
+ string += f'\
844
+ subtractAppliedForce on \n\
845
+ expandboundaries on \n\
846
+ extendedLagrangian on \n\
847
+ extendedFluctuation {0.1 * scaleFactor:.2f} \n'
848
+
849
+ string += f'\
850
+ distance {{ \n\
851
+ forceNoPBC yes \n\
852
+ group1 {{ \n\
853
+ indexGroup reference \n\
854
+ }} \n\
855
+ group2 {{ \n\
856
+ indexGroup ligand \n\
857
+ }} \n\
858
+ }} \n\
859
+ }} \n'
860
+
861
+ return string
862
+
863
+ def cvHeadTemplate(self, indexFile, reweightAMD=False):
864
+ """return the head of colvars file
865
+
866
+ Args:
867
+ indexFile (str): name of ndx file
868
+ reweightAMD (bool, optional): if reweightAMD, there should be "smp off" in the
869
+ head. Default to False.
870
+
871
+ Returns:
872
+ str: head of colvars file
873
+ """
874
+
875
+ string = f'\
876
+ colvarsTrajFrequency 5000 \n\
877
+ colvarsRestartFrequency 5000 \n\
878
+ indexFile {indexFile} \n'
879
+ # if reweightAMD:
880
+ # string += f'\
881
+ #smp off \n'
882
+ return string
883
+
884
+ def cvHarmonicWallsTemplate(self, cv, lowerWall, upperWall, unit = 'namd'):
885
+ ''' template of harmonic wall bias
886
+
887
+ Args:
888
+ cv (str): name of the colvars
889
+ lowerWall (float): lower wall of the bias
890
+ upperWall (float): upper wall of the bias
891
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
892
+
893
+ Returns:
894
+ str: string of the harmonic wall bias definition '''
895
+
896
+ if cv == 'RMSD' or cv == 'r':
897
+ distanceCV = True
898
+ else:
899
+ distanceCV = False
900
+
901
+ if unit == 'gromacs' and distanceCV:
902
+ scaleFactor = 0.1
903
+ else:
904
+ scaleFactor = 1
905
+
906
+ string = f'\
907
+ harmonicWalls {{ \n\
908
+ colvars {cv} \n\
909
+ lowerWalls {lowerWall * scaleFactor:.1f} \n\
910
+ upperWalls {upperWall * scaleFactor:.1f} \n\
911
+ lowerWallConstant 0.2 \n\
912
+ upperWallConstant 0.2 \n\
913
+ }} \n'
914
+ return string
915
+
916
+ def cvHarmonicTemplate(
917
+ self, cv, constant, center, tiWindows=0, tiForward=True, targetForceConstant = 0,
918
+ unit = 'namd'
919
+ ):
920
+ """template for a harmonic restraint
921
+
922
+ Args:
923
+ cv (str): name of the colvars
924
+ constant (float): force constant of the restraint
925
+ center (float): center of the restraint
926
+ tiWindows (int): number of windows of the TI simulation (if runs a TI simulation). Defaults to 0.
927
+ tiForward (bool, optional): whether the TI simulation is forward (if runs a TI simulation). Defaults to True.
928
+ targetForceConstant (int, optional): targeted force constant of the restraint in TI simulation (if runs a TI simulation).
929
+ Defaults to 0.
930
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
931
+
932
+ Returns:
933
+ str: string of the harmonic restraint definition
934
+ """
935
+
936
+ if cv == 'RMSD' or cv == 'r':
937
+ distanceCV = True
938
+ else:
939
+ distanceCV = False
940
+
941
+ if unit == 'gromacs' and distanceCV:
942
+ forceConstantScaleFactor = 418.4
943
+ centerScaleFactor = 0.1
944
+ elif unit == 'gromacs' and not distanceCV:
945
+ forceConstantScaleFactor = 4.164
946
+ centerScaleFactor = 1
947
+ else:
948
+ forceConstantScaleFactor = 1
949
+ centerScaleFactor = 1
950
+
951
+
952
+ string = f'\
953
+ harmonic {{ \n\
954
+ colvars {cv} \n\
955
+ forceConstant {constant * forceConstantScaleFactor:.1f} \n\
956
+ centers {center * centerScaleFactor:.1f} \n'
957
+
958
+ if tiWindows != 0:
959
+ string += f'\
960
+ targetNumSteps 500000 \n\
961
+ targetEquilSteps 100000 \n\
962
+ targetForceConstant {targetForceConstant * forceConstantScaleFactor:.1f} \n\
963
+ targetForceExponent 4 \n'
964
+
965
+ schedule = ''
966
+ if tiForward:
967
+ schedule += ' '.join([str(float(i) / float(tiWindows)) for i in range(tiWindows+1)])
968
+ else:
969
+ schedule += ' '.join([str(float(i) / float(tiWindows)) for i in range(tiWindows, -1, -1)])
970
+
971
+ string += f' lambdaSchedule {schedule}\n'
972
+
973
+ string += '}\n'
974
+ return string
975
+
976
+ def cvABFTemplate(self, cv, unit = 'namd'):
977
+ ''' template for WTM-eABF bias
978
+
979
+ Args:
980
+ cv (str): name of the colvars
981
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
982
+
983
+ Returns:
984
+ str: string of the WTM-eABF definition '''
985
+
986
+ if unit == 'namd':
987
+ scaleFactor = 1
988
+ elif unit == 'gromacs':
989
+ scaleFactor = 4.184
990
+
991
+ string = f'\
992
+ abf {{ \n\
993
+ colvars {cv} \n\
994
+ FullSamples 10000 \n\
995
+ historyfreq 50000 \n\
996
+ writeCZARwindowFile \n\
997
+ }} \n\
998
+ metadynamics {{ \n\
999
+ colvars {cv} \n\
1000
+ hillWidth 3.0 \n\
1001
+ hillWeight {0.05 * scaleFactor:.2f} \n\
1002
+ wellTempered on \n\
1003
+ biasTemperature 4000 \n\
1004
+ }} \n'
1005
+ return string
1006
+
1007
+ def cvHistogramTemplate(self, cv):
1008
+ """ template for outputting the histogram of the CV
1009
+
1010
+ Args:
1011
+ cv (str): name of the colvars
1012
+
1013
+ Returns:
1014
+ str: string of the histogram definition
1015
+ """
1016
+
1017
+ string = f'\
1018
+ histogram {{ \n\
1019
+ colvars {cv} \n\
1020
+ outputFileDX none \n\
1021
+ outputFreq 10000 \n\
1022
+ }} \n'
1023
+ return string
1024
+
1025
+ def cvReweightAMDTemplate(self, cv):
1026
+ """ template for reweight aMD results
1027
+
1028
+ Args:
1029
+ cv (str): name of the colvars
1030
+
1031
+ Returns:
1032
+ str: string of the reweightamd definition
1033
+ """
1034
+
1035
+ string = f'\
1036
+ reweightamd {{ \n\
1037
+ colvars {cv} \n\
1038
+ }} \n'
1039
+ return string
1040
+
1041
+ def cvProteinTemplate(self, centerCoor, refFile, unit = 'namd'):
1042
+ """the template of restraining the protein
1043
+
1044
+ Args:
1045
+ centerCoor (np.array, 3): (x,y,z), center of the protein
1046
+ refFile (str): path of the reference file
1047
+ unit (str, optional): unit, 'namd' or 'gromacs'. Default to namd.
1048
+
1049
+ Returns:
1050
+ str: string of the restraining the protein
1051
+ """
1052
+
1053
+ if unit == 'namd':
1054
+ translationCoorScaleFactor = 1
1055
+ translationForceScaleFactor = 1
1056
+ orientationForceScaleFactor = 1
1057
+ elif unit == 'gromacs':
1058
+ translationCoorScaleFactor = 0.1
1059
+ translationForceScaleFactor = 418.4
1060
+ orientationForceScaleFactor = 4.184
1061
+
1062
+ string = f'\
1063
+ colvar {{ \n\
1064
+ name translation \n\
1065
+ distance {{ \n\
1066
+ group1 {{ \n\
1067
+ indexGroup protein \n\
1068
+ }} \n\
1069
+ group2 {{ \n\
1070
+ dummyAtom ({centerCoor[0] * translationCoorScaleFactor}, {centerCoor[1] * translationCoorScaleFactor}, {centerCoor[2] * translationCoorScaleFactor}) \n\
1071
+ }} \n\
1072
+ }} \n\
1073
+ }} \n\
1074
+ harmonic {{ \n\
1075
+ colvars translation \n\
1076
+ centers 0.0 \n\
1077
+ forceConstant {100.0 * translationForceScaleFactor:.1f} \n\
1078
+ }} \n\
1079
+ \n\
1080
+ colvar {{ \n\
1081
+ name orientation \n\
1082
+ orientation {{ \n\
1083
+ atoms {{ \n\
1084
+ indexGroup protein \n\
1085
+ }} \n\
1086
+ refPositionsFile {refFile} \n\
1087
+ }} \n\
1088
+ }} \n\
1089
+ harmonic {{ \n\
1090
+ colvars orientation \n\
1091
+ centers (1.0, 0.0, 0.0, 0.0) \n\
1092
+ forceConstant {2000.0 * orientationForceScaleFactor:.1f} \n\
1093
+ }} \n'
1094
+ return string