Hi All,

I have written a quick little script to jump through various frames from an MD simulation loaded into PyMOL:

###################################################
from pymol import cmd
import time

def jump (*args, **kwargs):

    #Example: jump 1, 10, 20
    #This will jump from frame 1 to frame 10 to frame 20
    #for a total of 10 times (default) while pausing in
    #between frames for 0.1 seconds (default)

    #Example: jump 1, 50, 100, 1000, x=5, sleep=0.01
    #This will jump from frame 1 to frame 10 to frame 100 to frame 1000
    #for a total of 5 times while pausing in between frames for 0.01 seconds

    #Notice that I am using *args in order to allow a variable number of
    #frames to be specified

    x=10
    sleep=0.1

    for key in kwargs:
        if (key == "x"):
            x=kwargs["x"]
            x=int(x)
        elif (key == "sleep"):
            sleep=kwargs["sleep"]
            sleep=float(sleep)
        else:
            continue

    args=list(args)

    for i in range (x):
        #This loop runs through all of the selected frames "x" times
        #Need some way to recognize input from user to exit loop/return
        for j in range (len(args)):
            #This loop runs through each of the selected frames one time
            #Need some way to recognize input from user to exit loop/return
            cmd.frame(int(args[j]))
            #This skips to the specified frame
            cmd.refresh()
            #This refreshes the display
            time.sleep(sleep)
            #This "pauses" the loop for a period of time, acts like frame rate

    return

cmd.extend("jump", jump)

#################################################


I have two questions:

1) Is there some way that I can tell PyMOL to exit either of the "for loops" by pressing the keyboard/stdin?   The purpose of jumping through various frames is to look for conformational changes in the structure but with the current script, it is necessary to run through both "for loops" before it stops.  However, I would like a way to stop the script at any time by simply pressing a user defined button on the keyboard.  I've marked the places above where the script would be required to look for user input and move on if no input is provided.  Alternatively, I could have the user hold down a keyboard key in order to run through the loops and once the key is released have it automatically exit/return.  Either would be fine.  FYI, I did try to play with "raw_input" command but it didn't seem to work/help.

2) In this case, since I'm using "*args" and "**kwargs", how do I specify the usage?  Right now, when I do "jump ?" in PyMOL, it just spits out "Usage: jump" without any of the usual usage information.  Is there some explicit way of telling PyMOL exactly what usage information to print out??



Any suggestions would be greatly appreciated!

Thanks.

Sean


MSN Dating: Find someone special. Start now. Start now!