The Aelfinn
The Aelfinn

Reputation: 16938

How to disable logged warnings in Pybel?

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

Upvotes: 1

Views: 1583

Answers (4)

Huy Pham
Huy Pham

Reputation: 1

We can config the openbabel's logger without pybel like this:

from openbabel import openbabel
openbabel.obErrorLog.StopLogging()

Upvotes: 0

dkoes
dkoes

Reputation: 578

If you want to get rid of all error messages:

pybel.ob.obErrorLog.StopLogging()

Upvotes: 1

hyperparam
hyperparam

Reputation: 11

The Aelfinn's answer didn't work for me, but accessing SetOutputLevel this way did:

pybel.ob.obErrorLog.SetOutputLevel(0)

Upvotes: 1

The Aelfinn
The Aelfinn

Reputation: 16938

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

Upvotes: 1

Related Questions