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

Member Site Forums PyRosetta PyRosetta – Scripts scorefxn.show(pose) method in python shell and IDLE

  • This topic has 14 replies, 3 voices, and was last updated 11 years ago by Anonymous.
Viewing 8 reply threads
  • Author
    Posts
    • #1639
      Anonymous

        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?

      • #9008
        Anonymous

          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.)

        • #9012
          Anonymous

            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)

          • #9013
            Anonymous

              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

            • #9050
              Anonymous

                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:Python25Libidlelib on my system PATH, but still nothing. What am I doing wrong now?

              • #9061
                Anonymous

                  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.

                • #9137
                  Anonymous

                    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:UsersMichałDesktopscorefxn_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?

                  • #9140
                    Anonymous

                      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

                    • #9143
                      Anonymous

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

                      • #9014
                        Anonymous

                          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.)

                        • #9052
                          Anonymous

                            What operating system are you actually using? “/usr/bin/idle” suggests that it’s Linux, but “C:Python25Libidlelib” 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.

                          • #9063
                            Anonymous

                              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

                            • #9064
                              Anonymous

                                Additional note: You could possibly change the for line to


                                for scoretype in scorefxn.get_nonzero_weighted_scoretypes():

                              • #9141
                                Anonymous

                                  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:UsersMichałDesktopEK_pr_inz_allPyRosettamy.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?

                                • #9142
                                  Anonymous

                                    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?

                                Viewing 8 reply threads
                                • You must be logged in to reply to this topic.