annotate remove_protonation_state.py @ 13:274193d6c443 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 327c29cc43f56d7067ab9fa51323ea31951db98b"
author bgruening
date Tue, 10 Nov 2020 20:32:42 +0000
parents 2912ebf12ef2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
2 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
3 Input: molecular input file.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
4 Output: Molecule file with removed ions and fragments.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
5 Copyright 2013, Bjoern Gruening and Xavier Lucas
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
6 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
7 import argparse
11
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
8
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
9 from openbabel import openbabel, pybel
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
10 openbabel.obErrorLog.StopLogging()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
11
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
12
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
13 def parse_command_line():
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
14 parser = argparse.ArgumentParser()
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
15 parser.add_argument('--iformat', default='sdf', help='input file format')
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
16 parser.add_argument('-i', '--input', required=True, help='input file name')
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
17 parser.add_argument('-o', '--output', required=True, help='output file name')
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
18 return parser.parse_args()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
19
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
20
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
21 def remove_protonation(args):
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
23 for mol in pybel.readfile(args.iformat, args.input):
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
24 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms]
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
25 if 'inchi' in mol.data:
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
26 del mol.data['inchi'] # remove inchi cache so modified mol is saved
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
27 outfile.write(mol)
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
28 outfile.close()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
29
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
30
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
31 def __main__():
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
32 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
33 Remove any protonation state from each atom in each molecule.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
34 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
35 args = parse_command_line()
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
36 remove_protonation(args)
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
37
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
38
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
39 if __name__ == "__main__":
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
40 __main__()