That’s true, but I always hated ‘do your homework’ kind of answers, especially 
when I was completely lost and did not know where to start from (which may not 
be your case).

 

 import sys

from rdkit import Chem

 

saved_std_err = sys.stderr

log = sys.stderr = open('test_log.log', mode='w')

Chem.WrapLogs()

 

mol = Chem.MolFromSmiles('c1ccccc1(C)(C)')

 

log.close()

sys.stderr = saved_std_err

 

works

 

Lukas

 

From: Brian Lee <brian.kihoon....@gmail.com>
Date: Wednesday, 25 September 2019 at 20:55
To: <mi...@novadatasolutions.co.uk>
Cc: RDKIT mailing list <rdkit-discuss@lists.sourceforge.net>, Lukas Pravda 
<lpra...@ebi.ac.uk>
Subject: Re: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files

 

This isn't so much an RDKit question as it is a python IO question. I'd look 
into the docs at https://docs.python.org/3/library/io.html as a starting point.

 

On Wed, Sep 25, 2019 at 2:13 AM <mi...@novadatasolutions.co.uk> wrote:

Hi.

Yes this works for me as per the RDKit docs.  But I need to pipe it to a file, 
any suggestions?

Thanks.

Mike

Get Outlook for Android

 



On Tue, Sep 24, 2019 at 10:28 PM +0100, "Lukas Pravda" <lpra...@ebi.ac.uk> 
wrote:

Hi Mike,

 

The following code works for me:

 

import sys

from io import StringIO

from rdkit import Chem

 

saved_std_err = sys.stderr

log = sys.stderr = StringIO()

Chem.WrapLogs()

 

# do whatever you want with rdkit

 

whatever_used_to_be_printed_by_rdkit_in_console_as_str = log.getvalue()

sys.stderr = saved_std_err

 

 

This populated the stream in memory, if you replace StringIO with FileIO I 
think you can directly redirect it to file, but have not tested that. Let me 
know if this works for you.

 

Lukas

From: <mi...@novadatasolutions.co.uk>
Date: Tuesday, 24 September 2019 at 16:52
To: RDKIT mailing list <rdkit-discuss@lists.sourceforge.net>
Subject: [Rdkit-discuss] Fwd: sending warnings to stderr/stdout to files

 

 

Hi Rdkit forum,

 

Easy question, perhaps difficult to answer…  

 

I’ve been reading a lot of support messages, many a very old about how to get 
warnings (only visible at the cmd line) to be send to files.

I can get error messages sent, but not warnings.

 

The type I’m trying to capture are – which I can see when I run code at the cmd 
line, but not in jupyter-notebook.

“charges were rearranged”

“Omitted undefined stereo”

 

Ideally I’d like to run the code in jupyter-notebook and also at the cmd line 
with python script.py etc  and get the warnings into a file.

 

Can you provide me with a simple example as to how to do this?

 

Thanks,

mike

 

 

Error! Filename not specified.

 

Dr Mike Mazanetz, FRSC

Director

 

Honorary Lecturer

School of Natural and Computing Sciences

University of Aberdeen

 

+44 (0) 141 533 0930

+44 (0) 7780 672509

mi...@novadatasolutions.co.uk

www.novadatasolutions.co.uk

skype michael.mazanetz

 

NovaData Solutions Ltd.

PO Box 639

Abingdon-on-Thames

Oxfordshire

OX14 9JD

United Kingdom

 

 

_______________________________________________ Rdkit-discuss mailing list 
Rdkit-discuss@lists.sourceforge.net 
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss 

_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to