Mercurial > repos > bgruening > openbabel_compound_convert
diff remove_protonation_state.py @ 13:1400d1977e7b draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
author | bgruening |
---|---|
date | Mon, 19 Oct 2020 14:48:13 +0000 |
parents | 1c66bf08f687 |
children | 4242b4d68e9c |
line wrap: on
line diff
--- a/remove_protonation_state.py Tue Jul 28 08:41:13 2020 -0400 +++ b/remove_protonation_state.py Mon Oct 19 14:48:13 2020 +0000 @@ -4,32 +4,37 @@ Output: Molecule file with removed ions and fragments. Copyright 2013, Bjoern Gruening and Xavier Lucas """ -import sys, os import argparse from openbabel import openbabel, pybel openbabel.obErrorLog.StopLogging() + def parse_command_line(): parser = argparse.ArgumentParser() - parser.add_argument('--iformat', default='sdf' , help='input file format') + parser.add_argument('--iformat', default='sdf', help='input file format') parser.add_argument('-i', '--input', required=True, help='input file name') parser.add_argument('-o', '--output', required=True, help='output file name') return parser.parse_args() -def remove_protonation( args ): + +def remove_protonation(args): outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) for mol in pybel.readfile(args.iformat, args.input): [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms] - outfile.write( mol ) + if 'inchi' in mol.data: + del mol.data['inchi'] # remove inchi cache so modified mol is saved + outfile.write(mol) outfile.close() + def __main__(): """ Remove any protonation state from each atom in each molecule. """ args = parse_command_line() - remove_protonation( args ) + remove_protonation(args) + -if __name__ == "__main__" : +if __name__ == "__main__": __main__()