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