comparison merge_top.py @ 0:7f64dd60f5d7 draft

planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tree/master/tools/gromacs commit 27f3e0b555b8178299ada42df33006e2f69b4e80
author chemteam
date Mon, 24 Oct 2022 22:12:01 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7f64dd60f5d7
1 import argparse
2
3 import parmed as pmd
4
5
6 def merge_gro_files(prot_gro, lig_gro, cmplx_gro):
7 prot = pmd.load_file(prot_gro)
8 lig = pmd.load_file(lig_gro)
9 cmplx = prot + lig
10 cmplx.save(cmplx_gro)
11
12
13 def merge_top_files(prot_top, lig_top, cmplx_top):
14 with open(lig_top, 'r') as f:
15 lig_top_sections = f.read().split('\n[')
16
17 # open ligand topology
18 for n in range(len(lig_top_sections)):
19 if 'atomtypes' in lig_top_sections[n][:10]:
20 lig_atomtypes = lig_top_sections[n]
21 del lig_top_sections[n]
22 break
23 else:
24 lig_atomtypes = None
25 lig_top_updated = '\n['.join(lig_top_sections)
26
27 # open protein topology
28 with open(prot_top, 'r') as f:
29 prot_top_combined = f.read()
30 if lig_atomtypes:
31 prot_top_sections = prot_top_combined.split('[ moleculetype ]\n')
32 prot_top_combined = (prot_top_sections[0] +
33 '; Include ligand atomtypes\n[' +
34 lig_atomtypes +
35 '\n[ moleculetype ]\n' +
36 prot_top_sections[1])
37 prot_top_sections = prot_top_combined.split('; Include water topology')
38 prot_top_combined = (prot_top_sections[0] +
39 '; Include ligand topology\n' +
40 lig_top_updated +
41 '\n; Include water topology' +
42 prot_top_sections[1])
43 prot_top_combined += 'base 1\n'
44
45 # save complex topology
46 with open(cmplx_top, 'w') as f:
47 f.write(prot_top_combined)
48
49
50 def main():
51 parser = argparse.ArgumentParser(
52 description='Perform SMD runs for dynamic undocking')
53 parser.add_argument('--lig-top', help='Ligand TOP file.')
54 parser.add_argument('--prot-top', help='Protein TOP file.')
55 parser.add_argument('--lig-gro', help='Ligand GRO file.')
56 parser.add_argument('--prot-gro', help='Protein GRO file.')
57 parser.add_argument('--complex-top', help='Complex TOP file.')
58 parser.add_argument('--complex-gro', help='Complex GRO file.')
59 args = parser.parse_args()
60 merge_gro_files(args.prot_gro, args.lig_gro, args.complex_gro)
61 merge_top_files(args.prot_top, args.lig_top, args.complex_top)
62
63
64 if __name__ == "__main__":
65 main()