comparison ob_remIons.py @ 14:8ee975c49a3d draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
author bgruening
date Mon, 19 Oct 2020 14:41:44 +0000
parents ff2dd4b7d918
children df4dc55197dd
comparison
equal deleted inserted replaced
13:ff2dd4b7d918 14:8ee975c49a3d
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 2012, Bjoern Gruening and Xavier Lucas 5 Copyright 2012, 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
20 def remove_ions(args): 21 def remove_ions(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 if mol.OBMol.NumHvyAtoms() > 5: 24 if mol.OBMol.NumHvyAtoms() > 5:
24 mol.OBMol.StripSalts(0) 25 mol.OBMol.StripSalts(0)
26 if 'inchi' in mol.data:
27 del mol.data['inchi'] # remove inchi cache so modified mol is saved
25 # Check if new small fragments have been created and remove them 28 # Check if new small fragments have been created and remove them
26 if mol.OBMol.NumHvyAtoms() > 5: 29 if mol.OBMol.NumHvyAtoms() > 5:
27 outfile.write(mol) 30 outfile.write(mol)
28 outfile.close() 31 outfile.close()
32
29 33
30 def __main__(): 34 def __main__():
31 """ 35 """
32 Remove any counterion and delete any fragment but the largest one for each molecule. 36 Remove any counterion and delete any fragment but the largest one for each molecule.
33 """ 37 """
34 args = parse_command_line() 38 args = parse_command_line()
35 remove_ions(args) 39 remove_ions(args)
36 40
37 if __name__ == "__main__" : 41
42 if __name__ == "__main__":
38 __main__() 43 __main__()