-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwrite_mdp.py
47 lines (29 loc) · 1.09 KB
/
write_mdp.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
import sys
import os
import argparse
import configparser
def set_jobdir (args):
with open(args.input_mdp) as f:
file_content = '[top]\n' + f.read()
config_parser = configparser.RawConfigParser()
config_parser.read_string(file_content)
prefix = os.path.basename(args.input_mdp).split('.')[0]
os.makedirs (prefix,exist_ok=True)
for i in range (0, args.num_lambdas):
config_parser.set('top', 'init_lambda_state', i)
tmp_file = prefix + os.sep + prefix + "_"+str(i)+".mdp"
with open (tmp_file,"w") as fp:
config_parser.write(fp)
with open (tmp_file,"r") as fp:
lines = fp.readlines()
with open (tmp_file,"w") as fp:
for line in lines[1:]:
fp.write(line)
print("Please check:",prefix)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
config_parser = configparser.ConfigParser()
parser.add_argument ('-i','--input-mdp',help='Input mdp file')
parser.add_argument ('-n','--num-lambdas',type=int, help='Number of lambdas')
args = parser.parse_args()
set_jobdir (args)