Jump

From PyMOLWiki
Revision as of 00:06, 25 May 2010 by Slaw (talk | contribs) (Created page with '===Description=== In the case of movies or simulation trajectories, it is often useful to quickly jump between different frames but not necessarily in any order. This script al…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

In the case of movies or simulation trajectories, it is often useful to quickly jump between different frames but not necessarily in any order. This script allows the user to specify a list of frames and flipping through the set of frames is controlled by a user-defined keystroke (limited to those available through the Set Key command).

Note: This script also requires the Check Key script!


Usage

load the script using the run command

jump [frame1 [,...frameN [,sleep=0.1,[key='pgdn']]]]

Example

jump 1, 10, 100

#This causes the movie to jump from frame 1 to frame 10 and finally to frame 100 each time the 'pgdn' key is pressed
#Note that there is no limit to the number of frames that can be specified

jump 1, 10, 100, 1000, key='F1'
#This sets the hotkey to F1.  When pressed, it will jump through the frames 1, 10, 100, 1000 respectively

jump 1, 10, 100, sleep=0.01
#This does the same thing as the first example except that the pause between frames is 10x faster
#One could consider the "sleep" option to be similar to the frame rate

PyMOL API

from pymol import cmd
import time

def jump (*args, **kwargs):
    
    #Author Sean Law
    #Michigan State University
    #slaw_(at)_msu_dot_edu

    keystroke='pgdn'
    
    for key in kwargs:
        if (key == "key"):
            keystroke=kwargs["key"]
            keystroke=check_key(keystroke)
            if (keystroke == None):
                return
        else:
            continue

    cmd.set_key(keystroke, jumpit, args, kwargs)

    return

cmd.extend("jump", jump)

def jumpit (*args, **kwargs):

    x=1
    sleep=0.1

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

    args=list(args)
    
    for j in range (len(args)):
        cmd.frame(int(args[j]))
        cmd.refresh()
        time.sleep(sleep)

    return
cmd.extend("jumpit", jumpit)


See Also

Check Key