Mercurial > repos > bgruening > openbabel_remove_protonation_state
diff ob_remIons.py @ 15:22a866858b81 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
author | bgruening |
---|---|
date | Thu, 15 Aug 2024 11:00:20 +0000 |
parents | e376ba0fcde0 |
children |
line wrap: on
line diff
--- a/ob_remIons.py Tue Nov 10 20:34:01 2020 +0000 +++ b/ob_remIons.py Thu Aug 15 11:00:20 2024 +0000 @@ -8,37 +8,43 @@ 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('-i', '--input', required=True, help='input file name') - parser.add_argument('-o', '--output', required=True, help='output file name') - parser.add_argument('-idx', default=False, action='store_true', help='should output be an indexed text table? works only for inchi/smiles, otherwise is ignored') + 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") + parser.add_argument( + "-idx", + default=False, + action="store_true", + help="should output be an indexed text table? works only for inchi/smiles, otherwise is ignored", + ) return parser.parse_args() def remove_ions(args): - with open(args.output, 'w') as outfile: + with open(args.output, "w") as outfile: for index, mol in enumerate(pybel.readfile(args.iformat, args.input)): if mol.OBMol.NumHvyAtoms() > 5: mol.OBMol.StripSalts(0) - if 'inchi' in mol.data: - del mol.data['inchi'] # remove inchi cache so modified mol is saved + if "inchi" in mol.data: + del mol.data["inchi"] # remove inchi cache so modified mol is saved - mol = mol.write(args.iformat) if mol.OBMol.NumHvyAtoms() > 5 else '\n' + mol = mol.write(args.iformat) if mol.OBMol.NumHvyAtoms() > 5 else "\n" - if args.idx and args.iformat in ['inchi', 'smi']: - outfile.write(f'{index}\t{mol}') - elif mol != '\n': - outfile.write(f'{mol}') + if args.idx and args.iformat in ["inchi", "smi"]: + outfile.write(f"{index}\t{mol}") + elif mol != "\n": + outfile.write(f"{mol}") def __main__(): """ - Remove any counterion and delete any fragment but the largest one for each molecule. + Remove any counterion and delete any fragment but the largest one for each molecule. """ args = parse_command_line() remove_ions(args)