changeset 3:2b82fc7bec67 draft

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit cc13bd32ef2d80b01dc197a3ca120a4ff9f0dacc"
author chemteam
date Fri, 12 Mar 2021 12:32:24 +0000
parents b500cc25dd15
children 267a70416daf
files parmconv.py parmconv.xml template_parmconv.j2
diffstat 3 files changed, 198 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parmconv.py	Fri Mar 12 12:32:24 2021 +0000
@@ -0,0 +1,82 @@
+import argparse
+import io
+import sys
+from contextlib import redirect_stdout
+
+import parmed
+from parmed import amber, gromacs
+from parmed.tools.changeradii import ChRad
+
+
+def parse_command_line(argv):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--istr', help='input structure', required=True)
+    parser.add_argument('--itop', help='input topology file', required=True)
+    parser.add_argument('--istripmask', help='stripmask')
+    parser.add_argument('--iradii', required=True, help='parmed radii are \
+                        GB_RADII amber6,bondi, mbondi, mbondi2, mbondi3')
+    parser.add_argument('--removedihe', action='store_true',
+                        default=False, help='remove dihedrals with zero \
+                        periodicity')
+    parser.add_argument('--removebox', action='store_true',
+                        default=False, help='remove periodic box info')
+    parser.add_argument('--o_prmtop', help='AMBER output topology',
+                        required=True)
+    return parser.parse_args()
+
+
+def get_ids(dihedrals):
+    """
+    goes through dihedrals and looks for any with per=0.
+    returns a reverse sorted list of ids to be removed.
+    """
+    indices = []
+    for k, v in enumerate(dihedrals):
+        f = io.StringIO()
+        with redirect_stdout(f):
+            print(v)
+        if f.getvalue().find("per=0") != -1:
+            indices.append(k)
+    indices.sort(reverse=True)
+    return indices
+
+
+args = parse_command_line(sys.argv)
+
+gmx_top = gromacs.GromacsTopologyFile(args.itop)
+gmx_gro = gromacs.GromacsGroFile.parse(args.istr)
+
+if not args.removebox:
+    # keep box info
+    gmx_top.box = gmx_gro.box
+    gmx_top.positions = gmx_gro.positions
+
+
+if args.removedihe:
+    ids_to_remove = get_ids(gmx_top.dihedrals)
+    print("Original number of dihedrals %i" % len(gmx_top.dihedrals))
+    for i in ids_to_remove:
+        gmx_top.dihedrals.pop(i)
+    print("Update number of dihedrals %i" % len(gmx_top.dihedrals))
+
+if args.istripmask is not None:
+    if args.istripmask == "":
+        pass
+    else:
+        gmx_top.strip(args.istripmask)
+
+radii = str(args.iradii)
+parmed.tools.changeRadii(gmx_top, radii)
+amb_prm = amber.AmberParm.from_structure(gmx_top)
+parmed.tools.changeRadii(amb_prm, radii)
+
+if args.removebox:
+    amb_prm.pointers['IFBOX'] = 0
+
+ChRad(amb_prm, radii)
+for i, atom in enumerate(amb_prm.atoms):
+    amb_prm.parm_data['RADII'][i] = atom.solvent_radius
+    amb_prm.parm_data['SCREEN'][i] = atom.screen
+
+
+amb_prm.write_parm(args.o_prmtop)
--- a/parmconv.xml	Tue Feb 16 21:55:34 2021 +0000
+++ b/parmconv.xml	Fri Mar 12 12:32:24 2021 +0000
@@ -1,8 +1,8 @@
 <tool id="parmconv" name="Convert Parameters" version="@TOOL_VERSION@+galaxy@GALAXY_VERSION@">
-  <description>to AMBER prmtop in preparation for MMPBSA</description>
+  <description>to AMBER prmtop in preparation for MMGBSA/MMPBSA</description>
   <macros>
     <import>macros.xml</import>
-    <token name="@GALAXY_VERSION@">0</token>
+    <token name="@GALAXY_VERSION@">1</token>
   </macros>
   <expand macro="requirements">
     <requirement type="package" version="3.2.0">parmed</requirement>
