see:
https://docs.python.org/2/tutorial/errors.html

import rdkit
from rdkit import Chem
try:
    Chem.MolFromSmiles('XXX')
except Exception as msg:
    (do something here e.g. pring msg)

pozdrawiam
Adrian

2015-01-23 14:58 GMT+01:00 JP <jeanpaul.ebe...@inhibox.com>:

>
> Yo RDKitters,
>
> I am stuck on something so basic, its embarrassing.  But for the life of
> me I cannot figure it out on my own.  This is probably more of a python
> question than an RDKit one.
>
> I want to capture the RDKit warning/error message from python.  e.g.
>
> >>> import rdkit
> >>> from rdkit import Chem
> >>> Chem.MolFromSmiles('XXX')
> [14:51:32] SMILES Parse Error: syntax error for input: XXX
>
> I want to capture that error message (which in this case isn't very
> informative, but if you read in a mol2 you can get something like
> [14:25:46] 3ZGZ.A: warning - O.co2 with non C.2 or S.o2 neighbor. Which I
> am also interested in).  The big picture is that I built a web up where you
> upload an sdf, mol, mol2 or smi file - and I want to show RDKit's error
> message if there something funny in the query file.
>
> I have tried the obvious (I think):
>
> #!/usr/bin/env python
> import sys
> import rdkit
> from rdkit import Chem
>
> f = open("err.log", "w")
> original_stderr = sys.stderr
> sys.stderr = f
> Chem.MolFromSmiles('XXX')
> sys.stderr = original_stderr
> f.close()
>
> This still shows the error message in the terminal and not in the file.  I
> tried the same for stdout, still no cigar.
>
> Any ideas ?
>
> THANKS!
> JP
>
>
> ------------------------------------------------------------------------------
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to