You are here

Capturing the output of scorefxn.show(pose)

3 posts / 0 new
Last post
Capturing the output of scorefxn.show(pose)
#1

I'm using PyRosetta-r21 on Ubuntu togather with IPython 2.0.0 notebooks. This works extremly well, with one small problem:
Some output is redirected to the console in which "ipython notebook" command was started instead of the notebook cell. 
So the question is: is it possible to capture the output of scorefxn.show(pose)?

I have tried to use the example in "test/T007_TracerIO.py"

 

import rosetta as r
r.init()
from toolbox import pose_from_rcsb
#Basic tracer example
T = r.basic.PyTracer()
r.basic.Tracer.set_ios_hook(T, r.basic.Tracer.get_all_channels_string(), True)

pose = pose_from_rcsb("1YY8")
print "Captured IO"
print T.buf()

 

Works very well. But:

scorefxn = r.get_fa_scorefxn()
scorefxn.show(pose)
print '\nCaptured IO'
print T.buf()

 

Does not capture the output. (A side question, can T.buf() be cleared?) 

Doing: "scorefxn.show(pose, T)" raises an error, becaus of incompatible parameters

stream = r.utility.OString()
scorefxn.show(pose, stream)

raises "RuntimeError: This class cannot be instantiated from Python" and

stream = r.utility.OStringStream
scorefxn.show(pose, stream)

Is also incompatible.

 

Thank you for your help and best regards,
Ajasja

Category: 
Post Situation: 
Fri, 2014-06-20 05:30
ajasja

Hi Ajasja,

Here the right way to do this:

b = rosetta.utility.OStringStream()
sf.show(b, pose)
print b.str()

As you can see problem is just in order of arguments.

I am curious, how to do send this output to iPython notebook? Is there is standard API for this?

Thanks,

Fri, 2014-06-20 17:05
Sergey

Ahh, not used to reading the C++ signatures, so I missed it (and forgot that the first parameter is basically self and hidden in python!)

show(core::scoring::ScoreFunction {lvalue}, core::pose::Pose {lvalue} pose)
show(core::scoring::ScoreFunction {lvalue}, std::ostream {lvalue} out, core::pose::Pose {lvalue} pose)
show(core::scoring::ScoreFunction {lvalue}, std::ostream {lvalue} out)

 

>I am curious, how to do send this output to iPython notebook? Is there is standard API for this?I’m not using any particular API. The output of the python print statements is  automatically redirected to the corresponding output cell. Only C/C++ code writing to std out is problematic. Such as the scorefx.show()

Here is a simple notebook I used to start exploring PyRosseta. IPython Notebooks also have tab comlpetition and an inbuilt help viewer, so they are really great for prototyping code.

Thanks & best regards,
Ajasja

Sat, 2014-06-21 11:57
ajasja