diff ob_remIons.py @ 13:9ce9f996b941 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:00 +0000
parents afd14e10a318
children 330514267c57
line wrap: on
line diff
--- a/ob_remIons.py	Tue Jul 28 08:35:45 2020 -0400
+++ b/ob_remIons.py	Mon Oct 19 14:41:00 2020 +0000
@@ -4,29 +4,33 @@
     Output: Molecule file with removed ions and fragments.
     Copyright 2012, 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_ions(args):
     outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True)
     for mol in 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
             # Check if new small fragments have been created and remove them
             if mol.OBMol.NumHvyAtoms() > 5:
                 outfile.write(mol)
     outfile.close()
 
+
 def __main__():
     """
         Remove any counterion and delete any fragment but the largest one for each molecule.
@@ -34,5 +38,6 @@
     args = parse_command_line()
     remove_ions(args)
 
-if __name__ == "__main__" :
+
+if __name__ == "__main__":
     __main__()