You are here

scorefxn.show(pose) method in python shell and IDLE

15 posts / 0 new
Last post
scorefxn.show(pose) method in python shell and IDLE
#1

Hi,

I'm trying to write a script using IDLE. I use the method scorefxn.show(pose), however when I run module, nothing happens. When I use this method in python shell, (I mean writing single commands in standard command line with black window, not IDLE) there appears a beautiful table with energy scores. I have to add that in IDLE there is no information about any error - the only thing is that there is no table. Any ideas why?

Post Situation: 
Mon, 2013-07-08 01:34
peony

That function should print the scorefunction output to the standard output. I'm not quite sure how the C++-level standard output is redirected with IDLE. If it's not showing up in the IDLE commandline, it might be showing up in the (possibly invisible) terminal from which IDLE is being launched from. Try launching IDLE from a visible OS shell terminal. (So you should have three windows. One being the editing window for your module, one being the IDLE "Python Shell" window, and the third being the OS terminal from which you launched IDLE.) My guess is the output from the function should show up on the third.

If that is the case, we can look into getting IDLE to properly redirect the C++-level standard output. (Or alternatively, you can look into other Python IDEs.)

Mon, 2013-07-08 11:04
rmoretti

Thanks for reply!

Maybe my question will be trivial, but how should I launch the IDLE from OS terminal? What command or maybe with another way? I only find something like this "/usr/bin/idle" (sorry for this question if it's too simple, but I'm totally beginner)

Mon, 2013-07-08 14:08
peony

You'll want to open up a terminal window which is running BASH or some other OS commandline shell while you're in your GUI environment. Then if you have idle installed as /usr/bin/idle, you simply need to type "idle" at the prompt (typing "/usr/bin/idle" will also work) and press enter. This should launch the IDLE window in a separate window, assuming your system has everything set up appropriately. You can then interact with it the way you normally would interact with it.

(P.S. Even if you're going to be spending most of your time in a GUI or a Python IDE, it'll probably be well worth your time to run through some simple tutorials on the Unix commandline, just to get a better handle on how the system works. (I don't have particular recommendations - a Google search like /Unix command line tutorial/ should get you started.)

Mon, 2013-07-08 16:28
rmoretti

Type idle in the terminal.

For some IDE's to checkout: komodo is good (http://www.activestate.com/komodo-ide), wing is even better (http://www.wingware.com/), ipython for nice tab completion of PyRosetta classes and functions (http://ipython.org/install.html) (on ubuntu linux: sudo apt-get install ipython)

-J

Mon, 2013-07-08 16:24
jadolfbr

Ok. I've used ipython. I've written /usr/bin/idle and still doesn't work (invalid syntax information). Is it because my system isn't set up appropriate? I've assured that C:\Python25\Lib\idlelib on my system PATH, but still nothing. What am I doing wrong now?

Mon, 2013-07-15 04:51
peony

What operating system are you actually using? "/usr/bin/idle" suggests that it's Linux, but "C:\Python25\Lib\idlelib" indicates that it's Windows. How you get a command prompt and then launch IDLE will be different between the different systems.

I think for Windows you would open up a command prompt (could be under something like Start->All Programs->Accessories, though you may need to hunt around to find it.) and then type the command for IDLE. I don't know what it is on Windows, but you could try things like "idle", or try to find the main script for idle under the C:\Python25 directory (I think it's under Tools or something like that.) -- An alternative is to try right clicking on the icon you normally use to launch IDLE. If I recall correctly, there should be an option to run things with or without the separate terminal window (I think it's the difference between launching with "python" or with "pythonw".)

Also, if you are on Linux you would run "/usr/bin/idle" or "idle" at the OS command prompt. You would not run it within ipython (which is expecting Python commands, not OS commands). Jared suggested using ipython as an alternate IDE *instead* of IDLE.

Mon, 2013-07-15 11:00
rmoretti

yep it's working now . I'm using Windows.I checked again PATH, where I found a mistake.

I use command prompt, type idle and there appears IDLE (Python Shell). Then I type my script line by line in IDLE (Python shell) and at the end I use scorefxn.show(pose) and still nothing - no table.
I've tried typing my script line by line in command prompt but there appears an error when I type my first line which is "from rosetta import*".

So I'm still looking for my magic table.

Mon, 2013-07-15 13:40
peony

I don't know why IDLE doesn't seem to be properly redirecting the output.

My suggestion at this point is to try to replicate the function on the python level. Something like the following might work (warning, untested. Be careful about indentation - the forum tends to eat whitespace.)


def scorefunction_show(scorefxn, pose):
scorefxn(pose) #make sure scores are set
print "------------------------------------------------------------"
print " Scores Weight Raw Score Wghtd.Score"
print "------------------------------------------------------------"
sum_weighted=0.0
for i in range(1,len(core.scoring.n_score_types)+1):
scoretype = core.scoring.ScoreType(i)
if scorefxn.has_nonzero_weight( scoretype ):
weight = scorefxn[ scoretype ];
raw = pose.energies().total_energies()[ scoretype ]
print " %-24s %9.3f %9.3f %9.3f" % ( scoretype, weight, raw, weight*raw)
sum_weighted += weight * raw
#endif
#endfor
print "---------------------------------------------------"
print " Total weighted score: %9.3f" % sum_weighted

Mon, 2013-07-15 17:51
rmoretti

Additional note: You could possibly change the for line to


for scoretype in scorefxn.get_nonzero_weighted_scoretypes():

Mon, 2013-07-15 17:53
rmoretti

Hey, thanks a lot for all tips!

Still I have some questions.
I've run the script, but it's stopped with error

Traceback (most recent call last):
File "C:\Users\Michał\Desktop\scorefxn_try", line 23, in
for i in range(1,len(core.scoring.n_score_types)+1):
TypeError: object of type 'ScoreType' has no len()

What can be a reason of it?

Fri, 2013-07-26 11:43
peony

and when I use the second solution with for scoretype in scorefxn.get_nonzero_weighted_scoretypes(): there appears

Traceback (most recent call last):
File "C:/Users/Michał/Desktop/scorefxn_try_2", line 11, in
for scoretype in scorefxn.get_nonzero_weighted_scoretypes():
NameError: name 'scorefxn' is not defined

Sat, 2013-07-27 10:56
peony

It starts working! :D I've used scorefunction_show(scorefxn, pose) inside my function and there've been appeared some kind of table, but unfortunetly it isn't what I was expected to received.

>>> count_pdb_2('C:\Users\Michał\Desktop\EK_pr_inz_all\PyRosetta\my.pdb')
------------------------------------------------------------
Scores Weight Raw Score Wghtd.Score
------------------------------------------------------------
ref 1.000 -14.800 -14.800
---------------------------------------------------
Total weighted score: -14.800
[None]
>>>

It's not the same result that I am receiving from scorefxn.show(pose) in standard python shell. And what [None] is doing here?

Sat, 2013-07-27 12:35
peony

I can add that it looks as if it shows only the last line of correct table. I think the problem might be with the for loop and lines

for scoretype in scorefxn.get_nonzero_weighted_scoretypes():
#scoretype = core.scoring.ScoreType(i)
if scorefxn.has_nonzero_weight( scoretype ):
weight = scorefxn[ scoretype ];

Any ideas how to fix it, please?

Sat, 2013-07-27 13:14
peony

It's working it's working!!! I've found all mistakes. Thanks guys for everything!

Sun, 2013-07-28 03:06
peony