Discussion:
[Rdkit-discuss] Suppress stdout and stderr in rdkit
Gaetano Calabro
2016-02-17 23:54:37 UTC
Permalink
Hi there,

I wonder if there is an easy way to suppress the standard output and standard error from RDkit. For example:

from rdkit import Chem

smart = '[#6]1(:[#6]:[#6]:[#6]2:[#6](:[#6]:1):[#6]:[#6]:[#6]:[#6]:2)-[#8,#6]'

mol = Chem.MolFromSmarts(smart)

Chem.SanitizeMol(mol)

This will produce the warning message:

[15:52:25] Explicit valence for atom # 3 C, 5, is greater than permitted

I would like to suppress this message. Is there any way to do it?

Thanks,

Gaetano
Gaetano Calabro
2016-02-18 20:53:44 UTC
Permalink
Hi Paolo,

Thanks a lot for your prompt reply. I ended up coding this:

from rdkit import Chem
from rdkit import RDLogger

smart =
'[#6]1(:[#6]:[#6]:[#6]2:[#6](:[#6]:1):[#6]:[#6]:[#6]:[#6]:2)-[#8,#6]'

mol = Chem.MolFromSmarts(smart)

lg = RDLogger.logger()

lg.setLevel(RDLogger.CRITICAL)

try:
Chem.SanitizeMol(mol)
except:
print 'OK'


Ciao,

Gaetano
Dear Gaetano,
from rdkit import rdBase
rdBase.DisableLog('rdApp.error')
You may check the logging levels you wish to disable/enable in
rdkit/RDLogger.py, or use a wildcard such as 'rdApp.*' to affect all
levels at once.
Best,
Paolo
Post by Gaetano Calabro
from rdkit import Chem
smart =
'[#6]1(:[#6]:[#6]:[#6]2:[#6](:[#6]:1):[#6]:[#6]:[#6]:[#6]:2)-[#8,#6]'
mol = Chem.MolFromSmarts(smart)
Chem.SanitizeMol(mol)
Loading...