How to disable logged warnings in Pybel?

本秂侑毒 提交于 2019-12-11 07:42:32

问题


I am using Pybel - a Python wrapper around the OpenBabel API, and I am trying to disable warnings such as these:

==============================
*** Open Babel Warning  in ParseComplex
  Illegal aromatic element b-

My warnings were raised consistently when fingerprinting molecule SMILES fetched from ChEMBL


回答1:


You can obtain a handle to the openbabel logger (the class OBMessageHandler) off of the openbabel module. The trick is to first access the openbabel module off of the pybel module, grab the OBMessageHandler class, and instantiate the logger (docs):

import pybel

ob_log_handler = pybel.ob.OBMessageHandler()

Using the handle, you can set the log_level to 0 to disable all but critical messages (docs):

ob_log_handler.SetOutputLevel(0)

You can use the following enumerations (docs here) to choose your level of logging. The default is 1, which logs all warnings:

  • 0: Critical
  • 1: Warning (default)
  • 2: Info
  • 3: Audit (when molecules are destroyed/perceived)
  • 4: Debug


来源:https://stackoverflow.com/questions/50419371/how-to-disable-logged-warnings-in-pybel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!