Mercurial > repos > bgruening > openbabel_remduplicates
comparison remove_protonation_state.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 | f3099132512d | 
   comparison
  equal
  deleted
  inserted
  replaced
| 12:8c4a4e9e173c | 13:d44de092fef3 | 
|---|---|
| 2 """ | 2 """ | 
| 3 Input: molecular input file. | 3 Input: molecular input file. | 
| 4 Output: Molecule file with removed ions and fragments. | 4 Output: Molecule file with removed ions and fragments. | 
| 5 Copyright 2013, Bjoern Gruening and Xavier Lucas | 5 Copyright 2013, Bjoern Gruening and Xavier Lucas | 
| 6 """ | 6 """ | 
| 7 import sys, os | |
| 8 import argparse | 7 import argparse | 
| 9 | 8 | 
| 10 from openbabel import openbabel, pybel | 9 from openbabel import openbabel, pybel | 
| 11 openbabel.obErrorLog.StopLogging() | 10 openbabel.obErrorLog.StopLogging() | 
| 12 | 11 | 
| 12 | |
| 13 def parse_command_line(): | 13 def parse_command_line(): | 
| 14 parser = argparse.ArgumentParser() | 14 parser = argparse.ArgumentParser() | 
| 15 parser.add_argument('--iformat', default='sdf' , help='input file format') | 15 parser.add_argument('--iformat', default='sdf', help='input file format') | 
| 16 parser.add_argument('-i', '--input', required=True, help='input file name') | 16 parser.add_argument('-i', '--input', required=True, help='input file name') | 
| 17 parser.add_argument('-o', '--output', required=True, help='output file name') | 17 parser.add_argument('-o', '--output', required=True, help='output file name') | 
| 18 return parser.parse_args() | 18 return parser.parse_args() | 
| 19 | 19 | 
| 20 def remove_protonation( args ): | 20 | 
| 21 def remove_protonation(args): | |
| 21 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) | 22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) | 
| 22 for mol in pybel.readfile(args.iformat, args.input): | 23 for mol in pybel.readfile(args.iformat, args.input): | 
| 23 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms] | 24 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms] | 
| 24 outfile.write( mol ) | 25 if 'inchi' in mol.data: | 
| 26 del mol.data['inchi'] # remove inchi cache so modified mol is saved | |
| 27 outfile.write(mol) | |
| 25 outfile.close() | 28 outfile.close() | 
| 29 | |
| 26 | 30 | 
| 27 def __main__(): | 31 def __main__(): | 
| 28 """ | 32 """ | 
| 29 Remove any protonation state from each atom in each molecule. | 33 Remove any protonation state from each atom in each molecule. | 
| 30 """ | 34 """ | 
| 31 args = parse_command_line() | 35 args = parse_command_line() | 
| 32 remove_protonation( args ) | 36 remove_protonation(args) | 
| 33 | 37 | 
| 34 if __name__ == "__main__" : | 38 | 
| 39 if __name__ == "__main__": | |
| 35 __main__() | 40 __main__() | 
