comparison gmxtras_add_restraints.py @ 0:5521a057ed6a draft default tip

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tree/master/tools/buildtools/topologyeditors commit ae026d4ea6fe2ebaa53611b86f9047941c7b899b"
author chemteam
date Thu, 27 Jan 2022 18:16:37 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5521a057ed6a
1 #!/usr/bin/env python3
2 import argparse
3 END_OF_MOL = ('[ moleculetype ]', '[ system ]')
4
5
6 def __main__():
7 parser = argparse.ArgumentParser(
8 description='Add restriction to gromacs topology file')
9 parser.add_argument(
10 '--top_file', default=None,
11 help="Topology file input")
12 parser.add_argument(
13 '--res_file', default=None,
14 help='Restraint input')
15 parser.add_argument(
16 '--molecule', default=None,
17 help='Target Molecule Name you restrained')
18 parser.add_argument(
19 '--out', default=None,
20 help='Path to output')
21 args = parser.parse_args()
22 with open(args.out, 'w') as fh_out:
23 with open(args.top_file, 'r') as fh:
24 # for now, we will avoid using 'for line in fh:',
25 # since we have multiple places where we might want
26 # to read the next line
27 while True:
28 line = fh.readline()
29 if not line:
30 # eof
31 break
32 # always write out the line
33 fh_out.write(line)
34 # check if line matches molecule, then check if
35 # molecule name matches args.molecule
36 if line.strip().startswith('[ moleculetype ]'):
37 not_found_molecule = True
38 while not_found_molecule:
39 line = fh.readline()
40 if not line:
41 # eof
42 break
43 # always write this line
44 fh_out.write(line)
45 if not line.strip().startswith(';') or (line.strip()
46 and not line.strip().startswith(';')):
47 # this line should be the name line,
48 fields = line.strip().split()
49 if fields[0] == args.molecule:
50 # found our molecule!
51 while True:
52 line = fh.readline()
53 if not line:
54 # eof
55 break
56 if line.strip().startswith(END_OF_MOL):
57 fh_out.write("\n#ifdef POSRES\n")
58 with open(args.res_file, 'r') as fh_re:
59 for line2 in fh_re:
60 fh_out.write(line2)
61 fh_out.write("#endif\n\n")
62 fh_out.write(line)
63 not_found_molecule = False
64 break
65 fh_out.write(line)
66 else:
67 break
68
69
70 if __name__ == "__main__":
71 __main__()