我可以在pybel格式转换期间捕获警告消息吗?

2024-04-19 10:58:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个SMILES格式的分子列表,我正在转换成InChIKey格式。但是,其中一些正在生成警告。我希望能够生成一个文件,显示在转化每个分子的过程中生成的警告,以便团队成员可以查看它们。是否可以通过编程方式捕获这些消息,而不只是记录它们

这是一段说明我希望能够做什么的片段:

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))

Tags: 文件警告列表格式分子writeconvertedsmiles