annotate ob_remIons.py @ 0:631cd009009b draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
author bgruening
date Tue, 31 May 2016 11:46:16 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
2 """
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
3 Input: molecular input file.
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
4 Output: Molecule file with removed ions and fragments.
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
5 Copyright 2012, Bjoern Gruening and Xavier Lucas
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
6 """
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
7 import sys, os
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
8 import argparse
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
9 import openbabel
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
10 openbabel.obErrorLog.StopLogging()
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
11 import pybel
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
12
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
13 def parse_command_line():
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
14 parser = argparse.ArgumentParser()
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
15 parser.add_argument('-iformat', default='sdf' , help='input file format')
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
16 parser.add_argument('-i', '--input', required=True, help='input file name')
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
17 parser.add_argument('-o', '--output', required=True, help='output file name')
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
18 return parser.parse_args()
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
19
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
20 def remove_ions(args):
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
21 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
22 for mol in pybel.readfile(args.iformat, args.input):
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
23 if mol.OBMol.NumHvyAtoms() > 5:
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
24 mol.OBMol.StripSalts(0)
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
25 # Check if new small fragments have been created and remove them
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
26 if mol.OBMol.NumHvyAtoms() > 5:
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
27 outfile.write(mol)
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
28 outfile.close()
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
29
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
30 def __main__():
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
31 """
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
32 Remove any counterion and delete any fragment but the largest one for each molecule.
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
33 """
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
34 args = parse_command_line()
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
35 remove_ions(args)
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
36
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
37 if __name__ == "__main__" :
631cd009009b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
bgruening
parents:
diff changeset
38 __main__()