@@ -11,15 +11,53 @@
   </expand>
   <command detect_errors="exit_code">
     <![CDATA[
-   python '$templating_script' '$inputs' &&
-   PATH_TO_PARMED=\$(dirname `which parmed`) &&
-   export AMBERHOME=\$(dirname \$PATH_TO_PARMED) &&
-   export GMXDATA=\$AMBERHOME/share/gromacs/top/ &&
-   parmed -i ligand.script -O &&
-   parmed -i receptor.script -O &&
-   parmed -i complex.script -O &&
-   parmed -i solvatedcomplex.script -O
-
+    #if $param_inputs.fmt == "GROMACS":
+      python '$__tool_directory__/parmconv.py'
+        --istr '$param_inputs.str_in'
+        --itop '$param_inputs.top_in'
+        $param_inputs.modbehaviour.removedihe
+        $param_inputs.modbehaviour.removebox
+        --iradii '$param_inputs.modbehaviour.radii'
+        --istripmask '$stripmask_ligand'
+        --o_prmtop '$prmtop_ligand'
+      2>&1  &&
+      python '$__tool_directory__/parmconv.py'
+        --istr '$param_inputs.str_in'
+        --itop '$param_inputs.top_in'
+        $param_inputs.modbehaviour.removedihe
+        $param_inputs.modbehaviour.removebox
+        --iradii '$param_inputs.modbehaviour.radii'
+        --istripmask '$stripmask_receptor'
+        --o_prmtop '$prmtop_receptor'
+      2>&1 &&
+      python '$__tool_directory__/parmconv.py'
+        --istr '$param_inputs.str_in'
+        --itop '$param_inputs.top_in'
+        $param_inputs.modbehaviour.removedihe
+        $param_inputs.modbehaviour.removebox
+        --iradii '$param_inputs.modbehaviour.radii'
+        --istripmask '$stripmask_complex'
+        --o_prmtop '$prmtop_complex'
+      2>&1 &&
+      python '$__tool_directory__/parmconv.py'
+        --istr '$param_inputs.str_in'
+        --itop '$param_inputs.top_in'
+        $param_inputs.modbehaviour.removedihe
+        $param_inputs.modbehaviour.removebox
+        --iradii '$param_inputs.modbehaviour.radii'
+        --istripmask '$stripmask_solvatedcomplex'
+        --o_prmtop '$prmtop_solvatedcomplex'
+      2>&1
+    #else
+      python '$templating_script' '$inputs' &&
+      PATH_TO_PARMED=\$(dirname `which parmed`) &&
+      export AMBERHOME=\$(dirname \$PATH_TO_PARMED) &&
+      export GMXDATA=\$AMBERHOME/share/gromacs/top/ &&
+      parmed -i ligand.script -O &&
+      parmed -i receptor.script -O &&
+      parmed -i complex.script -O &&
+      parmed -i solvatedcomplex.script -O
+    #end if
       ]]>
   </command>
   <configfiles>
@@ -93,7 +131,7 @@
   </configfiles>
   <inputs>
     <conditional name="param_inputs">
-      <param name="fmt" type="select" label="Force Field format">
+      <param name="fmt" type="select" label="Input format">
         <option selected="True" value="AMBER">AMBER</option>
         <option value="GROMACS">GROMACS</option>
       </param>
@@ -103,46 +141,45 @@
       <when value="GROMACS">
         <param name="top_in" type="data" label="Input topology (top) file" format="top"/>
         <param name="str_in" type="data" label="Input structure (gro) file" format="gro"/>
+        <section name="modbehaviour" title="Modify behaviour" expanded="false">
+          <param name="removedihe" type="boolean" truevalue="--removedihe" falsevalue="" checked="false" label="Remove all zero period dihedrals" help="This will remove zero period dihedrals from the generated topology"/>
+          <param name="removebox" type="boolean" truevalue="--removebox" falsevalue="" checked="false" label="Remove periodic box information" help="This will remove periodic information from the generated topology"/>
+          <param name="radii" type="select"  label="Radii to use" help="Select the radii to use. Default is mbondi.">
+              <option selected="True" value="mbondi">mbondi</option>
+              <option value="mbondi2">mbondi2</option>
+              <option value="mbondi3">mbondi3</option>
+              <option value="bondi">bondi</option>
+              <option value="amber6">amber6</option>
+          </param>
+        </section>
       </when>
     </conditional>
     <param name="stripmask_ligand" type="text" label="Ligand selection" value="!:UNL" help="Define a valid AMBER stripmask that will select only the ligand">
       <sanitizer>
         <valid initial="string.printable">
-          <remove value="&amp;"/>
+          <add value="&amp;"/>
         </valid>
-        <mapping initial="none">
-          <add source="&amp;" target="__and__"/>
-        </mapping>
       </sanitizer>
     </param>
     <param name="stripmask_receptor" type="text" label="Receptor selection" value=":NA,SOL,UNL" help="Define a valid AMBER stripmask that will select only the receptor">
       <sanitizer>
         <valid initial="string.printable">
-          <remove value="&amp;"/>
+          <add value="&amp;"/>
         </valid>
-        <mapping initial="none">
-          <add source="&amp;" target="__and__"/>
-        </mapping>
       </sanitizer>
     </param>
     <param name="stripmask_complex" type="text" label="Complex selection" value=":NA,SOL" help="Define a valid AMBER stripmask that will select the complex (receptor with ligand)">
       <sanitizer>
         <valid initial="string.printable">
-          <remove value="&amp;"/>
+          <add value="&amp;"/>
         </valid>
-        <mapping initial="none">
-          <add source="&amp;" target="__and__"/>
-        </mapping>
       </sanitizer>
     </param>
     <param name="stripmask_solvatedcomplex" type="text" label="Solvated complex selection" help="Define a valid AMBER stripmask that will select the solvated complex (includes water and ions)">
       <sanitizer>
         <valid initial="string.printable">
