annotate modify/remove_protonation_state.py @ 2:125da3a296ca draft default tip

Uploaded
author bgruening
date Wed, 15 Jul 2015 12:13:08 -0400
parents 527ecd2fc500
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: molecular input file.
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
4 Output: Molecule file with removed ions and fragments.
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
5 Copyright 2013, Bjoern Gruening and Xavier Lucas
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
6 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
7 import sys, os
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
8 import argparse
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
9 import openbabel
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
10 openbabel.obErrorLog.StopLogging()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
11 import pybel
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
12
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
13 def parse_command_line():
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
14 parser = argparse.ArgumentParser()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
15 parser.add_argument('--iformat', default='sdf' , help='input file format')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
16 parser.add_argument('-i', '--input', required=True, help='input file name')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
17 parser.add_argument('-o', '--output', required=True, help='output file name')
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
18 return parser.parse_args()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
19
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
20 def remove_protonation( args ):
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
21 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
22 for mol in pybel.readfile(args.iformat, args.input):
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
23 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms]
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
24 outfile.write( mol )
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
25 outfile.close()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
26
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
27 def __main__():
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
28 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
29 Remove any protonation state from each atom in each molecule.
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
30 """
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
31 args = parse_command_line()
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
32 remove_protonation( args )
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
33
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
34 if __name__ == "__main__" :
527ecd2fc500 Uploaded
bgruening
parents:
diff changeset
35 __main__()