Mercurial > repos > chemteam > gmx_sim
annotate merge_top.py @ 4:cdaed42b4223 draft
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit d75a4b4a47d2a74aacb6d3ff90755f9a5289cfb1"
author | chemteam |
---|---|
date | Wed, 18 Dec 2019 15:25:39 -0500 |
parents | 1a5960636405 |
children | 2e219a2d9327 |
rev | line source |
---|---|
0
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
1 import re |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
2 import sys |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
3 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
4 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
5 def combine_tops(top_text, itp_texts): |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
6 """ |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
7 Search through parent topology top_text and replace |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
8 #include lines with the relevant child topologies |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
9 from the dictionary itp_texts |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
10 """ |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
11 for itp in itp_texts: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
12 # split on include string, then rejoin around itp file |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
13 spl = re.split('#include ".*{}"\n'.format(itp), top_text) |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
14 top_text = itp_texts[itp].join(spl) |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
15 return top_text |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
16 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
17 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
18 top = sys.argv[1] # parent topology file |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
19 itps_file = sys.argv[2] # file with list of child topologies (.itp files) |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
20 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
21 with open(itps_file) as f: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
22 itps = f.read().split() |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
23 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
24 with open(top, 'r') as f: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
25 top_text = f.read() |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
26 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
27 itp_texts = {} # create dictionary of child topologies |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
28 for itp in itps: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
29 with open(itp, 'r') as f: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
30 itp_texts[itp] = f.read() |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
31 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
32 for itp in itp_texts: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
33 # child tops may also refer to each other; we need to check this |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
34 itp_texts[itp] = combine_tops(itp_texts[itp], itp_texts) |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
35 |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
36 with open('top_output.top', 'w') as f: |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
37 # now combine all children into the parent |
1a5960636405
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tools/gromacs commit 3b99f08f22b9e0c16c0a0adc82f8c16c1a25cedf"
chemteam
parents:
diff
changeset
|
38 f.write(combine_tops(top_text, itp_texts)) |