Can I capture warning messages during format conversion in pybel?

105 views Asked by At

I have a list of molecules in SMILES format that I am converting to InChIKey format. However, a number of them are generating warnings. I would like to be able to generate a file showing the warnings generated in the process of converting each molecule, so that a team member can review them. Is it possible to capture these messages programmatically, instead of just logging them?

A snippet illustrating what I'd like to be able to do:

import pybel

smiles = pybel.readfile('smi', 'smiles.txt')
converted = []
for mol in smiles:
    smiles_str = mol.write('smiles')
    inchikey_str = mol.write('inchikey')
    warnings = None # Is there something I can do here to capture the warnings?
    converted.append((smiles_str, inchikey_str, warnings))
0

There are 0 answers