This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_md.py
executable file
·152 lines (102 loc) · 4.34 KB
/
run_md.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
import sys, os
import argparse
import subprocess as sp
import shutil
parser = argparse.ArgumentParser(description="Run MD")
parser.add_argument("-d", help="Select run directory.", type=str)
parser.add_argument(
"-s",
help="Create 'setup_files' directory with included parameter file.",
default=False,
type=str,
)
parser.add_argument("-em", help="Energy Minimisation", default=False, type=bool)
parser.add_argument("-eq", help="MD Equilibration", default=False, type=bool)
parser.add_argument("-solvate", help="Solvation", default=False, type=bool)
parser.add_argument(
"-sol_box_size", help="Solvation Box Size", default=False, type=float
)
args = parser.parse_args()
def create_em_conf_file_from_template(em_dir, structure_name):
current_dir = os.getcwd()
namd_em_template_conf_file_path = os.path.join(
current_dir, "templates", "namd", "em_template.conf"
)
psf_file_relative_path = "../structures/" + structure_name + ".psf"
pdb_file_relative_path = "../structures/" + structure_name + ".pdb"
namd_em_conf_file_path = os.path.join(em_dir, "em.conf")
with open(namd_em_template_conf_file_path, "r") as namd_em_template_file:
x = namd_em_template_file.read()
x = x.replace("__PSF_FILE_PATH_TOKEN__", psf_file_relative_path)
x = x.replace("__PDB_FILE_PATH_TOKEN__", pdb_file_relative_path)
with open(namd_em_conf_file_path, "w") as namd_em_file:
namd_em_file.write(x)
def _do_em(em_dir):
log_file_path = os.path.join(em_dir, "em.log")
conf_file_path = os.path.join(em_dir, "em.conf")
namd_energy_calc_command = [
"/home/timol/.NAMD_2.13_Linux-x86_64-multicore/namd2",
"+p8",
conf_file_path,
]
f = open(log_file_path, "w")
sp.call(namd_energy_calc_command, stdout=f)
f.close()
def energy_minimisation(base_dir, structure_name):
setup_files_dir = os.path.join(base_dir, "setup_files")
em_dir = os.path.join(setup_files_dir, "em")
if not os.path.exists(em_dir):
os.mkdir(em_dir)
# structure_dir = os.path.join(setup_files_dir, "structure")
create_em_conf_file_from_template(em_dir, structure_name)
_do_em(em_dir)
shutil.copy(
os.path.join(em_dir, "run_output", "em.coor"),
os.path.join(em_dir, "run_output", "em.pdb"),
)
def create_solvation_file_from_template(solvation_dir, structure_name):
current_dir = os.getcwd()
solvate_template_file_path = os.path.join(
current_dir, "templates", "namd", "solvate_template.tcl"
)
solvation_script_file_path = os.path.join(solvation_dir, "solvate.tcl")
psf_file_relative_path = "../structures/" + structure_name + ".psf"
pdb_file_relative_path = "../em/run_output/em.pdb"
MIN = "-30"
MAX = "30"
with open(solvate_template_file_path, "r") as solvation_template:
x = solvation_template.read()
x = x.replace("__SOLVATION_DIR_TOKEN__", solvation_dir)
x = x.replace("__PSF_FILE_PATH_TOKEN__", psf_file_relative_path)
x = x.replace("__PDB_FILE_PATH_TOKEN__", pdb_file_relative_path)
x = x.replace("__LOWER_BOUND_TOKEN__", MIN)
x = x.replace("__UPPER_BOUND_TOKEN__", MAX)
with open(solvation_script_file_path, "w") as solvation_script:
solvation_script.write(x)
def _do_solvation(solvation_dir):
solvation_data_file_path = os.path.join(solvation_dir, "solvate.dat")
solvation_script = os.path.join(solvation_dir, "solvate.tcl")
vmd_solvate_command = [
"vmd",
"-dispdev",
"text",
"-e",
solvation_script,
]
f = open(solvation_data_file_path, "w")
sp.call(vmd_solvate_command, stdout=f)
f.close()
def solvate_minimised_structure(base_dir, structure_name):
setup_files_dir = os.path.join(base_dir, "setup_files")
solvation_dir = os.path.join(setup_files_dir, "solvated")
if not os.path.exists(solvation_dir):
os.mkdir(solvation_dir)
create_solvation_file_from_template(solvation_dir, structure_name)
_do_solvation(solvation_dir)
def main():
base_dir = "/home/timol/C6W/Studies/Dynamics/NAMD/Shigella/MD/Solution/1a_s_flexneri/1a_s_flexneri_3ru/simulations/ring_restrained/"
structure_name = "1a_s_flexneri_3ru"
energy_minimisation(base_dir, structure_name)
solvate_minimised_structure(base_dir, structure_name)
if __name__ == "__main__":
main()