annotate parmconv.py @ 1:5b4ae74b7f0b draft default tip

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