diff gmxtras_extract_top.py @ 0:9faa4f4b8b76 draft default tip

"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/tree/master/tools/buildtools/topologyeditors commit ae026d4ea6fe2ebaa53611b86f9047941c7b899b"
author chemteam
date Thu, 27 Jan 2022 18:17:05 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gmxtras_extract_top.py	Thu Jan 27 18:17:05 2022 +0000
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+import argparse
+
+
+def __main__():
+    parser = argparse.ArgumentParser(
+        description='Adds New topologies to gromacs topology file')
+    parser.add_argument(
+                        '--top_file', default=None,
+                        help="Topologies input")
+    parser.add_argument(
+                        '--out_bondparam', default=None,
+                        help='moleculetype section')
+    parser.add_argument(
+                        '--out_nonbondparam', default=None,
+                        help='atomtypes section')
+
+    args = parser.parse_args()
+    # extracts the atom types with nonbonded terms from
+    # the new molecules and puts them in a new file
+    with open(args.top_file) as inFile:
+        with open(args.out_nonbondparam, "w") as outFile:
+            buffer = []
+            for line in inFile:
+                if line.startswith(";name   bond_type"):
+                    buffer = ['']
+                elif line.startswith("[ moleculetype ]"):
+                    outFile.write("".join(buffer))
+                    buffer = []
+                elif buffer:
+                    buffer.append(line)
+
+    # extracts the molecule types (rest of the force field parameters)
+    # with bonded terms and puts them in a new file
+    with open(args.top_file) as inFile:
+        with open(args.out_bondparam, "w") as outFile:
+            buffer = []
+            for line in inFile:
+                if line.startswith("[ moleculetype ]"):
+                    buffer = ["\n[ moleculetype ]\n"]
+                elif line.startswith("[ system ]"):
+                    outFile.write("".join(buffer))
+                    buffer = []
+                elif buffer:
+                    buffer.append(line)
+
+
+if __name__ == "__main__":
+    __main__()