Mercurial > repos > bgruening > ctb_remove_protonation_state
annotate ob_remIons.py @ 0:bdfd80d7586d draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
| author | bgruening | 
|---|---|
| date | Tue, 31 May 2016 11:45:34 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
2 """ | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
3 Input: molecular input file. | 
| 
 
bdfd80d7586d
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. | 
| 
 
bdfd80d7586d
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 | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
6 """ | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
7 import sys, os | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
8 import argparse | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
9 import openbabel | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
10 openbabel.obErrorLog.StopLogging() | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
11 import pybel | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
12 | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
13 def parse_command_line(): | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
14 parser = argparse.ArgumentParser() | 
| 
 
bdfd80d7586d
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') | 
| 
 
bdfd80d7586d
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') | 
| 
 
bdfd80d7586d
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') | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
18 return parser.parse_args() | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
19 | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
20 def remove_ions(args): | 
| 
 
bdfd80d7586d
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) | 
| 
 
bdfd80d7586d
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): | 
| 
 
bdfd80d7586d
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: | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
24 mol.OBMol.StripSalts(0) | 
| 
 
bdfd80d7586d
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 | 
| 
 
bdfd80d7586d
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: | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
27 outfile.write(mol) | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
28 outfile.close() | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
29 | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
30 def __main__(): | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
31 """ | 
| 
 
bdfd80d7586d
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. | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
33 """ | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
34 args = parse_command_line() | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
35 remove_ions(args) | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
36 | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
37 if __name__ == "__main__" : | 
| 
 
bdfd80d7586d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 4a60df09ddf9dfcedad80f7b72a927198da2f755
 
bgruening 
parents:  
diff
changeset
 | 
38 __main__() | 
