-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.py
412 lines (357 loc) · 20.6 KB
/
prepare.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import argparse
import functions
import os
import sofra
import prepare_afe
import logging
logger = logging.getLogger()
logger.setLevel(logging.CRITICAL)
def main():
parser = argparse.ArgumentParser(description="MEZE: MetalloEnZymE FF-builder for alchemistry")
parser.add_argument("-n",
"--non-metal",
dest="non_metal",
help="boolean flag for preparing non-metal proteins",
action="store_true")
parser.add_argument("-co",
"--cut-off",
dest="cut_off",
help="cut off distance in Å, used to define zinc coordinating ligands and active site",
default=2.6,
type=float)
parser.add_argument("-fc0",
"--force-constant-0",
dest="force_constant_0",
help="force constant for model 0",
default=100,
type=float)
parser.add_argument("-if",
"--input-pdb-file",
dest="protein",
type=functions.file_exists,
help="input pdb file for the metalloenzyme/protein")
parser.add_argument("-g",
"--group-name",
dest="group_name",
help="group name for system, e.g. vim2/kpc2/ndm1/etc.; default taken from input filename",
default="meze")
parser.add_argument("-ppd",
"--protein-prep-directory",
dest="protein_directory",
help="path to protein preparation directory, default: $CWD + /inputs/protein/",
default=os.getcwd()+"/inputs/protein/")
parser.add_argument("-ff",
"--force-field",
dest="forcefield",
help="protein force field, default is ff14SB",
default="ff14SB")
parser.add_argument("-w",
"--water-model",
dest="water_model",
help="water model, default is tip3p",
default="tip3p")
parser.add_argument("-lpd",
"--ligand-prep-directory",
dest="ligand_directory",
help="path to ligands preparation directory, default: $CWD + /inputs/ligands/",
default=os.getcwd()+"/inputs/ligands/")
parser.add_argument("-c",
"--ligand-charge",
dest="ligand_charge",
help="ligand charge",
default=0)
parser.add_argument("-pwd",
"--project-working-directory",
dest="working_directory",
type=functions.path_exists,
help="working directory for the project",
default=os.getcwd())
parser.add_argument("-e",
"--engine",
dest="engine",
help="MD engine",
default="SOMD")
parser.add_argument("-lf",
"--ligand-forcefield",
dest="ligand_forcefield",
help="ligand force field",
default="gaff2")
parser.add_argument("-be",
"--box-edges",
dest="box_edges",
help="box edges in angstroms",
type=float,
default=20)
parser.add_argument("-bs",
"--box-shape",
dest="box_shape",
help="box shape",
default="cubic")
parser.add_argument("-st",
"--sampling-time",
dest="sampling_time",
help="sampling time in nanoseconds",
type=float,
default=4)
parser.add_argument("-r",
"--repeats",
dest="repeats",
help="number of AFE repeat runs",
type=int,
default=3)
parser.add_argument("-min",
"--minimisation-steps",
dest="min_steps",
help="number of minimisation steps for equilibration stage",
type=int,
default=5000)
parser.add_argument("-snvt",
"--short-nvt-runtime",
dest="short_nvt",
help="runtime in ps for short NVT equilibration",
type=float,
default=5)
parser.add_argument("-nvt",
"--nvt-runtime",
dest="nvt",
help="runtime in ps for NVT equilibration",
type=float,
default=50)
parser.add_argument("-npt",
"--npt-runtime",
dest="npt",
help="runtime in ps for NPT equilibration",
type=float,
default=200)
parser.add_argument("--em-step",
dest="emstep",
help="Step size for energy minimisation",
type=float,
default=0.001)
parser.add_argument("--em-tolerance",
dest="emtol",
help="kJ mol-1 nm-1, Maximum force tolerance for energy minimisation",
type=float,
default=1000)
parser.add_argument("-lw",
"--lambda-windows",
dest="lambdas",
help="number of lambda windows to use for AFE transformations",
type=int,
default=11)
parser.add_argument("-ld",
"--lambda-windows-difficult",
dest="n_difficult",
help="number of lambda windows to use for difficult AFE transformations",
type=int,
default=17)
parser.add_argument("-sm",
"--solvation-method",
dest="solvation_method",
help="MD engine used for solvation; default is BioSimSpace (GROMACS)",
choices=["amber", "gromacs"],
default="amber",
type=str)
parser.add_argument("-sc",
"--solvent-closeness",
dest="solvent_closeness",
help="control how close, in \AA, solvent atoms can come to solute atoms, default 1.0",
type=float,
default=1.0)
parser.add_argument("-et",
"--extra-transformations",
dest="extra_transformations_file",
help="file containing additional transformations in format: lig A lig B; equivalent to BioSimSpace.generateNetwork links file",
type=str)
parser.add_argument("-pf",
"--protocol-file",
dest="protocol_file",
help="protocol file",
type=str,
default=os.getcwd() + "/afe/protocol.dat")
parser.add_argument("-cs",
"--cutoff-scheme",
dest="cutoff_scheme",
help="PME or Reaction Field",
default="rf",
choices=["pme", "rf"],
type=str)
parser.add_argument("-os",
"--only-save-end-states",
help="tell somd to only save trajectories for lambda 0 and lambda 1",
action=argparse.BooleanOptionalAction,
dest="only_save_end_states")
arguments = parser.parse_args()
if not arguments.non_metal:
metal = True
elif arguments.non_metal:
metal = False
if not arguments.extra_transformations_file:
if metal:
network = prepare_afe.Meze(protein_file=arguments.protein,
cut_off=arguments.cut_off,
force_constant_0=arguments.force_constant_0,
workdir=arguments.working_directory,
ligand_path=arguments.ligand_directory,
ligand_charge=arguments.ligand_charge,
ligand_ff=arguments.ligand_forcefield,
group_name=arguments.group_name,
protein_path=arguments.protein_directory,
water_model=arguments.water_model,
protein_ff=arguments.forcefield,
engine=arguments.engine,
sampling_time=arguments.sampling_time,
box_edges=arguments.box_edges,
box_shape=arguments.box_shape,
min_steps=arguments.min_steps,
short_nvt=arguments.short_nvt,
nvt=arguments.nvt,
npt=arguments.npt,
min_dt=arguments.emstep,
min_tol=arguments.emtol,
repeats=arguments.repeats,
n_normal=arguments.lambdas,
n_difficult=arguments.n_difficult,
cutoff_scheme=arguments.cutoff_scheme,
solvation_method=arguments.solvation_method,
solvent_closeness=arguments.solvent_closeness,
only_save_end_states=arguments.only_save_end_states)
elif not metal:
network = sofra.Sofra(protein_file=arguments.protein,
workdir=arguments.working_directory,
ligand_path=arguments.ligand_directory,
ligand_charge=arguments.ligand_charge,
ligand_ff=arguments.ligand_forcefield,
group_name=arguments.group_name,
protein_path=arguments.protein_directory,
water_model=arguments.water_model,
protein_ff=arguments.forcefield,
engine=arguments.engine,
sampling_time=arguments.sampling_time,
box_edges=arguments.box_edges,
box_shape=arguments.box_shape,
min_steps=arguments.min_steps,
short_nvt=arguments.short_nvt,
nvt=arguments.nvt,
npt=arguments.npt,
min_dt=arguments.emstep,
min_tol=arguments.emtol,
repeats=arguments.repeats,
n_normal=arguments.lambdas,
n_difficult=arguments.n_difficult,
solvation_method=arguments.solvation_method,
solvent_closeness=arguments.solvent_closeness,
only_save_end_states=arguments.only_save_end_states)
prepared_network = network.prepare_network()
functions.write_slurm_script(template_file="02_add_water.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=prepared_network.protocol_file,
extra_lines={"LIGANDS_DATA_FILE": prepared_network.ligands_dat_file,
"TRANSFORMATIONS_DATA_FILE": prepared_network.network_file})
functions.write_slurm_script(template_file="03_heat_meze.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=prepared_network.protocol_file,
extra_lines={"LIGANDS_DATA_FILE": prepared_network.ligands_dat_file,
"TRANSFORMATIONS_DATA_FILE": prepared_network.network_file})
functions.write_slurm_script(template_file="04_meze.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=prepared_network.protocol_file)
prepared_network.write_afe_run_script()
functions.write_slurm_script(template_file="06_analyse.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=prepared_network.protein_file)
functions.write_slurm_script(template_file="slurm_all.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=prepared_network.protocol_file,
extra_lines={"NUMBER_OF_LIGANDS": prepared_network.n_ligands,
"ENGINE": prepared_network.md_engine,
"AFE_PATH": prepared_network.afe_input_directory,
"LIGANDS_DATA_FILE": prepared_network.ligands_dat_file,
"TRANSFORMATIONS_DATA_FILE": prepared_network.network_file})
elif arguments.extra_transformations_file:
protocol_file = functions.file_exists(arguments.protocol_file)
protocol = functions.input_to_dict(protocol_file)
if metal:
prepared_network = prepare_afe.Meze(prepared=True,
protein_file=protocol["protein input file"],
cut_off=protocol["cutoff"],
force_constant_0=protocol["force constant"],
workdir=protocol["project directory"],
ligand_path=protocol["ligand directory"],
ligand_charge=protocol["ligand charge"],
ligand_ff=protocol["ligand forcefield"],
group_name=protocol["group name"],
protein_path=protocol["protein directory"],
water_model=protocol["water model"],
protein_ff=protocol["protein forcefield"],
engine=protocol["engine"],
sampling_time=protocol["sampling time"],
box_edges=protocol["box edges"],
box_shape=protocol["box shape"],
min_steps=protocol["minimisation steps"],
short_nvt=protocol["short nvt"],
nvt=protocol["nvt"],
npt=protocol["npt"],
min_dt=protocol["minimisation stepsize"],
min_tol=protocol["minimisation tolerance"],
repeats=protocol["repeats"],
temperature=protocol["temperature"],
pressure=protocol["pressure"],
n_normal=arguments.lambdas,
n_difficult=arguments.n_difficult,
only_save_end_states=arguments.only_save_end_states)
elif not metal:
prepared_network = sofra.Sofra(prepared=True,
equilibration_path=protocol["equilibration directory"],
outputs=protocol["outputs"],
workdir=protocol["project directory"],
ligand_path=protocol["ligand directory"],
group_name=protocol["group name"],
protein_file=protocol["prepared protein file"],
protein_path=protocol["protein directory"],
water_model=protocol["water model"],
ligand_ff=protocol["ligand forcefield"],
protein_ff=protocol["protein forcefield"],
ligand_charge=protocol["ligand charge"],
engine=protocol["engine"],
sampling_time=protocol["sampling time"],
box_edges=protocol["box edges"],
box_shape=protocol["box shape"],
min_steps=protocol["minimisation steps"],
short_nvt=protocol["short nvt"],
nvt=protocol["nvt"],
npt=protocol["npt"],
min_dt=protocol["minimisation stepsize"],
min_tol=protocol["minimisation tolerance"],
repeats=protocol["repeats"],
temperature=protocol["temperature"],
pressure=protocol["pressure"],
n_normal=arguments.lambdas,
n_difficult=arguments.n_difficult,
solvation_method=protocol["solvation_method"],
solvent_closeness=protocol["solvent_closeness"],
only_save_end_states=arguments.only_save_end_states)
links_file = functions.file_exists(arguments.extra_transformations_file)
_, transformations_file = prepared_network.set_transformations(links_file=links_file)
functions.write_slurm_script(template_file="run_extra_edges.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=protocol_file,
extra_lines={"ENGINE": prepared_network.md_engine,
"AFE_PATH": prepared_network.afe_input_directory,
"TRANSFORMATIONS_DATA_FILE": transformations_file})
functions.write_slurm_script(template_file="07_extra_meze.sh",
path=prepared_network.afe_input_directory,
log_dir=prepared_network.log_directory,
protocol_file=arguments.protocol_file,
extra_lines={"EXTRA_TRANSFORMATIONS": transformations_file})
print("\n")
print("Successfully prepared meze network for AFE calculations.")
print(f"Run scripts saved in: {prepared_network.afe_input_directory}")
if __name__ == "__main__":
main()