Rdkit: No way to ignore warnings

Created on 3 Oct 2019  路  3Comments  路  Source: rdkit/rdkit

I can't find a way to ignore RDKit's warnings

I'm using RDKit version 2019.03.4; I haven't been able to suppress the warnings that
pop up when trying to convert a SMILES string to a molecule object.

I have to parse a LARGE number of smiles (~46 M strings) and all of them have hydrogen atoms without neighbors. Each time RDKit parses one of the smiles strings I get the warning

[17:58:45] WARNING: not removing hydrogen atom without neighbors

Since the number of strings is so large, this results in a significant slowdown...

My current workaround is to redirect stderr to /dev/null, but there surely is a better solution? I couldn't find it, and it seems that python's warnings module doesn't interact with RDKit's warnings at all.

question

Most helpful comment

@IgnacioJPickering: the RDKit warnings are done at the C++ level and, you are correct, they don't integrate well with the normal Python warnings module.

You can, however, switch off the messages using functionality in the RDLogger module:

In [1]: from rdkit import Chem                                                                                                                                                                   

In [2]: from rdkit import RDLogger                                                                                                                                                               

In [3]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            
[09:26:28] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4


In [4]: RDLogger.DisableLog('rdApp.*')                                                                                                                                                           

In [5]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            

In [6]:  

All 3 comments

@IgnacioJPickering: the RDKit warnings are done at the C++ level and, you are correct, they don't integrate well with the normal Python warnings module.

You can, however, switch off the messages using functionality in the RDLogger module:

In [1]: from rdkit import Chem                                                                                                                                                                   

In [2]: from rdkit import RDLogger                                                                                                                                                               

In [3]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            
[09:26:28] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4


In [4]: RDLogger.DisableLog('rdApp.*')                                                                                                                                                           

In [5]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            

In [6]:  

@IgnacioJPickering: the RDKit warnings are done at the C++ level and, you are correct, they don't integrate well with the normal Python warnings module.

You can, however, switch off the messages using functionality in the RDLogger module:

In [1]: from rdkit import Chem                                                                                                                                                                   

In [2]: from rdkit import RDLogger                                                                                                                                                               

In [3]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            
[09:26:28] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4


In [4]: RDLogger.DisableLog('rdApp.*')                                                                                                                                                           

In [5]: Chem.MolFromSmiles('c1cncc1')                                                                                                                                                            

In [6]:  

Thank you so much! After quite a lot googling, finally solved this problem XD

Thanks for this suggestion @greglandrum , this was about 90% of what I needed.

For people coming here through Google who like me have a slightly different use case:

If you only want to see a specific warning for example we wanted to disable
WARNING: not removing hydrogen atom without neighbors but we want to see the logs for Can't kekulize mol. Unkekulized atoms: 0 1 2 3 4

Also, full disclosure, I haven't tried this but I think it should work.

RDLogger.DisableLog('rdApp.info')                                                                                                                                                       
Chem.MolFromSmiles('<long_SMILES_STRING_TO_IGNORE>')  # this line won't print                                                                                                                                                           
RDLogger.EnableLog('rdApp.info')                                                                                                                                                        
Chem.MolFromSmiles('c1cncc1') # this line will print     
Was this page helpful?
0 / 5 - 0 ratings

Related issues

panpan2 picture panpan2  路  3Comments

michaelosthege picture michaelosthege  路  6Comments

rvianello picture rvianello  路  3Comments

mc-robinson picture mc-robinson  路  5Comments

contrebande-labs picture contrebande-labs  路  5Comments