diff ob_addh.py @ 0:06340f46ecb8 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
author bgruening
date Fri, 10 May 2019 08:55:09 -0400
parents
children de4c80d17527
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ob_addh.py	Fri May 10 08:55:09 2019 -0400
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+"""
+    Input:  Molecule file
+    Output: Molecule file with hydrogen atoms added at the target pH.
+"""
+import sys, os
+import argparse
+import openbabel
+openbabel.obErrorLog.StopLogging()
+import pybel
+
+def parse_command_line(argv):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--iformat', type=str, default='sdf' , help='input file format')
+    parser.add_argument('-i', '--input', type=str, required=True, help='input file name')
+    parser.add_argument('-o', '--output', type=str, required=True, help='output file name')
+    parser.add_argument('--polar', action="store_true", default=False, help='Add hydrogen atoms only to polar atoms')
+    parser.add_argument('--pH', type=float, default="7.4", help='Specify target pH value')
+    return parser.parse_args()
+
+def addh(args):
+    outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
+    for mol in pybel.readfile(args.iformat, args.input):
+        if mol.OBMol.NumHvyAtoms() > 5:
+            mol.removeh()
+            mol.OBMol.AddHydrogens(args.polar, True, args.pH)
+            outfile.write(mol)
+    outfile.close()
+
+def __main__():
+    """
+        Add hydrogen atoms at a certain pH value
+    """
+    args = parse_command_line(sys.argv)
+    addh(args)
+
+if __name__ == "__main__" :
+    __main__()