Mercurial > repos > bgruening > openbabel_filter
comparison ob_addh.py @ 14:8ee975c49a3d draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
author | bgruening |
---|---|
date | Mon, 19 Oct 2020 14:41:44 +0000 |
parents | ff2dd4b7d918 |
children | 988085c7a0ea |
comparison
equal
deleted
inserted
replaced
13:ff2dd4b7d918 | 14:8ee975c49a3d |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 """ | 2 """ |
3 Input: Molecule file | 3 Input: Molecule file |
4 Output: Molecule file with hydrogen atoms added at the target pH. | 4 Output: Molecule file with hydrogen atoms added at the target pH. |
5 """ | 5 """ |
6 import sys, os | |
7 import argparse | 6 import argparse |
7 import sys | |
8 | 8 |
9 from openbabel import openbabel, pybel | 9 from openbabel import openbabel, pybel |
10 openbabel.obErrorLog.StopLogging() | 10 openbabel.obErrorLog.StopLogging() |
11 | 11 |
12 | |
12 def parse_command_line(argv): | 13 def parse_command_line(argv): |
13 parser = argparse.ArgumentParser() | 14 parser = argparse.ArgumentParser() |
14 parser.add_argument('--iformat', type=str, default='sdf' , help='input file format') | 15 parser.add_argument('--iformat', type=str, default='sdf', help='input file format') |
15 parser.add_argument('-i', '--input', type=str, required=True, help='input file name') | 16 parser.add_argument('-i', '--input', type=str, required=True, help='input file name') |
16 parser.add_argument('-o', '--output', type=str, required=True, help='output file name') | 17 parser.add_argument('-o', '--output', type=str, required=True, help='output file name') |
17 parser.add_argument('--polar', action="store_true", default=False, help='Add hydrogen atoms only to polar atoms') | 18 parser.add_argument('--polar', action="store_true", default=False, help='Add hydrogen atoms only to polar atoms') |
18 parser.add_argument('--pH', type=float, default="7.4", help='Specify target pH value') | 19 parser.add_argument('--pH', type=float, default="7.4", help='Specify target pH value') |
19 return parser.parse_args() | 20 return parser.parse_args() |
21 | |
20 | 22 |
21 def addh(args): | 23 def addh(args): |
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) | 24 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) |
23 for mol in pybel.readfile(args.iformat, args.input): | 25 for mol in pybel.readfile(args.iformat, args.input): |
24 if mol.OBMol.NumHvyAtoms() > 5: | 26 if mol.OBMol.NumHvyAtoms() > 5: |
25 mol.removeh() | 27 mol.removeh() |
26 mol.OBMol.AddHydrogens(args.polar, True, args.pH) | 28 mol.OBMol.AddHydrogens(args.polar, True, args.pH) |
27 outfile.write(mol) | 29 outfile.write(mol) |
28 outfile.close() | 30 outfile.close() |
29 | 31 |
32 | |
30 def __main__(): | 33 def __main__(): |
31 """ | 34 """ |
32 Add hydrogen atoms at a certain pH value | 35 Add hydrogen atoms at a certain pH value |
33 """ | 36 """ |
34 args = parse_command_line(sys.argv) | 37 args = parse_command_line(sys.argv) |
35 addh(args) | 38 addh(args) |
36 | 39 |
37 if __name__ == "__main__" : | 40 |
41 if __name__ == "__main__": | |
38 __main__() | 42 __main__() |