0
|
1 #!/usr/bin/env python
|
|
2 """
|
|
3 Input: Molecule file
|
|
4 Output: Molecule file with hydrogen atoms added at the target pH.
|
|
5 """
|
|
6 import sys, os
|
|
7 import argparse
|
|
8 import openbabel
|
|
9 openbabel.obErrorLog.StopLogging()
|
|
10 import pybel
|
|
11
|
|
12 def parse_command_line(argv):
|
|
13 parser = argparse.ArgumentParser()
|
|
14 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('-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('--pH', type=float, default="7.4", help='Specify target pH value')
|
|
19 return parser.parse_args()
|
|
20
|
|
21 def addh(args):
|
|
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
|
|
23 for mol in pybel.readfile(args.iformat, args.input):
|
|
24 if mol.OBMol.NumHvyAtoms() > 5:
|
|
25 mol.removeh()
|
|
26 mol.OBMol.AddHydrogens(args.polar, True, args.pH)
|
|
27 outfile.write(mol)
|
|
28 outfile.close()
|
|
29
|
|
30 def __main__():
|
|
31 """
|
|
32 Add hydrogen atoms at a certain pH value
|
|
33 """
|
|
34 args = parse_command_line(sys.argv)
|
|
35 addh(args)
|
|
36
|
|
37 if __name__ == "__main__" :
|
|
38 __main__()
|