annotate ob_remIons.py @ 11:78640d0127ce draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
author bgruening
date Tue, 28 Jul 2020 08:36:19 -0400
parents b0311f002a5f
children 2912ebf12ef2
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 2012, 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 sys, os
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
8 import argparse
11
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
9
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
10 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
11 openbabel.obErrorLog.StopLogging()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
12
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()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
15 parser.add_argument('-iformat', default='sdf' , help='input file format')
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
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
20 def remove_ions(args):
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
21 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
22 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
23 if mol.OBMol.NumHvyAtoms() > 5:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
24 mol.OBMol.StripSalts(0)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
25 # Check if new small fragments have been created and remove them
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
26 if mol.OBMol.NumHvyAtoms() > 5:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
27 outfile.write(mol)
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
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
30 def __main__():
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
31 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
32 Remove any counterion and delete any fragment but the largest one for each molecule.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
33 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
34 args = parse_command_line()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
35 remove_ions(args)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
36
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
37 if __name__ == "__main__" :
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
38 __main__()