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