-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduction.py
71 lines (53 loc) · 2.04 KB
/
production.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
# Script to run production in python
import subprocess
import argparse
def run(commands, cwd=None):
'''Run commands with subprocess'''
if not isinstance(commands, list):
commands = [commands]
for cmd in commands:
subprocess.run(cmd, shell=True, cwd=cwd)
def grompp(gro, mdp, top, tpr=None, gmx='gmx', flags={}, dry_run=False, **kwargs):
'''
Run grompp with mdp file on gro file with topology top
flags should be a dictionary containing any additional flags, e.g. flags = {'maxwarn' : 1}
'''
if tpr is None:
tpr = gro.split('.gro')[0] + '.tpr'
cmd = [f'{gmx} grompp -f {mdp} -p {top} -c {gro} -o {tpr}']
for f in flags:
cmd[0] += f' -{f} {flags[f]}'
if dry_run:
print(cmd)
else:
run(cmd, **kwargs)
return tpr
def mdrun(tpr, output=None, gmx='gmx', flags={}, dry_run=False, **kwargs):
'''
Run GROMACS with tpr file
flags should be a dictionary containing any additional flags, e.g. flags = {'maxwarn' : 1}
'''
if output is None:
output = tpr.split('.tpr')[0]
cmd = [f'{gmx} mdrun -s {tpr} -deffnm {output}']
for f in flags:
cmd[0] += f' -{f} {flags[f]}'
if dry_run:
print(cmd)
else:
run(cmd, **kwargs)
return output + '.gro'
if __name__ == '__main__':
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--coords', type=str, help='Coordinate file')
parser.add_argument('-p', '--top', type=str, help='Topology file')
parser.add_argument('-f', '--mdp', type=str, help='MDP file')
args = parser.parse_args()
gmx = lambda n : f'mpirun -np {n} gmx_mpi' # GROMACS callable
input_gro = args.coords # initial gro file
input_top = args.top # topology for the system
mdp_file = args.mdp
# NPT (100 ns)
npt_tpr = grompp(input_gro, mdp_file, top=input_top, tpr=f'prod.tpr', gmx=gmx(1), flags={'maxwarn' : 1}, cwd='./production/')
npt_gro = mdrun(npt_tpr, output=f'prod', gmx=gmx(128), cwd='./production/')