Mercurial > repos > bgruening > openbabel_remduplicates
annotate ob_remIons.py @ 13:d44de092fef3 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
| author | bgruening | 
|---|---|
| date | Mon, 19 Oct 2020 14:36:22 +0000 | 
| parents | 8c4a4e9e173c | 
| children | 89e8077589f2 | 
| rev | line source | 
|---|---|
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 1 #!/usr/bin/env python | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 2 """ | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 3 Input: molecular input file. | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 4 Output: Molecule file with removed ions and fragments. | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 5 Copyright 2012, Bjoern Gruening and Xavier Lucas | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 6 """ | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 7 import argparse | 
| 12 
8c4a4e9e173c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
 bgruening parents: 
0diff
changeset | 8 | 
| 
8c4a4e9e173c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
 bgruening parents: 
0diff
changeset | 9 from openbabel import openbabel, pybel | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 10 openbabel.obErrorLog.StopLogging() | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 11 | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 12 | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 13 def parse_command_line(): | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 14 parser = argparse.ArgumentParser() | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 15 parser.add_argument('-iformat', default='sdf', help='input file format') | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 16 parser.add_argument('-i', '--input', required=True, help='input file name') | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 17 parser.add_argument('-o', '--output', required=True, help='output file name') | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 18 return parser.parse_args() | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 19 | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 20 | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 21 def remove_ions(args): | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 23 for mol in pybel.readfile(args.iformat, args.input): | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 24 if mol.OBMol.NumHvyAtoms() > 5: | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 25 mol.OBMol.StripSalts(0) | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 26 if 'inchi' in mol.data: | 
| 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 27 del mol.data['inchi'] # remove inchi cache so modified mol is saved | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 28 # Check if new small fragments have been created and remove them | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 29 if mol.OBMol.NumHvyAtoms() > 5: | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 30 outfile.write(mol) | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 31 outfile.close() | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 32 | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 33 | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 34 def __main__(): | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 35 """ | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 36 Remove any counterion and delete any fragment but the largest one for each molecule. | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 37 """ | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 38 args = parse_command_line() | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 39 remove_ions(args) | 
| 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 40 | 
| 13 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 41 | 
| 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 bgruening parents: 
12diff
changeset | 42 if __name__ == "__main__": | 
| 0 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 bgruening parents: diff
changeset | 43 __main__() | 
