Hi, I'm trying to catch the line numbers of lines in a SMILES file that aren't parsed by the SmilesMolSupplier. Example code is attached, along with 2 SMILES files. When there is a bad SMILES string on the last line, the error is not reported, as in test2.smi. I've tried iterating through the file in a loop using next(suppl1) and catching the StopIteration exception, but I have the same issue. Is there a way to spot a last bad record in a file?
Thanks, Dave -- David Cosgrove Freelance computational chemistry and chemoinformatics developer http://cozchemix.co.uk
test1.smi
Description: application/diskcopy
test2.smi
Description: application/diskcopy
#!/usr/bin/env python from rdkit import Chem suppl1 = Chem.SmilesMolSupplier('test1.smi', titleLine=False, nameColumn=1) rec_num = 0 for mol in suppl1: rec_num += 1 if not mol: print('Record {} not read.'.format(rec_num)) else: print('Record {} read ok.'.format(rec_num)) suppl2 = Chem.SmilesMolSupplier('test2.smi', titleLine=False, nameColumn=1) rec_num = 0 for mol in suppl2: rec_num += 1 if not mol: print('Record {} not read.'.format(rec_num)) else: print('Record {} read ok.'.format(rec_num))
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss