annotate modify/ob_addh.py @ 0:527ecd2fc500 draft

Uploaded
author bgruening
date Thu, 15 Aug 2013 03:25:06 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
2 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
3 Input: Molecule file
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
4 Output: Molecule file with hydrogen atoms added at the target pH.
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
5 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
6 import sys, os
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
7 import argparse
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
8 import openbabel
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
9 openbabel.obErrorLog.StopLogging()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
10 import pybel
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
11
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
12 def parse_command_line(argv):
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
13 parser = argparse.ArgumentParser()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
14 parser.add_argument('--iformat', type=str, default='sdf' , help='input file format')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
15 parser.add_argument('-i', '--input', type=str, required=True, help='input file name')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
16 parser.add_argument('-o', '--output', type=str, required=True, help='output file name')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
17 parser.add_argument('--polar', action="store_true", default=False, help='Add hydrogen atoms only to polar atoms')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
18 parser.add_argument('--pH', type=float, default="7.4", help='Specify target pH value')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
19 return parser.parse_args()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
20
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
21 def addh(args):
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
23 for mol in pybel.readfile(args.iformat, args.input):
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
24 if mol.OBMol.NumHvyAtoms() > 5:
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
25 mol.removeh()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
26 mol.OBMol.AddHydrogens(args.polar, True, args.pH)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
27 outfile.write(mol)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
28 outfile.close()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
29
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
30 def __main__():
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
31 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
32 Add hydrogen atoms at a certain pH value
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
33 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
34 args = parse_command_line(sys.argv)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
35 addh(args)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
36
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
37 if __name__ == "__main__" :
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
38 __main__()