Re: [Rdkit-discuss] Capturing warnings

2012-10-30 Thread Greg Landrum
Hi Grégori,

On Mon, Oct 29, 2012 at 10:05 AM, Gerebtzoff, Gregori
 wrote:
>
> Is there a clean way to capture the warnings generated by RDKit, for
> instance “Warning: ring stereochemistry detected. The output SMILES is not
> canonical”?
>
> I tried several approaches (the warnings python module, by redirecting the
> stderr with os.devnull, or try/except) but none of them allowed me to
> capture these warnings.

unfortunately there's no way to capture errors or warnings to a file.

You can disable all the warning messages:

In [4]: from rdkit import RDLogger

In [5]: lg = RDLogger.logger()

In [6]: Chem.CanonSmiles('C[C@H]1CC[C@H](C)CC1')
[06:01:43] Warning: ring stereochemistry detected. The output SMILES
is not canonical.
[06:01:43] Warning: ring stereochemistry detected. The output SMILES
is not canonical.
Out[6]: 'C[C@@H]1CC[C@@H](C)CC1'

In [7]: lg.setLevel(RDLogger.ERROR)

In [8]: Chem.CanonSmiles('C[C@H]1CC[C@H](C)CC1')
Out[8]: 'C[C@@H]1CC[C@@H](C)CC1'

In [9]: lg.setLevel(RDLogger.WARNING)

In [10]: Chem.CanonSmiles('C[C@H]1CC[C@H](C)CC1')
[06:02:04] Warning: ring stereochemistry detected. The output SMILES
is not canonical.
[06:02:04] Warning: ring stereochemistry detected. The output SMILES
is not canonical.
Out[10]: 'C[C@@H]1CC[C@@H](C)CC1'


or you can send warning and error messages to a file by redirecting stderr:
~ > python -c "from rdkit import
Chem;Chem.CanonSmiles('C[C@H]1CC[C@H](C)CC1')" 2> err.txt
~ > cat err.txt
[06:03:37] Warning: ring stereochemistry detected. The output SMILES
is not canonical.
[06:03:37] Warning: ring stereochemistry detected. The output SMILES
is not canonical.

But this only helps outside of the RDKit.

I've avoided spending any real time on this because getting logging
right is tricky and there is, theoretically, a boost logging library
coming. Of course, it's been theoretically coming for a couple of
years now, so maybe it's time to give up.

-greg

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Capturing warnings

2012-10-29 Thread Gerebtzoff, Gregori
Hi List,

Is there a clean way to capture the warnings generated by RDKit, for instance 
"Warning: ring stereochemistry detected. The output SMILES is not canonical"?
I tried several approaches (the warnings python module, by redirecting the 
stderr with os.devnull, or try/except) but none of them allowed me to capture 
these warnings.

Many thanks for your advices!

Best,

Grégori
--
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss