forked from kzinovjev/string-amber
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_cvs.py
More file actions
executable file
·36 lines (26 loc) · 941 Bytes
/
generate_cvs.py
File metadata and controls
executable file
·36 lines (26 loc) · 941 Bytes
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
#!/usr/bin/env python
import argparse
from parmed.amber import AmberParm, AmberMask
def get_atom_index(top, mask):
return next(AmberMask(top, mask).Selected()) + 1
def write_cv(top, raw_cv_def):
cv_def = raw_cv_def.split()
cv_type = cv_def[0]
indices = [str(get_atom_index(top, mask)) for mask in cv_def[1:]]
print('\n$COLVAR')
print('COLVAR_type = "{}"'.format(cv_type))
print('atoms = {}'.format(', '.join(indices)))
print('$END')
def main():
parser = argparse.ArgumentParser(description="Create CVs file from amber masks")
parser.add_argument("top", help="Topology file")
parser.add_argument("defs", help="CV definitions")
args = parser.parse_args()
top = AmberParm(args.top)
with open(args.defs, 'r') as f:
cv_defs = f.readlines()
print('{}'.format(len(cv_defs)))
for cv_def in cv_defs:
write_cv(top, cv_def)
if __name__ == '__main__':
main()