annotate parmconv.py @ 11:a0c154146234 draft

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 27e76b3f6ed12955fd60609aad4043bc9c60cba2"
author chemteam
date Thu, 07 Oct 2021 09:51:33 +0000
parents c8cdde00b105
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
1 import argparse
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
2 import io
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
3 import sys
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
4 from contextlib import redirect_stdout
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
5
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
6 import parmed
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
7 from parmed import amber, gromacs
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
8 from parmed.tools.changeradii import ChRad
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
9
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
10
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
11 def parse_command_line(argv):
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
12 parser = argparse.ArgumentParser()
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
13 parser.add_argument('--istr', help='input structure', required=True)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
14 parser.add_argument('--itop', help='input topology file', required=True)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
15 parser.add_argument('--istripmask', help='stripmask')
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
16 parser.add_argument('--iradii', required=True, help='parmed radii are \
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
17 GB_RADII amber6,bondi, mbondi, mbondi2, mbondi3')
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
18 parser.add_argument('--removedihe', action='store_true',
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
19 default=False, help='remove dihedrals with zero \
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
20 periodicity')
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
21 parser.add_argument('--removebox', action='store_true',
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
22 default=False, help='remove periodic box info')
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
23 parser.add_argument('--o_prmtop', help='AMBER output topology',
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
24 required=True)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
25 return parser.parse_args()
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
26
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
27
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
28 def get_ids(dihedrals):
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
29 """
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
30 goes through dihedrals and looks for any with per=0.
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
31 returns a reverse sorted list of ids to be removed.
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
32 """
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
33 indices = []
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
34 for k, v in enumerate(dihedrals):
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
35 f = io.StringIO()
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
36 with redirect_stdout(f):
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
37 print(v)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
38 if f.getvalue().find("per=0") != -1:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
39 indices.append(k)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
40 indices.sort(reverse=True)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
41 return indices
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
42
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
43
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
44 args = parse_command_line(sys.argv)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
45
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
46 gmx_top = gromacs.GromacsTopologyFile(args.itop)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
47 gmx_gro = gromacs.GromacsGroFile.parse(args.istr)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
48
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
49 if not args.removebox:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
50 # keep box info
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
51 gmx_top.box = gmx_gro.box
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
52 gmx_top.positions = gmx_gro.positions
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
53
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
54
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
55 if args.removedihe:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
56 ids_to_remove = get_ids(gmx_top.dihedrals)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
57 print("Original number of dihedrals %i" % len(gmx_top.dihedrals))
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
58 for i in ids_to_remove:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
59 gmx_top.dihedrals.pop(i)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
60 print("Update number of dihedrals %i" % len(gmx_top.dihedrals))
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
61
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
62 if args.istripmask is not None:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
63 if args.istripmask == "":
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
64 pass
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
65 else:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
66 gmx_top.strip(args.istripmask)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
67
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
68 radii = str(args.iradii)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
69 parmed.tools.changeRadii(gmx_top, radii)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
70 amb_prm = amber.AmberParm.from_structure(gmx_top)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
71 parmed.tools.changeRadii(amb_prm, radii)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
72
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
73 if args.removebox:
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
74 amb_prm.pointers['IFBOX'] = 0
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
75
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
76 ChRad(amb_prm, radii)
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
77 for i, atom in enumerate(amb_prm.atoms):
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
78 amb_prm.parm_data['RADII'][i] = atom.solvent_radius
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
79 amb_prm.parm_data['SCREEN'][i] = atom.screen
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
80
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
81
c8cdde00b105 "planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
chemteam
parents:
diff changeset
82 amb_prm.write_parm(args.o_prmtop)