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