Hi Grégori, On Mon, Oct 29, 2012 at 10:05 AM, Gerebtzoff, Gregori <gregori.gerebtz...@roche.com> 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