-          <remove value="&amp;"/>
+          <add value="&amp;"/>
         </valid>
-        <mapping initial="none">
-          <add source="&amp;" target="__and__"/>
-        </mapping>
       </sanitizer>
     </param>
   </inputs>
@@ -200,24 +237,68 @@
       <param name="stripmask_solvatedcomplex" value=":1-500@O&amp;!(:WAT|:LYS,ARG)"/>
       <output name="prmtop_ligand">
         <assert_contents>
-          <has_text text="       8      59"/>
           <has_text text="%FLAG MASS"/>
           <has_text text="CL"/>
+          <has_text text="SOLVENT_POINTERS"/>
+          <has_text text="BOX_DIMENSIONS"/>
         </assert_contents>
       </output>
       <output name="prmtop_receptor">
         <assert_contents>
-          <has_text text="    1960      59"/>
           <has_text text="%FLAG MASS"/>
           <has_text text="LYS VAL PHE "/>
+          <has_text text="SOLVENT_POINTERS"/>
+          <has_text text="BOX_DIMENSIONS"/>
           <not_has_text text="CL "/>
         </assert_contents>
       </output>
       <output name="prmtop_solvatedcomplex">
         <assert_contents>
-          <has_text text="   38265      59"/>
           <has_text text="%FLAG MASS"/>
           <has_text text="LYS VAL PHE"/>
+          <has_text text="SOLVENT_POINTERS"/>
+          <has_text text="BOX_DIMENSIONS"/>
+        </assert_contents>
+      </output>
+    </test>
+    <test>
+      <!-- test with removing dihedrals and periodicity -->
+      <param name="fmt" value="GROMACS"/>
+      <conditional name="param_inputs">
+        <param name="top_in" value="topol_solv.top"/>
+        <param name="str_in" value="solv_ions.gro"/>
+      </conditional>
+      <!-- dihedrals and periodicity -->
+      <param name="removedihe" value="--removedihe"/>
+      <param name="removebox" value="--removebox"/>
+      <!-- pretending CL is a ligand -->
+      <param name="stripmask_ligand" value="!:CL"/>
+      <param name="stripmask_receptor" value=":NA,CL,SOL,WAT"/>
+      <!-- test a fairly complex selection. All backbone oxygens in residues 1-500 but not in water, lysine or arginine -->
+      <param name="stripmask_solvatedcomplex" value=":1-500@O&amp;!(:WAT|:LYS,ARG)"/>
+      <output name="prmtop_ligand">
+        <assert_contents>
+          <has_text text="%FLAG MASS"/>
+          <has_text text="CL"/>
+          <not_has_text text="SOLVENT_POINTERS"/>
+          <not_has_text text="BOX_DIMENSIONS"/>
+        </assert_contents>
+      </output>
+      <output name="prmtop_receptor">
+        <assert_contents>
+          <has_text text="%FLAG MASS"/>
+          <has_text text="LYS VAL PHE "/>
+          <not_has_text text="CL "/>
+          <not_has_text text="SOLVENT_POINTERS"/>
+          <not_has_text text="BOX_DIMENSIONS"/>
+        </assert_contents>
+      </output>
+      <output name="prmtop_solvatedcomplex">
+        <assert_contents>
+          <has_text text="%FLAG MASS"/>
+          <has_text text="LYS VAL PHE"/>
+          <not_has_text text="SOLVENT_POINTERS"/>
+          <not_has_text text="BOX_DIMENSIONS"/>
         </assert_contents>
       </output>
     </test>
@@ -228,13 +309,13 @@
 
     **What it does**
 
-    This tool converts parameter and topology files that represent a solvated complex into parameter files for the ligand, receptor, complex and solvated complex in AMBER prmtop format. These files are needed for MMPBSA calculations.
+    This tool converts parameter and topology files that represent a solvated complex into parameter files for the ligand, receptor, complex and solvated complex in AMBER prmtop format. These files are needed for MMGBSA/MMPBSA calculations.
 
     .. class:: infomark
 
     **How it works**
 
-    AmberTools ParmEd is used to strip unneeded atoms and save out the parameter files. The stripmasks are defined by the user.
+    AmberTools' ParmEd is used to strip unneeded atoms and save the parameter files. The stripmasks are defined by the user.
 
     .. class:: infomark
 
--- a/template_parmconv.j2	Tue Feb 16 21:55:34 2021 +0000
+++ b/template_parmconv.j2	Fri Mar 12 12:32:24 2021 +0000
@@ -2,9 +2,9 @@
 {% if fmt == 'AMBER' %}
 parm {{ top_in }}
 {% elif fmt == 'GROMACS' %}
-gromber {{ top_in }} {{gro_in}}
+gromber {{ top_in }} {{str_in}}
 {% elif fmt == 'CHARMM' %}
-chamber {{ top_in }} {{gro_in}}
+chamber {{ top_in }} {{str_in}}
 {% else %}
 parm {{ top_in }}
 {% endif %}