comparison remove_protonation_state.py @ 15:c5de6c19eb06 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:46 +0000
parents 12aca74f07d7
children
comparison
equal deleted inserted replaced
14:b2569e22b40c 15:c5de6c19eb06
5 Copyright 2013, Bjoern Gruening and Xavier Lucas 5 Copyright 2013, Bjoern Gruening and Xavier Lucas
6 """ 6 """
7 import argparse 7 import argparse
8 8
9 from openbabel import openbabel, pybel 9 from openbabel import openbabel, pybel
10
10 openbabel.obErrorLog.StopLogging() 11 openbabel.obErrorLog.StopLogging()
11 12
12 13
13 def parse_command_line(): 14 def parse_command_line():
14 parser = argparse.ArgumentParser() 15 parser = argparse.ArgumentParser()
15 parser.add_argument('--iformat', default='sdf', help='input file format') 16 parser.add_argument("--iformat", default="sdf", help="input file format")
16 parser.add_argument('-i', '--input', required=True, help='input file name') 17 parser.add_argument("-i", "--input", required=True, help="input file name")
17 parser.add_argument('-o', '--output', required=True, help='output file name') 18 parser.add_argument("-o", "--output", required=True, help="output file name")
18 return parser.parse_args() 19 return parser.parse_args()
19 20
20 21
21 def remove_protonation(args): 22 def remove_protonation(args):
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) 23 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
23 for mol in pybel.readfile(args.iformat, args.input): 24 for mol in pybel.readfile(args.iformat, args.input):
24 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms] 25 [atom.OBAtom.SetFormalCharge(0) for atom in mol.atoms]
25 if 'inchi' in mol.data: 26 if "inchi" in mol.data:
26 del mol.data['inchi'] # remove inchi cache so modified mol is saved 27 del mol.data["inchi"] # remove inchi cache so modified mol is saved
27 outfile.write(mol) 28 outfile.write(mol)
28 outfile.close() 29 outfile.close()
29 30
30 31
31 def __main__(): 32 def __main__():
32 """ 33 """
33 Remove any protonation state from each atom in each molecule. 34 Remove any protonation state from each atom in each molecule.
34 """ 35 """
35 args = parse_command_line() 36 args = parse_command_line()
36 remove_protonation(args) 37 remove_protonation(args)
37 38
38 39