<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joelbard</id>
	<title>PyMOL Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joelbard"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php/Special:Contributions/Joelbard"/>
	<updated>2026-09-06T15:48:27Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10254</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10254"/>
		<updated>2007-01-08T04:05:15Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* slerpy.py */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see [[#Command Reference|Command Reference]] for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when you're done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
&lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
&lt;br /&gt;
===Live pymol presentations during a talk===&lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
Of course showing your movie from within pymol allows you to show movies in stereo if you've got a presentation system that allows this.  If you pass out stereo glasses first it's guaranteed that everyone will remember your talk...&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            #mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10253</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10253"/>
		<updated>2007-01-02T03:14:43Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* slerpy.py */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see [[#Command Reference|Command Reference]] for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when you're done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
&lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
&lt;br /&gt;
===Live pymol presentations during a talk===&lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
Of course showing your movie from within pymol allows you to show movies in stereo if you've got a presentation system that allows this.  If you pass out stereo glasses first it's guaranteed that everyone will remember your talk...&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10252</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10252"/>
		<updated>2007-01-01T21:41:09Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Starting off right */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see [[#Command Reference|Command Reference]] for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when you're done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
&lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
&lt;br /&gt;
===Live pymol presentations during a talk===&lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
Of course showing your movie from within pymol allows you to show movies in stereo if you've got a presentation system that allows this.  If you pass out stereo glasses first it's guaranteed that everyone will remember your talk...&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10251</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10251"/>
		<updated>2007-01-01T21:37:22Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Converting scenes to movies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see [[#Command Reference|Command Reference]] for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when you're done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
&lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10250</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10250"/>
		<updated>2007-01-01T21:35:10Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see [[#Command Reference|Command Reference]] for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Main_Page&amp;diff=4569</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Main_Page&amp;diff=4569"/>
		<updated>2007-01-01T21:32:58Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* [[TOPTOC|'''Table of Contents''']]&lt;br /&gt;
&lt;br /&gt;
* [[Special:Allpages|Alphabetized Index of all pages]]&lt;br /&gt;
&lt;br /&gt;
* [[Improvements|Discussion of PyMolWiki Improvements]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PyMol Wiki Home ==&lt;br /&gt;
You have reached the home of the PyMolWiki, a user-driven web-oriented CMS.&lt;br /&gt;
&lt;br /&gt;
We provide&lt;br /&gt;
* updates on [http://pymol.sf.net PyMol]&lt;br /&gt;
* a stable user-oriented documentation base&lt;br /&gt;
* a thorough treatment of the PyMol program&lt;br /&gt;
* feature-rich scripts for general PyMol use&lt;br /&gt;
&lt;br /&gt;
== New Users ==&lt;br /&gt;
The PyMol Wiki actively seeks new users and contributors!  However, due to massive amount of spamming, we've changed the registration process, until further notice.  '''If you would like access,''' you will need to be verified by a system administrator/sysop.  To do so, email Jason dot Vertrees at gmail dot com (and tell me why you use PyMol).  Also, be sure to include your '''desired user name''', '''real name''', and '''email address'''.  Once we figure out a way to automatically prevent spamming, we'll return to the normal method of registration.&lt;br /&gt;
&lt;br /&gt;
==News==&lt;br /&gt;
===PyMol===&lt;br /&gt;
* [[Slerpy]], a set of pymol command extensions to simplify complex movie making is now available.&lt;br /&gt;
* Updated the [[Kabsch#The_New_Code|Kabsch]] code with a more elegant solution; fixed a small rotation bug.&lt;br /&gt;
* Pymol 0.99 is out! Get it [http://delsci.com/rel/099/ here].&lt;br /&gt;
* A new version of APBS plugin is available on [http://www-personal.umich.edu/~mlerner/PyMOL/ Michael Lerner's Page].&lt;br /&gt;
* New [http://www.delsci.com/beta Beta Releases] available.&lt;br /&gt;
* New cool [[ray]] tracing features added!&lt;br /&gt;
&lt;br /&gt;
===Wiki===&lt;br /&gt;
* [[Settings]] now contains documentation on:&lt;br /&gt;
               - helix roundness&lt;br /&gt;
               - ribbon sampling&lt;br /&gt;
               - cartoon sampling&lt;br /&gt;
               - cartoon highlight coloring&lt;br /&gt;
               - cartoon color blending vs discrete colors&lt;br /&gt;
               - and more!  now 48 documented (with examples); just 470 to go....&lt;br /&gt;
&lt;br /&gt;
* [[SURFNET]] information on reading surfaces from other programs added.&lt;br /&gt;
* Two new [[:Category:Plugins|Plugins]] have been added, [[NsSNP Loader]] and [[Proxy Config]].&lt;br /&gt;
* Added a page that lists all [[Settings|PyMol settings]].  We need to start documenting these.&lt;br /&gt;
* [[MAC_Install]] page has been developed. It describes pymol and apbs issues specific to Mac OS X.&lt;br /&gt;
* [[APBS]] page has been established.   &lt;br /&gt;
* [[APBS]] How to set this up on OS X and on Linux has been started but needs contributions.&lt;br /&gt;
&lt;br /&gt;
===News Archive===&lt;br /&gt;
*See our [[Older_News]].&lt;br /&gt;
&lt;br /&gt;
== Links of Interest ==&lt;br /&gt;
* [[TOPTOC|Top Level Table of Contents]]&lt;br /&gt;
* [[:Category:FAQ|Frequently Asked Questions]] -- new!&lt;br /&gt;
* [[PyMolWiki:Community_Portal| How to get involved!]] -- read me if you want to add something&lt;br /&gt;
* [[:Category:Script Library| Script Library]] -- add one! (rTools info!)&lt;br /&gt;
* [[:Category:Commands|PyMol Commands]] (&amp;gt;130 documented!)&lt;br /&gt;
* [[Settings|PyMol Settings]]  (6 newly documented; only 470 to go...)&lt;br /&gt;
* [[:Special:Allpages| All Pages]]&lt;br /&gt;
* [[:Category:Plugins|Plugins]]&lt;br /&gt;
* [[:Special:Categories| See All Categories]]&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10249</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10249"/>
		<updated>2006-12-31T17:02:25Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* slerpy.py */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
#obsolete&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
#obsolete in favor of readKeyViewFile&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
#deprecated in favor of key files&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10248</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10248"/>
		<updated>2006-12-31T16:55:47Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Tips and Tricks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
===Morphing and multi-state models===&lt;br /&gt;
&lt;br /&gt;
Morphs and multi-conformation models are represented in pymol as single objects with multiple states.  Cycling through the states as an animation is very straightforward in pymol.  Slerpy allows you to include this animation over the states of an object as a transition between slerpy views within the context of larger movie.  This is done using the ''smorph'' command (see [[#Command Reference|Command Reference]]).  ''smorph'' allows you to specify the starting and ending pymol state numbers to use during the transition from the current to the next view.  It will often be appropriate to have the movie continue after the morph using the final state of the morphing model, that is, the conformation to which you morphed.  Since the default for a typical slerpy view is to show the first state of an object, you'll probably need to have available, in addition to your multi-state model, a single-state object containing the final conformation.  You can then hide the multistate object and show the single-state final conformation as an action associated with the final view of your morphing sequence.&lt;br /&gt;
&lt;br /&gt;
To generate morphs you can use the [[http://www.delanoscientific.com/rigimol.html rigimol]] program provided by Warren as part of the incentive pymol package for subscribers or use [[http://alpha2.bmc.uu.se/usf/mol_morph.html lsqman]] from Gerard Kleywegt.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10247</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10247"/>
		<updated>2006-12-31T16:38:16Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Tips and Tricks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
===Converting scenes to movies===&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
===Starting off right===&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
===Pausing on a view===&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10246</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10246"/>
		<updated>2006-12-31T06:44:30Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Command Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand be sure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10245</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10245"/>
		<updated>2006-12-31T06:37:12Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Command Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10244</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10244"/>
		<updated>2006-12-31T06:06:48Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[:Category:Software_Movies|Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10243</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10243"/>
		<updated>2006-12-31T06:05:06Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).  Also, see the useful article [[Software_Movies]].&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10242</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10242"/>
		<updated>2006-12-31T05:42:10Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
==Why is it called slerpy?==&lt;br /&gt;
&lt;br /&gt;
slerp is an acronym of sorts for spherical linear interpolation.  The transition between two views approximates spherical linear interpolation of the their camera positions using quaternions.  See the Wikipedia [[http://en.wikipedia.org/wiki/Slerp article]] on slerps.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10241</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10241"/>
		<updated>2006-12-31T05:34:32Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===slerpy.py===&lt;br /&gt;
&lt;br /&gt;
:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===movs.py===&lt;br /&gt;
&lt;br /&gt;
:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10240</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10240"/>
		<updated>2006-12-31T05:32:47Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation|Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10239</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10239"/>
		<updated>2006-12-31T05:31:34Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10238</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10238"/>
		<updated>2006-12-31T05:30:40Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10237</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10237"/>
		<updated>2006-12-31T05:30:22Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
&lt;br /&gt;
If you haven't installed slerpy yet see [[#Installation]]&lt;br /&gt;
&lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10236</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10236"/>
		<updated>2006-12-31T05:26:17Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10235</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10235"/>
		<updated>2006-12-31T05:24:34Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
If you don't have write priviledges in the pymol installation directories you can just copy these files to the working directory from which pymol will be run.  &lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10234</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10234"/>
		<updated>2006-12-31T05:23:07Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
To install, copy (by pasting into a text editor) the following two python code segments to files named slerpy.py and movs.py, respectively.    Place these files in the pymol/modules/pymol/ directory created by the pymol installation.  &lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10233</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10233"/>
		<updated>2006-12-31T05:17:14Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
To install, copy the following two python code segments to files named slerpy.py and movs.py, respectively.  Place these files in the pymol/modules/pymol/ directory created by the pymol installation.&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
##################################################################################&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10232</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10232"/>
		<updated>2006-12-31T05:13:26Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10231</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10231"/>
		<updated>2006-12-31T05:11:55Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
################################################################################&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
#&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
#################################################################################&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*;movs.py:Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd,stored&lt;br /&gt;
from math import *&lt;br /&gt;
from string import split&lt;br /&gt;
&lt;br /&gt;
def rmat2quat( M ):&lt;br /&gt;
    #M is a list of 9 values being the elements of the rotation matrix in row order&lt;br /&gt;
    T = M[0] + M[4] + M[8] + 1&lt;br /&gt;
    print &amp;quot;Trace &amp;quot;,T&lt;br /&gt;
    if T&amp;gt;0:&lt;br /&gt;
        S = 0.5 / sqrt(T)&lt;br /&gt;
        W = 0.25/S&lt;br /&gt;
        X = (M[7] - M[5])*S&lt;br /&gt;
        Y = (M[2] - M[6])*S&lt;br /&gt;
        Z = (M[3] - M[1])*S&lt;br /&gt;
    else:&lt;br /&gt;
        if( M[0] &amp;gt; M[4] and M[0] &amp;gt; M[8] ):&lt;br /&gt;
            S = sqrt( 1.0 + M[0] - M[4] - M[8]) * 2&lt;br /&gt;
            X = 0.25 * S&lt;br /&gt;
            Y = (M[1] + M[3])/S&lt;br /&gt;
            Z = (M[2] + M[6])/S&lt;br /&gt;
            W = (M[5] - M[7])/S&lt;br /&gt;
        elif M[4] &amp;gt; M[8]:&lt;br /&gt;
            S = sqrt( 1.0 + M[4] - M[0] - M[8] ) * 2&lt;br /&gt;
            X = (M[1] + M[3])/S&lt;br /&gt;
            Y = 0.25 * S&lt;br /&gt;
            Z = (M[5] + M[7])/S&lt;br /&gt;
            W = (M[2] - M[6])/S&lt;br /&gt;
        else:&lt;br /&gt;
            S = sqrt( 1.0 + M[8] - M[0] - M[4]) * 2&lt;br /&gt;
            X = (M[2] + M[6])/S&lt;br /&gt;
            Y = (M[5] + M[7])/S&lt;br /&gt;
            Z = 0.25 * S&lt;br /&gt;
            W = (M[1] - M[3])/S&lt;br /&gt;
    return [X,Y,Z,W]&lt;br /&gt;
&lt;br /&gt;
def quat2rmat( Q ):&lt;br /&gt;
    #Q is a list of 4 values being the quaternion X Y Z W&lt;br /&gt;
    X=Q[0]&lt;br /&gt;
    Y=Q[1]&lt;br /&gt;
    Z=Q[2]&lt;br /&gt;
    W=Q[3]&lt;br /&gt;
    xx = X*X&lt;br /&gt;
    xy = X*Y&lt;br /&gt;
    xz = X*Z&lt;br /&gt;
    xw = X*W&lt;br /&gt;
    yy = Y*Y&lt;br /&gt;
    yz = Y*Z&lt;br /&gt;
    yw = Y*W&lt;br /&gt;
    zz = Z*Z&lt;br /&gt;
    zw = Z*W&lt;br /&gt;
&lt;br /&gt;
    M= [1.0]*9&lt;br /&gt;
    M[0] = 1 - 2 * ( yy + zz )&lt;br /&gt;
    M[1] = 2 * ( xy - zw )&lt;br /&gt;
    M[2] = 2 * ( xz + yw )&lt;br /&gt;
    M[3] = 2 * ( xy + zw )&lt;br /&gt;
    M[4] = 1 - 2 * ( xx + zz )&lt;br /&gt;
    M[5] = 2 * ( yz - xw )&lt;br /&gt;
    M[6] = 2 * ( xz - yw )&lt;br /&gt;
    M[7] = 2 * ( yz + xw )&lt;br /&gt;
    M[8] = 1 - 2 * ( xx + yy )&lt;br /&gt;
    return M&lt;br /&gt;
&lt;br /&gt;
def quatconj( Q ):&lt;br /&gt;
    return [-Q[0],-Q[1],-Q[2],Q[3]]&lt;br /&gt;
&lt;br /&gt;
def quatmag( Q ):&lt;br /&gt;
    s = 0.0&lt;br /&gt;
    QC = quatconj(Q)&lt;br /&gt;
    for x in range(0,4):&lt;br /&gt;
        s += Q[x]*Q[x]&lt;br /&gt;
    print s&lt;br /&gt;
    return sqrt(s)&lt;br /&gt;
&lt;br /&gt;
def quatnorm( Q ):&lt;br /&gt;
    m = quatmag( Q )&lt;br /&gt;
    return [q/m for q in Q]&lt;br /&gt;
&lt;br /&gt;
def quatdotprod( q1, q2 ):&lt;br /&gt;
    dp = 0&lt;br /&gt;
    for i in range(0,4):&lt;br /&gt;
        dp += q1[i]*q2[i]&lt;br /&gt;
    return dp&lt;br /&gt;
&lt;br /&gt;
def vectnorm( V ):&lt;br /&gt;
    mag = 0.0&lt;br /&gt;
    for x in V:&lt;br /&gt;
        mag += x*x&lt;br /&gt;
    mag = sqrt(mag)&lt;br /&gt;
    return [x/mag for x in V]&lt;br /&gt;
&lt;br /&gt;
def quat2axisangle( Q ):&lt;br /&gt;
    #returns list where 0..2 are rot axis and 3 is angle&lt;br /&gt;
    qn = quatnorm( Q )&lt;br /&gt;
    cos_a = Q[3]&lt;br /&gt;
    angle = acos( cos_a ) * 2&lt;br /&gt;
    sin_a = sqrt( 1.0 - cos_a * cos_a )&lt;br /&gt;
    if( fabs( sin_a ) &amp;lt; 0.000005 ):&lt;br /&gt;
        sin_a = 1&lt;br /&gt;
    ax_an = [ q/sin_a for q in Q[0:3] ]&lt;br /&gt;
    ax_an.append( angle )&lt;br /&gt;
    return ax_an&lt;br /&gt;
&lt;br /&gt;
def axisangle2quat( ax_an ):&lt;br /&gt;
    #ax_an is a list with axis coordinates followed by rotation angle&lt;br /&gt;
    axn = vectnorm( ax_an[:3] )&lt;br /&gt;
    angle = ax_an[3]&lt;br /&gt;
    sin_a = sin( angle / 2 )&lt;br /&gt;
    cos_a = cos( angle / 2 )&lt;br /&gt;
    Q = [ x * sin_a for x in axn ]&lt;br /&gt;
    Q.append( cos_a )&lt;br /&gt;
    return Q&lt;br /&gt;
    &lt;br /&gt;
def rmat2axisangle( M ):&lt;br /&gt;
    q = rmat2quat( M )&lt;br /&gt;
    return quat2axisangle( q )&lt;br /&gt;
&lt;br /&gt;
def axisangle2rmat( a ):&lt;br /&gt;
    q = axisangle2quat( a )&lt;br /&gt;
    return quat2rmat( q )&lt;br /&gt;
&lt;br /&gt;
def animate_transition( start_view, end_view, nframes, first_frame, settings = [] ):&lt;br /&gt;
    #print &amp;quot;Views&amp;quot;&lt;br /&gt;
    #print start_view,'\n',end_view&lt;br /&gt;
&lt;br /&gt;
    cview = start_view[:]&lt;br /&gt;
    cmd.set_view( start_view )&lt;br /&gt;
&lt;br /&gt;
    #get initial and final quaternions for interpolation&lt;br /&gt;
    #print start_view[0:9]&lt;br /&gt;
    #get quaternions&lt;br /&gt;
    qstart = rmat2quat( start_view[0:9] )&lt;br /&gt;
    qend = rmat2quat( end_view[0:9] )&lt;br /&gt;
    &lt;br /&gt;
    #test for long way vs. short way&lt;br /&gt;
    if( quatdotprod( qstart,qend ) &amp;lt; 0 ):&lt;br /&gt;
        qstart = [-q for q in qstart]&lt;br /&gt;
&lt;br /&gt;
    axan_start = quat2axisangle( qstart )&lt;br /&gt;
    axan_end = quat2axisangle( qend )&lt;br /&gt;
        &lt;br /&gt;
    axan_cur = axan_start[:]&lt;br /&gt;
    frame_start = first_frame&lt;br /&gt;
    frame_end = frame_start + nframes&lt;br /&gt;
    doFade = 0&lt;br /&gt;
    doSetting = 0&lt;br /&gt;
    if len( settings ) == 4:&lt;br /&gt;
        settingName, selection, startVal, endVal = settings&lt;br /&gt;
        settingStep = (endVal-startVal)/float(nframes)&lt;br /&gt;
        print &amp;quot;Setting step &amp;quot;, settingStep&lt;br /&gt;
        doSetting = 1&lt;br /&gt;
    elif len( settings ) == 3:&lt;br /&gt;
        startVisSelection, endVisSelection, sticksOnly = settings&lt;br /&gt;
        settingStep = 1.0/float(nframes)&lt;br /&gt;
        doFade = 1&lt;br /&gt;
    for f in range( frame_start , frame_end):&lt;br /&gt;
        #get rotmat&lt;br /&gt;
        #using angle axis&lt;br /&gt;
&lt;br /&gt;
        for i in range(0,4):&lt;br /&gt;
            axan_cur[i] = axan_cur[i] + (axan_end[i]-axan_start[i])/nframes&lt;br /&gt;
        newmat = axisangle2rmat( axan_cur )&lt;br /&gt;
        #print cview&lt;br /&gt;
        for i in range(0,9):&lt;br /&gt;
            cview[i] = newmat[i]&lt;br /&gt;
&lt;br /&gt;
        mdo_cmd = &amp;quot;set_view ([&amp;quot;&lt;br /&gt;
        for i in range(0,18):&lt;br /&gt;
            if( i&amp;gt;8 ):&lt;br /&gt;
                cview[i] = cview[i]+(end_view[i]-start_view[i])/nframes&lt;br /&gt;
            mdo_cmd += &amp;quot;%12.7f,&amp;quot;% cview[i]&lt;br /&gt;
        mdo_cmd = mdo_cmd[:-1]+&amp;quot;])&amp;quot;&lt;br /&gt;
        if doSetting:       &lt;br /&gt;
            val = float(f-frame_start)*settingStep + startVal &lt;br /&gt;
            print val;&lt;br /&gt;
            mdo_cmd += &amp;quot;; set %s, %f, %s&amp;quot; % (settingName, val, selection)&lt;br /&gt;
            print mdo_cmd;&lt;br /&gt;
        #print &amp;quot;mdo &amp;quot;, mdo_cmd&lt;br /&gt;
        if doFade:&lt;br /&gt;
            val = float(f-frame_start)*settingStep&lt;br /&gt;
            otherVal = 1.0 - val&lt;br /&gt;
            mdo_cmd += &amp;quot;; set stick_transparency, %f, %s; set stick_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
            if not sticksOnly:&lt;br /&gt;
                #comment out surface transparency interpolation due to problem with transparent sticks in front of &lt;br /&gt;
                #transparent surfaces (get black holes)&lt;br /&gt;
               # mdo_cmd += &amp;quot;; set transparency, %f, %s; set transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
                mdo_cmd += &amp;quot;; set cartoon_transparency, %f, %s; set cartoon_transparency, %f, %s&amp;quot; % ( val, startVisSelection, otherVal, endVisSelection )&lt;br /&gt;
        cmd.mdo(f,mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;pymol&amp;quot;:&lt;br /&gt;
#read the views&lt;br /&gt;
&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( 'viewfile.txt' )&lt;br /&gt;
    while 1:&lt;br /&gt;
        line = viewfile.readline()&lt;br /&gt;
        if not line:&lt;br /&gt;
            break&lt;br /&gt;
        vals = line.split()&lt;br /&gt;
        view = []&lt;br /&gt;
        for v in vals:&lt;br /&gt;
            view.append( float(v) )&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
&lt;br /&gt;
    #now loop through the views adding interpolated frames to the movie&lt;br /&gt;
&lt;br /&gt;
    nframes = 50&lt;br /&gt;
    full_length = nframes * ( len(views)-1 )&lt;br /&gt;
    print &amp;quot;full_length %i&amp;quot; % full_length&lt;br /&gt;
    cmd.mset(&amp;quot;1 x%i&amp;quot; % full_length)&lt;br /&gt;
    start_view = views[0]&lt;br /&gt;
    first_frame = 0&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view&lt;br /&gt;
        animate_transition( start_view, end_view, nframes, first_frame )&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
        first_frame += nframes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10230</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10230"/>
		<updated>2006-12-31T05:09:05Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#slerpy.py - Command definition routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10229</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10229"/>
		<updated>2006-12-31T05:08:36Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#slerpy.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10228</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10228"/>
		<updated>2006-12-31T05:07:52Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*;slerpy.py:The command definitions for slerpy&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
        views.append( view )&lt;br /&gt;
    vfile.close()&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
    frames = []&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
    ffile.close()&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
    actions = {}&lt;br /&gt;
    try:&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
        return actions&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
        try:&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    afile.close()&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
    models = {}&lt;br /&gt;
    try:&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
        return models&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    mfile.close()&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
    settings = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
        return settings&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scommas = sstring[4:]&lt;br /&gt;
            settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
            setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return settings&lt;br /&gt;
            &lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    try:&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
        return scenes&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
        try:&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
        except:&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
    sfile.close()&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global scenes&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
    &lt;br /&gt;
def print_view( view ):&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
    cur_index = n&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
    #set frames to default&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    &lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
    &lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
        else:&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
    return tempDict&lt;br /&gt;
    &lt;br /&gt;
def delete_current():&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
    #show the previous view&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global scenes&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global frames&lt;br /&gt;
    global fades&lt;br /&gt;
    &lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
        &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
    global settings&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global views&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global cur_view&lt;br /&gt;
    global scenes&lt;br /&gt;
    global scene_counter&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    cur_index += 1&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
    i = 1&lt;br /&gt;
    found = 1&lt;br /&gt;
    while found == 1:&lt;br /&gt;
        found = 0&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
                found = 1&lt;br /&gt;
                break&lt;br /&gt;
        if found == 1:&lt;br /&gt;
            i += 1&lt;br /&gt;
        else:&lt;br /&gt;
            break&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
        &lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
    &lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
    &lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
    for view in views:&lt;br /&gt;
        for v in view:&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
    &lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
        settingName, selection, startVal, endVal = setting&lt;br /&gt;
        settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
        &lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
 &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
    i=0&lt;br /&gt;
    for view in views:&lt;br /&gt;
        keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
        for v in view:&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
        keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
        if scenes.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
        if fades.has_key( i ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))            &lt;br /&gt;
        i += 1&lt;br /&gt;
        keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global scenes&lt;br /&gt;
    global actions&lt;br /&gt;
    global settings&lt;br /&gt;
    global models&lt;br /&gt;
    global fades&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
    frames = []&lt;br /&gt;
    actions = {}&lt;br /&gt;
    scenes = {}&lt;br /&gt;
    models = {}&lt;br /&gt;
    settings = {}&lt;br /&gt;
    fades = {}&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
        if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
            viewindex = int( line[6:10] )&lt;br /&gt;
            vals = line[10:].split()&lt;br /&gt;
            view = [float(v) for v in vals]&lt;br /&gt;
            views.append( view )&lt;br /&gt;
        if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
            frames.append( int( line[8:] ) )&lt;br /&gt;
        if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
            actions[ viewindex ] = line[9:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
            scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
        if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
            models[ viewindex ] = line[8:-1]&lt;br /&gt;
        if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
            settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
        if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
            fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
    global frames&lt;br /&gt;
    global cur_index&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    global settings&lt;br /&gt;
    &lt;br /&gt;
    i=0&lt;br /&gt;
    f=0&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
        else:&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
        if models.has_key( i ):&lt;br /&gt;
            m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
        else:&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
        if settings.has_key( i ):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
        else:&lt;br /&gt;
            s = &amp;quot;&amp;quot;&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
    global actions&lt;br /&gt;
    global cur_index&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
    global actions&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global settings&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global fades&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
    global frames&lt;br /&gt;
    global views&lt;br /&gt;
    global cur_index&lt;br /&gt;
    global actions&lt;br /&gt;
    global models&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
    else:&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    i = start_index&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
        &lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
            #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
            #cmd.do( actions[i] )&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
            first_action += action&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
            #cmd.do( action )&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
    global views&lt;br /&gt;
    global frames&lt;br /&gt;
    global models&lt;br /&gt;
    &lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
    ftot = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
        if models.has_key(i):&lt;br /&gt;
                            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
    i = 0&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
        elif fades.has_key(i):&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
        else:&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
        #add an action&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
        i += 1&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
#for v in views:&lt;br /&gt;
 #   print v&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
views = []&lt;br /&gt;
frames = []&lt;br /&gt;
models = {}&lt;br /&gt;
actions = {}&lt;br /&gt;
scenes = {}&lt;br /&gt;
settings = {}&lt;br /&gt;
fades = {}&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
cur_index = -1&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10227</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10227"/>
		<updated>2006-12-31T05:03:33Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
        views.append( view )&lt;br /&gt;
&lt;br /&gt;
    vfile.close()&lt;br /&gt;
&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
&lt;br /&gt;
    ffile.close()&lt;br /&gt;
&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return actions&lt;br /&gt;
&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
&lt;br /&gt;
	except:&lt;br /&gt;
&lt;br /&gt;
	    print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    afile.close()&lt;br /&gt;
&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return models&lt;br /&gt;
&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    mfile.close()&lt;br /&gt;
&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return settings&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
	    sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
	    scommas = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
&lt;br /&gt;
	    setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return settings&lt;br /&gt;
&lt;br /&gt;
	    &lt;br /&gt;
&lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return scenes&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def print_view( view ):&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index = n&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    #set frames to default&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def delete_current():&lt;br /&gt;
&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
&lt;br /&gt;
    #show the previous view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
&lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
&lt;br /&gt;
    i = 1&lt;br /&gt;
&lt;br /&gt;
    found = 1&lt;br /&gt;
&lt;br /&gt;
    while found == 1:&lt;br /&gt;
&lt;br /&gt;
        found = 0&lt;br /&gt;
&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
&lt;br /&gt;
                found = 1&lt;br /&gt;
&lt;br /&gt;
                break&lt;br /&gt;
&lt;br /&gt;
        if found == 1:&lt;br /&gt;
&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            break&lt;br /&gt;
&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
&lt;br /&gt;
	keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
	settingName, selection, startVal, endVal = setting&lt;br /&gt;
&lt;br /&gt;
	settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
&lt;br /&gt;
	if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
 	    keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
&lt;br /&gt;
	if scenes.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
	if fades.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))	    &lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    fades = {}&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    viewindex = int( line[6:10] )&lt;br /&gt;
&lt;br /&gt;
	    vals = line[10:].split()&lt;br /&gt;
&lt;br /&gt;
	    view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
	    views.append( view )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    frames.append( int( line[8:] ) )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    actions[ viewindex ] = line[9:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    models[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
	    fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    f=0&lt;br /&gt;
&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
&lt;br /&gt;
    else:&lt;br /&gt;
&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    i = start_index&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	    print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
		            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
&lt;br /&gt;
#for v in views:&lt;br /&gt;
&lt;br /&gt;
 #   print v&lt;br /&gt;
&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
views = []&lt;br /&gt;
&lt;br /&gt;
frames = []&lt;br /&gt;
&lt;br /&gt;
models = {}&lt;br /&gt;
&lt;br /&gt;
actions = {}&lt;br /&gt;
&lt;br /&gt;
scenes = {}&lt;br /&gt;
&lt;br /&gt;
settings = {}&lt;br /&gt;
&lt;br /&gt;
fades = {}&lt;br /&gt;
&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
cur_index = -1&lt;br /&gt;
&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10226</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10226"/>
		<updated>2006-12-31T05:02:51Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
        views.append( view )&lt;br /&gt;
&lt;br /&gt;
    vfile.close()&lt;br /&gt;
&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
&lt;br /&gt;
    ffile.close()&lt;br /&gt;
&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return actions&lt;br /&gt;
&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
&lt;br /&gt;
	except:&lt;br /&gt;
&lt;br /&gt;
	    print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    afile.close()&lt;br /&gt;
&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return models&lt;br /&gt;
&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    mfile.close()&lt;br /&gt;
&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return settings&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
	    sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
	    scommas = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
&lt;br /&gt;
	    setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return settings&lt;br /&gt;
&lt;br /&gt;
	    &lt;br /&gt;
&lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return scenes&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def print_view( view ):&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index = n&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    #set frames to default&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def delete_current():&lt;br /&gt;
&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
&lt;br /&gt;
    #show the previous view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
&lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
&lt;br /&gt;
    i = 1&lt;br /&gt;
&lt;br /&gt;
    found = 1&lt;br /&gt;
&lt;br /&gt;
    while found == 1:&lt;br /&gt;
&lt;br /&gt;
        found = 0&lt;br /&gt;
&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
&lt;br /&gt;
                found = 1&lt;br /&gt;
&lt;br /&gt;
                break&lt;br /&gt;
&lt;br /&gt;
        if found == 1:&lt;br /&gt;
&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            break&lt;br /&gt;
&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
&lt;br /&gt;
	keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
	settingName, selection, startVal, endVal = setting&lt;br /&gt;
&lt;br /&gt;
	settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
&lt;br /&gt;
	if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
 	    keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
&lt;br /&gt;
	if scenes.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
	if fades.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))	    &lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    fades = {}&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    viewindex = int( line[6:10] )&lt;br /&gt;
&lt;br /&gt;
	    vals = line[10:].split()&lt;br /&gt;
&lt;br /&gt;
	    view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
	    views.append( view )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    frames.append( int( line[8:] ) )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    actions[ viewindex ] = line[9:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    models[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
	    fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    f=0&lt;br /&gt;
&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
&lt;br /&gt;
    else:&lt;br /&gt;
&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    i = start_index&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	    print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
		            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
&lt;br /&gt;
#for v in views:&lt;br /&gt;
&lt;br /&gt;
 #   print v&lt;br /&gt;
&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
views = []&lt;br /&gt;
&lt;br /&gt;
frames = []&lt;br /&gt;
&lt;br /&gt;
models = {}&lt;br /&gt;
&lt;br /&gt;
actions = {}&lt;br /&gt;
&lt;br /&gt;
scenes = {}&lt;br /&gt;
&lt;br /&gt;
settings = {}&lt;br /&gt;
&lt;br /&gt;
fades = {}&lt;br /&gt;
&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
cur_index = -1&lt;br /&gt;
&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10225</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10225"/>
		<updated>2006-12-31T05:01:50Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#movs.py - Math and animation routines for slerpy&lt;br /&gt;
&lt;br /&gt;
#Copyright (C) 2006 Joel Bard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#This program is free software; you can redistribute it and/or&lt;br /&gt;
&lt;br /&gt;
#modify it under the terms of the GNU General Public License&lt;br /&gt;
&lt;br /&gt;
#as published by the Free Software Foundation; either version 2&lt;br /&gt;
&lt;br /&gt;
#of the License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#This program is distributed in the hope that it will be useful,&lt;br /&gt;
&lt;br /&gt;
#but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
&lt;br /&gt;
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
&lt;br /&gt;
#GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#You should have received a copy of the GNU General Public License&lt;br /&gt;
&lt;br /&gt;
#along with this program; if not, write to the Free Software&lt;br /&gt;
&lt;br /&gt;
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&lt;br /&gt;
&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
import movs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readViews( filename ):&lt;br /&gt;
&lt;br /&gt;
    vfile = open( filename, 'r')&lt;br /&gt;
&lt;br /&gt;
    views = [] #a list of views each of which is a list of 18 numbers&lt;br /&gt;
&lt;br /&gt;
    vstrings = vfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for vstring in vstrings:&lt;br /&gt;
&lt;br /&gt;
        vals = vstring.split()&lt;br /&gt;
&lt;br /&gt;
        view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
        views.append( view )&lt;br /&gt;
&lt;br /&gt;
    vfile.close()&lt;br /&gt;
&lt;br /&gt;
    return views&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readFrames( filename ):&lt;br /&gt;
&lt;br /&gt;
    ffile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    fstrings = ffile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for fstring in fstrings:&lt;br /&gt;
&lt;br /&gt;
        frames.append( int(fstring) )&lt;br /&gt;
&lt;br /&gt;
    ffile.close()&lt;br /&gt;
&lt;br /&gt;
    return frames&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readActions( filename ):&lt;br /&gt;
&lt;br /&gt;
    #actions are stored in file where&lt;br /&gt;
&lt;br /&gt;
    #for each line, the first 4 chars are the view index&lt;br /&gt;
&lt;br /&gt;
    #associated with the action and the rest of the&lt;br /&gt;
&lt;br /&gt;
    #line is the pymol command to be executed&lt;br /&gt;
&lt;br /&gt;
    #upon reading, a dictionary is returned&lt;br /&gt;
&lt;br /&gt;
    #with view indices as keys and actions as values&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        afile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No actions for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return actions&lt;br /&gt;
&lt;br /&gt;
    astrings = afile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for astring in astrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
            aindex = int(astring[:4])&lt;br /&gt;
&lt;br /&gt;
            action = astring[4:]&lt;br /&gt;
&lt;br /&gt;
            actions[ aindex ] = action[:-1]&lt;br /&gt;
&lt;br /&gt;
	except:&lt;br /&gt;
&lt;br /&gt;
	    print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    afile.close()&lt;br /&gt;
&lt;br /&gt;
    return actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readModels( filename ):&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        mfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No models for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return models&lt;br /&gt;
&lt;br /&gt;
    mstrings = mfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for mstring in mstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            mindex = int(mstring[:4])&lt;br /&gt;
&lt;br /&gt;
            model = mstring[4:]&lt;br /&gt;
&lt;br /&gt;
            models[ mindex ] = model[:-1]&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    mfile.close()&lt;br /&gt;
&lt;br /&gt;
    return models&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readSettings( filename ):&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No settings for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return settings&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
	try:&lt;br /&gt;
&lt;br /&gt;
	    sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
	    scommas = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = scommas.split(',')&lt;br /&gt;
&lt;br /&gt;
	    setting = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
            settings[sindex] = setting&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;unable to parse setting&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return settings&lt;br /&gt;
&lt;br /&gt;
	    &lt;br /&gt;
&lt;br /&gt;
def readScenes( filename ):&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
&lt;br /&gt;
        sfile = open( filename, 'r' )&lt;br /&gt;
&lt;br /&gt;
    except:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No scenes file for this project&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return scenes&lt;br /&gt;
&lt;br /&gt;
    sstrings = sfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    for sstring in sstrings:&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
&lt;br /&gt;
            sindex = int(sstring[:4])&lt;br /&gt;
&lt;br /&gt;
            scene = sstring[4:]&lt;br /&gt;
&lt;br /&gt;
            scenes[ sindex ] = scene[:-1]&lt;br /&gt;
&lt;br /&gt;
            scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;reading scene&amp;quot;, sstring, sindex, scene&lt;br /&gt;
&lt;br /&gt;
        except:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;empty line&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    sfile.close()&lt;br /&gt;
&lt;br /&gt;
    return scenes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def read_all( fileroot ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    views = readViews( fileroot+&amp;quot;.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    frames = readFrames( fileroot+&amp;quot;.frm&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    actions = readActions( fileroot+&amp;quot;.act&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    scenes = readScenes( fileroot+&amp;quot;.scn&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    models = readModels( fileroot+&amp;quot;.mod&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    settings = readSettings( fileroot+&amp;quot;.set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def print_view( view ):&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,6):&lt;br /&gt;
&lt;br /&gt;
        for j in range(0,3):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;%12.6f&amp;quot;% view[ 3*i+j ] ,&lt;br /&gt;
&lt;br /&gt;
        print&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_next():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == len( views )-1 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_prev():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    if( cur_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;No more views.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_cur():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[ cur_index ]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view(cur_view)&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def go_to_view( arg=0 ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    n = int( arg )&lt;br /&gt;
&lt;br /&gt;
    if n &amp;lt; 0 or n &amp;gt; len(views)-1:&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;Index out of range.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    cur_index = n&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[n]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Matrix: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Showing view number &amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_current():&lt;br /&gt;
&lt;br /&gt;
    #insert the current view into the list after the view&lt;br /&gt;
&lt;br /&gt;
    #in views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    #set frames to default&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with actions dictionary&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_view():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    cur_index = len(views)&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.append( [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.append( 50 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Appended view with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;The current view is&amp;quot;, cur_index&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def incKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt;= index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key + 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def decKeyAbove( dict, index ):&lt;br /&gt;
&lt;br /&gt;
    tempDict = {}&lt;br /&gt;
&lt;br /&gt;
    for key, val in dict.iteritems():&lt;br /&gt;
&lt;br /&gt;
        if key &amp;gt; index:&lt;br /&gt;
&lt;br /&gt;
            newkey = key - 1&lt;br /&gt;
&lt;br /&gt;
            tempDict[newkey] = val&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            tempDict[key] = val&lt;br /&gt;
&lt;br /&gt;
    return tempDict&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def delete_current():&lt;br /&gt;
&lt;br /&gt;
    #remove the current view from the list&lt;br /&gt;
&lt;br /&gt;
    #show the previous view&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    del views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    del frames[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if actions.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if scenes.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del scenes[cur_index]&lt;br /&gt;
&lt;br /&gt;
    if settings.has_key( cur_index ):&lt;br /&gt;
&lt;br /&gt;
        del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = decKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = decKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = decKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = decKeyAbove( models, cur_index )                               &lt;br /&gt;
&lt;br /&gt;
    fades = decKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;View number&amp;quot;,cur_index,&amp;quot;deleted.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if cur_index &amp;gt; 0:&lt;br /&gt;
&lt;br /&gt;
        cur_index -= 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[cur_index]&lt;br /&gt;
&lt;br /&gt;
    cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Current view is number&amp;quot;,cur_index&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def delete_settings():&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del settings[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def replace_current():&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views[cur_index] = [cv for cv in cur_view]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def insert_scene():&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global cur_view&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    cur_index += 1&lt;br /&gt;
&lt;br /&gt;
    cur_view = cmd.get_view()&lt;br /&gt;
&lt;br /&gt;
    views.insert( cur_index, [cv for cv in cur_view] )&lt;br /&gt;
&lt;br /&gt;
    frames.insert( cur_index, 50 )&lt;br /&gt;
&lt;br /&gt;
    #TODO record scene with indexed name (global scene index?)&lt;br /&gt;
&lt;br /&gt;
    #Save the pse file on swrite&lt;br /&gt;
&lt;br /&gt;
    #We'll also need to maintain our own list of scenes as a dict&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #deal with dictionaries&lt;br /&gt;
&lt;br /&gt;
    actions = incKeyAbove( actions, cur_index )&lt;br /&gt;
&lt;br /&gt;
    scenes = incKeyAbove( scenes, cur_index )&lt;br /&gt;
&lt;br /&gt;
    settings = incKeyAbove( settings, cur_index )&lt;br /&gt;
&lt;br /&gt;
    models = incKeyAbove( models, cur_index )&lt;br /&gt;
&lt;br /&gt;
    fades = incKeyAbove( fades, cur_index )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #this stuff has to be done after the above&lt;br /&gt;
&lt;br /&gt;
    #find a free scene name&lt;br /&gt;
&lt;br /&gt;
    i = 1&lt;br /&gt;
&lt;br /&gt;
    found = 1&lt;br /&gt;
&lt;br /&gt;
    while found == 1:&lt;br /&gt;
&lt;br /&gt;
        found = 0&lt;br /&gt;
&lt;br /&gt;
        for sname in scenes.values():&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;|&amp;quot;+sname+&amp;quot;|&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if sname == &amp;quot;slerpy_&amp;quot;+str(i):&lt;br /&gt;
&lt;br /&gt;
                found = 1&lt;br /&gt;
&lt;br /&gt;
                break&lt;br /&gt;
&lt;br /&gt;
        if found == 1:&lt;br /&gt;
&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            break&lt;br /&gt;
&lt;br /&gt;
    newname = &amp;quot;slerpy_&amp;quot;+str(i)&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
    cmd.scene( newname, &amp;quot;store&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    scenes[ cur_index ] = newname&lt;br /&gt;
&lt;br /&gt;
    actions[ cur_index ] = &amp;quot;scene &amp;quot;+newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;New view:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Inserted view at with index&amp;quot;, cur_index, &amp;quot;and a 50 frame transition&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Added scene&amp;quot;,newname&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
def write_views( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    viewfile = open( filename+&amp;quot;.txt&amp;quot;, 'w')&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            viewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        viewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
    viewfile.close()&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    framefile = open( filename+&amp;quot;.frm&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for frame in frames:&lt;br /&gt;
&lt;br /&gt;
        framefile.write( str( frame )+'\n' )&lt;br /&gt;
&lt;br /&gt;
    framefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    actionfile = open( filename+&amp;quot;.act&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,action in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        actionfile.write( keystring.rjust(4)+action + '\n' )&lt;br /&gt;
&lt;br /&gt;
    actionfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    scenefile = open( filename+&amp;quot;.scn&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,scene in scenes.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        scenefile.write( keystring.rjust(4)+scene + '\n' )&lt;br /&gt;
&lt;br /&gt;
    scenefile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    modelfile = open( filename+&amp;quot;.mod&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,model in models.iteritems():&lt;br /&gt;
&lt;br /&gt;
        keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
        modelfile.write( keystring.rjust(4)+model + '\n' )&lt;br /&gt;
&lt;br /&gt;
    modelfile.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    settingsfile = open( filename+&amp;quot;.set&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    for key,setting in settings.iteritems():&lt;br /&gt;
&lt;br /&gt;
	keystring = str( key )&lt;br /&gt;
&lt;br /&gt;
	settingName, selection, startVal, endVal = setting&lt;br /&gt;
&lt;br /&gt;
	settingsfile.write( &amp;quot;%s%s,%s,%f,%f\n&amp;quot; % (keystring.rjust(4), settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
    settingsfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename+&amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files&amp;quot;, filename+&amp;quot;.txt,&amp;quot;,filename+&amp;quot;.frm,&amp;quot;,filename+&amp;quot;.pse, and&amp;quot;,filename+&amp;quot;.act&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def writeKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'w' )&lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    for view in views:&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;VIEW: %4d &amp;quot; % i )&lt;br /&gt;
&lt;br /&gt;
        for v in view:&lt;br /&gt;
&lt;br /&gt;
            keyviewfile.write( str(v) + &amp;quot; &amp;quot; )&lt;br /&gt;
&lt;br /&gt;
        keyviewfile.write('\n')&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write( &amp;quot;FRAMES: %d\n&amp;quot; % frames[i] )&lt;br /&gt;
&lt;br /&gt;
	if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
 	    keyviewfile.write( &amp;quot;ACTIONS: %s\n&amp;quot; % actions[i] )&lt;br /&gt;
&lt;br /&gt;
	if scenes.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SCENES: %s\n&amp;quot; % scenes[i] )&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;MODELS: %s\n&amp;quot; % models[i] )&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;SETTINGS: %s, %s, %f, %f\n&amp;quot; % (settingName, selection, startVal, endVal))&lt;br /&gt;
&lt;br /&gt;
	if fades.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    keyviewfile.write( &amp;quot;FADES: %s, %s, %d\n&amp;quot; % (startVisSelection, endVisSelection, sticksOnly))	    &lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
	keyviewfile.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    cmd.save( filename + &amp;quot;.pse&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
    print &amp;quot;Wrote files &amp;quot; , filename + &amp;quot;.key&amp;quot;, filename + &amp;quot;.pse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def readKeyViewFile( filename ):&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global scenes&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    global scene_counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    views = []&lt;br /&gt;
&lt;br /&gt;
    frames = []&lt;br /&gt;
&lt;br /&gt;
    actions = {}&lt;br /&gt;
&lt;br /&gt;
    scenes = {}&lt;br /&gt;
&lt;br /&gt;
    models = {}&lt;br /&gt;
&lt;br /&gt;
    settings = {}&lt;br /&gt;
&lt;br /&gt;
    fades = {}&lt;br /&gt;
&lt;br /&gt;
    scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
                                                                                                                  &lt;br /&gt;
&lt;br /&gt;
    keyviewfile = open( filename + &amp;quot;.key&amp;quot;, 'r' )&lt;br /&gt;
&lt;br /&gt;
    viewstrings = keyviewfile.readlines()&lt;br /&gt;
&lt;br /&gt;
    keyviewfile.close()&lt;br /&gt;
&lt;br /&gt;
    viewindex = 0&lt;br /&gt;
&lt;br /&gt;
    for line in viewstrings:&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;VIEW: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    viewindex = int( line[6:10] )&lt;br /&gt;
&lt;br /&gt;
	    vals = line[10:].split()&lt;br /&gt;
&lt;br /&gt;
	    view = [float(v) for v in vals]&lt;br /&gt;
&lt;br /&gt;
	    views.append( view )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;FRAMES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    frames.append( int( line[8:] ) )&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;ACTIONS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    actions[ viewindex ] = line[9:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SCENES: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    scenes[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	    scene_counter += 1&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;MODELS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    models[ viewindex ] = line[8:-1]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith(&amp;quot;SETTINGS: &amp;quot;):&lt;br /&gt;
&lt;br /&gt;
	    settingName,selection,startVal,endVal = line[10:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
            settings[ viewindex ] = [settingName,selection,float(startVal),float(endVal)]&lt;br /&gt;
&lt;br /&gt;
	if line.startswith( &amp;quot;FADES: &amp;quot; ):&lt;br /&gt;
&lt;br /&gt;
	    startVisSelection, endVisSelection, sticksOnly = line[7:-1].split(',')&lt;br /&gt;
&lt;br /&gt;
	    fades[ viewindex ] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
    cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
    cur_index = 0&lt;br /&gt;
&lt;br /&gt;
    show_cur()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def set_frames_current( arg=50 ):&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = int(arg)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_frames():&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    i=0&lt;br /&gt;
&lt;br /&gt;
    f=0&lt;br /&gt;
&lt;br /&gt;
    for view in views[:-1]:&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            a = actions[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            a = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if models.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
	    m = &amp;quot;States: &amp;quot; + models[i]&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            m = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key( i ):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;Settings: %s %s %f %f&amp;quot; % (settingName, selection, startVal, endVal)&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
	    s = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        print &amp;quot;View&amp;quot;,i,&amp;quot;to&amp;quot;,i+1,&amp;quot;Frames &amp;quot;,f,&amp;quot;to&amp;quot;,f+frames[i],a,m,s&lt;br /&gt;
&lt;br /&gt;
        f += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def add_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] = cmd[1:-1] #strip off quotes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def append_action_current( cmd ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    actions[cur_index] += &amp;quot;;&amp;quot; + cmd[1:-1]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def clear_action_current():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    del actions[cur_index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def list_actions():&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    for i,a in actions.iteritems():&lt;br /&gt;
&lt;br /&gt;
        print i,a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def morph_models( start_model, end_model ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    models[cur_index] = &amp;quot;%s -%s&amp;quot; % (start_model, end_model)&lt;br /&gt;
&lt;br /&gt;
    frames[cur_index] = abs(int(end_model) - int(start_model)) + 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def interpolate_settings( setting, selection, startval, endval ):&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global settings&lt;br /&gt;
&lt;br /&gt;
    settingEntry = [setting, selection, float(startval), float(endval)]&lt;br /&gt;
&lt;br /&gt;
    settings[cur_index] = settingEntry &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def crossfade( startVisSelection, endVisSelection, sticksOnly = 1 ):&lt;br /&gt;
&lt;br /&gt;
#cross fade the specified objects, vary stick transparency only if stickOnly=1&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global fades&lt;br /&gt;
&lt;br /&gt;
    fades[cur_index] = [startVisSelection, endVisSelection, int(sticksOnly) ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def setup_view( index ):&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, int(index)+1 ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
            action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
            cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def show_transition(start_index=0, end_index=0):&lt;br /&gt;
&lt;br /&gt;
    #show the transition from the current view to the next view&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global cur_index&lt;br /&gt;
&lt;br /&gt;
    global actions&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    if( start_index == 0 and end_index == 0 ):&lt;br /&gt;
&lt;br /&gt;
        if cur_index &amp;gt;= len(views)-1:&lt;br /&gt;
&lt;br /&gt;
            print &amp;quot;Current view is last in sequence.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        start_index=cur_index&lt;br /&gt;
&lt;br /&gt;
        end_index=cur_index+1&lt;br /&gt;
&lt;br /&gt;
    else:&lt;br /&gt;
&lt;br /&gt;
        start_index = int(start_index)&lt;br /&gt;
&lt;br /&gt;
        end_index = int(end_index)&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    i = start_index&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[start_index:end_index]:&lt;br /&gt;
&lt;br /&gt;
        #ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
#    cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
    start_frame = 1&lt;br /&gt;
&lt;br /&gt;
    #first do all actions that happen up to this point to make sure&lt;br /&gt;
&lt;br /&gt;
    #things look the way they should&lt;br /&gt;
&lt;br /&gt;
    first_action = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for i in range( 0, start_index ):&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            first_action += actions[i] + ';'&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from actions %d&amp;quot; % (actions[i],i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( actions[i] )&lt;br /&gt;
&lt;br /&gt;
        if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    settingName, selection, startVal, endVal = settings[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set %s, %f, %s;&amp;quot; % (settingName, endVal, selection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
	    #print &amp;quot;Executing %s from settings %d&amp;quot; % (action,i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
        if fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            startVisSelection, endVisSelection, sticksOnly = fades[i]&lt;br /&gt;
&lt;br /&gt;
	    action = &amp;quot;set stick_transparency, 0, %s; set stick_transparency, 1, %s;&amp;quot; % (endVisSelection, startVisSelection)&lt;br /&gt;
&lt;br /&gt;
	    first_action += action&lt;br /&gt;
&lt;br /&gt;
            #print &amp;quot;Executing %s from fades %d&amp;quot; % (action, i)&lt;br /&gt;
&lt;br /&gt;
	    #cmd.do( action )&lt;br /&gt;
&lt;br /&gt;
    for i in range( start_index, end_index ):&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( views[i], views[i+1], frames[i], start_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( views[i], views[i+1], frames[i], start_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if start_frame == 1:&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = first_action&lt;br /&gt;
&lt;br /&gt;
            if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
                mdo_cmd += actions[i]+&amp;quot;;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd += &amp;quot;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	    print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        elif actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]+&amp;quot;;set_view(&amp;quot;+str(views[i])+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(start_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
            #print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
        start_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
    cmd.mplay()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def make_all():&lt;br /&gt;
&lt;br /&gt;
    #make the whole movie&lt;br /&gt;
&lt;br /&gt;
    global views&lt;br /&gt;
&lt;br /&gt;
    global frames&lt;br /&gt;
&lt;br /&gt;
    global models&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    #first get total number of frames&lt;br /&gt;
&lt;br /&gt;
    ftot = 0&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    setcommand = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    for nframes in frames[:-1]:&lt;br /&gt;
&lt;br /&gt;
        ftot += nframes&lt;br /&gt;
&lt;br /&gt;
	if models.has_key(i):&lt;br /&gt;
&lt;br /&gt;
		            setcommand += &amp;quot; &amp;quot; + models[i] + &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
&lt;br /&gt;
            setcommand += &amp;quot; 1 x%i&amp;quot; % nframes&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #initialize movie&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x%i&amp;quot; % ftot)&lt;br /&gt;
&lt;br /&gt;
    #cmd.mset(&amp;quot;1 x50 1 -30 30 x20&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    cmd.mset( setcommand )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    #loop through views&lt;br /&gt;
&lt;br /&gt;
    start_view = views[0][:]&lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
&lt;br /&gt;
    first_frame = 1&lt;br /&gt;
&lt;br /&gt;
    for view in views[1:]:&lt;br /&gt;
&lt;br /&gt;
        end_view = view[:]&lt;br /&gt;
&lt;br /&gt;
	if settings.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, settings[i] )&lt;br /&gt;
&lt;br /&gt;
	elif fades.has_key(i):&lt;br /&gt;
&lt;br /&gt;
	    movs.animate_transition( start_view, end_view, frames[i], first_frame, fades[i] )&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
            movs.animate_transition( start_view, end_view, frames[i], first_frame )&lt;br /&gt;
&lt;br /&gt;
        #add an action&lt;br /&gt;
&lt;br /&gt;
        if actions.has_key(i):&lt;br /&gt;
&lt;br /&gt;
            mdo_cmd = actions[i]#+&amp;quot;;set_view (&amp;quot;+str( views[i] )+&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            print mdo_cmd&lt;br /&gt;
&lt;br /&gt;
            cmd.mdo(first_frame, mdo_cmd)&lt;br /&gt;
&lt;br /&gt;
        first_frame += frames[i]&lt;br /&gt;
&lt;br /&gt;
        i += 1&lt;br /&gt;
&lt;br /&gt;
        start_view = end_view[:]&lt;br /&gt;
&lt;br /&gt;
    cmd.frame(1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## views = readViews( &amp;quot;viewfile.txt&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## frames = readFrames( &amp;quot;viewfile.frm&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## actions = readActions( &amp;quot;viewfile.act&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
##print &amp;quot;Length &amp;quot;,len(views)&lt;br /&gt;
&lt;br /&gt;
#for v in views:&lt;br /&gt;
&lt;br /&gt;
 #   print v&lt;br /&gt;
&lt;br /&gt;
#cur_view = views[0]&lt;br /&gt;
&lt;br /&gt;
views = []&lt;br /&gt;
&lt;br /&gt;
frames = []&lt;br /&gt;
&lt;br /&gt;
models = {}&lt;br /&gt;
&lt;br /&gt;
actions = {}&lt;br /&gt;
&lt;br /&gt;
scenes = {}&lt;br /&gt;
&lt;br /&gt;
settings = {}&lt;br /&gt;
&lt;br /&gt;
fades = {}&lt;br /&gt;
&lt;br /&gt;
scene_counter = 0&lt;br /&gt;
&lt;br /&gt;
cur_index = -1&lt;br /&gt;
&lt;br /&gt;
cmd.set( &amp;quot;scene_animation_duration&amp;quot;,&amp;quot;0&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
#cmd.set_view( cur_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sn&amp;quot;, show_next )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sp&amp;quot;, show_prev )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sc&amp;quot;, show_cur )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinsert&amp;quot;, insert_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelete&amp;quot;, delete_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreplace&amp;quot;, replace_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappend&amp;quot;, append_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sscene&amp;quot;, insert_scene )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sgo&amp;quot;, go_to_view )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sreadold&amp;quot;, read_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swriteold&amp;quot;, write_views )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;slist&amp;quot;, list_frames )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetf&amp;quot;, set_frames_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sshow&amp;quot;, show_transition )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;srecord&amp;quot;, make_all )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;saction&amp;quot;, add_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdelaction&amp;quot;, clear_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdumpactions&amp;quot;, list_actions )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sappendaction&amp;quot;, append_action_current )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;smorph&amp;quot;, morph_models )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sinterpsetting&amp;quot;, interpolate_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sdeletesetting&amp;quot;, delete_settings )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;scrossfade&amp;quot;, crossfade )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;swrite&amp;quot;, writeKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;sread&amp;quot;, readKeyViewFile )&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;ssetupview&amp;quot;, setup_view )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10224</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10224"/>
		<updated>2006-12-31T04:45:20Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10223</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10223"/>
		<updated>2006-12-31T04:40:27Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;br /&gt;
&lt;br /&gt;
=Script Files=&lt;br /&gt;
&lt;br /&gt;
*[[Media:movs.py]]&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10222</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10222"/>
		<updated>2006-12-31T04:26:42Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Manual for Slerpy.py =&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==General Use==&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
==Important concepts==&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
==Quick Start Tutorial==&lt;br /&gt;
 &lt;br /&gt;
;Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
;Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
;Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
;Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
;Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
;Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
;Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
;Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
;Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
==Command Reference==&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10221</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10221"/>
		<updated>2006-12-31T04:22:47Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: /* Quick Start Tutorial */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Manual for Slerpy.py ===&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=General Use=&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
= Important concepts =&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
= Quick Start Tutorial =&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
&lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
=Command Reference=&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10220</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10220"/>
		<updated>2006-12-31T04:21:17Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Manual for Slerpy.py ===&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=General Use=&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
= Important concepts =&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
= Quick Start Tutorial =&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7A: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Step 7B (Alternative using scenes):&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
=Command Reference=&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
&lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10219</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10219"/>
		<updated>2006-12-31T04:19:28Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Manual for Slerpy.py ===&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=General Use=&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
&lt;br /&gt;
= Important concepts =&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
= Quick Start Tutorial =&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
&lt;br /&gt;
 import slerpy&lt;br /&gt;
&lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
&lt;br /&gt;
 sinsert&lt;br /&gt;
&lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Step 7 Alternative using scenes:&lt;br /&gt;
&lt;br /&gt;
 sgo 5&lt;br /&gt;
&lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
&lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
=Command Reference=&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
 &lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10218</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10218"/>
		<updated>2006-12-31T04:18:09Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Manual for Slerpy.py ===&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=General Use=&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
 &lt;br /&gt;
 import slerpy&lt;br /&gt;
 &lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
 &lt;br /&gt;
= Important concepts =&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
&lt;br /&gt;
= Quick Start Tutorial =&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
 &lt;br /&gt;
 import slerpy&lt;br /&gt;
 &lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
 &lt;br /&gt;
 sinsert&lt;br /&gt;
 &lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
:Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
:You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
:You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
Step 7 Alternative using scenes:&lt;br /&gt;
 &lt;br /&gt;
 sgo 5&lt;br /&gt;
 &lt;br /&gt;
:Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
 sscene&lt;br /&gt;
 &lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
&lt;br /&gt;
 swrite mymovie&lt;br /&gt;
&lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
&lt;br /&gt;
 srecord&lt;br /&gt;
&lt;br /&gt;
:You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
&lt;br /&gt;
 sgo 0&lt;br /&gt;
 saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
&lt;br /&gt;
=Command Reference=&lt;br /&gt;
&lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
&lt;br /&gt;
 sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
 &lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10217</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10217"/>
		<updated>2006-12-31T04:11:56Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Manual for Slerpy.py ==&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=General Use=&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(important)]]&lt;br /&gt;
= Important concepts =&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tutorial)]]&lt;br /&gt;
= Quick Start Tutorial =&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinsert&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
 Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
 You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
 You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 7 Alternative using scenes:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
 Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sscene&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
swrite mymovie&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
srecord&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tips)]]&lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sgo 0&lt;br /&gt;
saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(commands)]]&lt;br /&gt;
=Command Reference=&lt;br /&gt;
 &lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10216</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10216"/>
		<updated>2006-12-30T23:48:19Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Manual for Slerpy.py ==&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation. &lt;br /&gt;
&lt;br /&gt;
 * [[#important Important Concepts]]&lt;br /&gt;
 * [[#tutorial Tutorial]]&lt;br /&gt;
 * [[#tips Tips and Tricks]]&lt;br /&gt;
 * [[#commands Command Reference]]&lt;br /&gt;
 &lt;br /&gt;
'''General Use:'''&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(important)]]&lt;br /&gt;
'''Important concepts'''&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tutorial)]]&lt;br /&gt;
'''Quick Start Tutorial:'''&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinsert&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
 Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
 You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
 You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 7 Alternative using scenes:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
 Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sscene&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
swrite mymovie&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
srecord&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tips)]]&lt;br /&gt;
'''Tips and Tricks''':&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sgo 0&lt;br /&gt;
saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(commands)]]&lt;br /&gt;
'''Command Reference'''.&lt;br /&gt;
 &lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10215</id>
		<title>Slerpy</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Slerpy&amp;diff=10215"/>
		<updated>2006-12-30T23:43:47Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Manual for Slerpy.py ==&lt;br /&gt;
 &lt;br /&gt;
An extension to pymol that creates a moderately easy to use environment for doing keyframe animation.&lt;br /&gt;
[[BR]]&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 * [#important Important Concepts]&lt;br /&gt;
 * [#tutorial Tutorial]&lt;br /&gt;
 * [#tips Tips and Tricks]&lt;br /&gt;
 * [#commands Command Reference]&lt;br /&gt;
 &lt;br /&gt;
'''General Use:'''&lt;br /&gt;
 &lt;br /&gt;
At the pymol command line type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will load the extended commands. All commands in slerpy begin with the letter s. Pymol's tab autocomplete feature will work on the additional commands.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(important)]]&lt;br /&gt;
'''Important concepts'''&lt;br /&gt;
 &lt;br /&gt;
The main function of slerpy is to record a series of pymol views. A movie can then be created by interpolating between these views. A pymol view consists mostly of the camera orientation (that is, the orientation of the viewers eye with respect to the molecule). It also includes information about the clipping planes.&lt;br /&gt;
 &lt;br /&gt;
It is important to realize that most slerpy commands act on the &amp;quot;current&amp;quot; view. You can navigate among views by using the sn, sp, and sgo commands. If you've changed the view around with the mouse or you just want to know the number of the current view you can get back to the current view with the sc command.&lt;br /&gt;
 &lt;br /&gt;
Pymol views do not contain information about how pymol objects and selections are displayed. If you just want to create a movie which moves around a single representation of a molecule then all you need to do is record the set of views that define the tour of the molecule.&lt;br /&gt;
 &lt;br /&gt;
If, on the other hand, you want to change the representation or change which items are displayed you will need to add actions to some of your views. An action is any set of pymol commands. Actions can be associated with any view in the series recorded by slerpy. The ''sscene'' command inserts a new view and simultaneously creates a pymol scene and the action to display it. The scene will include all of the objects and representations visible at the time the command was issued.&lt;br /&gt;
 &lt;br /&gt;
In order to control the rate of motion between the defined views in a slerpy movie, you can control the number of frames used in each interpolation. When a view is saved in slerpy it is associated by default with a transition of 50 frames to the next view. The number of frames in the transition can be altered with the ''ssetf'' command in slerpy.&lt;br /&gt;
 &lt;br /&gt;
The views and actions stored by slerpy can (and should) be saved to a key file with the ''swrite'' command. They can then be retrieved with the sread command.  Note that swrite saves the current pymol state in a .pse file but sread does not read in the .pse file.  If you're starting a new pymol session to continue work on an existing movie you should load the pse file before doing an sread.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tutorial)]]&lt;br /&gt;
'''Quick Start Tutorial:'''&lt;br /&gt;
 &lt;br /&gt;
Step 1: You probably want to start off in a nice clean working directory that just has the coordinate files you want to work with.&lt;br /&gt;
 &lt;br /&gt;
Step 2: Read in your molecule(s) and create the various selections and representations that you want to include in the movie.&lt;br /&gt;
 &lt;br /&gt;
Step 3: At the pymol prompt, type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
import slerpy&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 4: Get your molecule in exactly the orientation and representation that you want to use for the beginning of your movie.&lt;br /&gt;
 &lt;br /&gt;
Step 5: Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinsert&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 6: Using the mouse, move your molecule to the next orientation that you want to use. When you record the movie, the camera orientation will be interpolated between each consecutive pair of views. This can include changes in rotation, zooming, clipping etc.&lt;br /&gt;
 &lt;br /&gt;
 Loop back to Step 5. Continue this until you've got all your orientations stored.&lt;br /&gt;
 &lt;br /&gt;
 You can check how any set of transitions will look at any time by using the ''sshow'' command (see command ref for details).&lt;br /&gt;
 &lt;br /&gt;
 You can adjust the rate of any transition using the ''ssetf'' command&lt;br /&gt;
 &lt;br /&gt;
Step 7: Add any actions to your views using the saction command. Any number of pymol commands can be strung together separated by semicolons. If, for example, you want to change your protein from a cartoon to a surface and add a ligand when you get to view 5 you would do the following (assuming you've defined the pymol selections prot and lig):&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
 saction &amp;quot;hide cartoon, prot; show surface, prot; show sticks, lig&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 7 Alternative using scenes:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sgo 5&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
 Now use the gui to create the representation you want and then:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
 sscene&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Step 8: Save everything. Save your slerpy views and actions as well as a pse file of your current pymol session:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
swrite mymovie&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
This will create mymovie.key, which has all of the views, frame counts, actions etc. and mymovie.pse, the associated pymol session file.&lt;br /&gt;
 &lt;br /&gt;
Step 9: Record the movie! Type:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
srecord&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
You can then play the movie by typing the standard pymol command ''mplay'' or by clicking the play button in pymol.&lt;br /&gt;
 &lt;br /&gt;
Step 10: If you save the pymol session again, the pse file will contain the movie which can then be shown immediately after startup without running slerpy.py. Note that pymol will warn you when you load a pse file that contains a movie.&lt;br /&gt;
 &lt;br /&gt;
Step 11: If you want to, the movie can be exported using the mpng command (see the pymol [http://pymol.sourceforge.net/newman/ref/S1000comref.html#2_105 documentation]).&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(tips)]]&lt;br /&gt;
'''Tips and Tricks''':&lt;br /&gt;
 &lt;br /&gt;
'''Converting scenes to movies''':&lt;br /&gt;
 &lt;br /&gt;
You can just step through the scenes and type sscene for each one. This will create a duplicate slerpy scene for each of the scenes you'd already saved but that's not such a disaster. Be sure to swrite when your done.&lt;br /&gt;
 &lt;br /&gt;
Note that there is some overhead associated with recalling scenes. To avoid pauses at view transitions, I prefer to actually issue the set of show and hide commands that will generate the scene rather than using the above method.&lt;br /&gt;
 &lt;br /&gt;
'''Starting off right''':&lt;br /&gt;
 &lt;br /&gt;
It's a bit of a pain, but I like to associate with the first frame of the movie an action list that hides everything and then turns on all the objects that I want to have visible at the beginning. This ensures that when your movie loops back to the beginning it will look the same as it did the first time through. For example:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sgo 0&lt;br /&gt;
saction &amp;quot;hide everything; show lines, prot; show surface, activesite; show sticks, ligand&amp;quot;&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
Alternatively, start your slerpy work with an ''sscene''.&lt;br /&gt;
 &lt;br /&gt;
Be sure to run your movie once it's been opened and before your presentation if you're presenting in pymol. This will ensure that any objects that don't appear until the middle of the movie are available in memory and won't need to be rebuilt while your audience waits.&lt;br /&gt;
&lt;br /&gt;
'''Pausing on a view''':&lt;br /&gt;
&lt;br /&gt;
Just sgo to the view you want to stay on for a while and do an sinsert.  This will insert a new view with the same orientation etc as the one you were just on.  You can adjust the length of the pause by changing the number of frames for the transistion between these two identical views  using the ssetf command.&lt;br /&gt;
 &lt;br /&gt;
[[Anchor(commands)]]&lt;br /&gt;
'''Command Reference'''.&lt;br /&gt;
 &lt;br /&gt;
Note that it is essential to understand that slerpy uses the concept of a current or active view. This is the element in the list to which most commands are applied. It is not necessarily the view that is currently visible on the screen. It is advisable to use the sc command frequently to make sure you really know which view your command is being applied to.&lt;br /&gt;
 &lt;br /&gt;
'''saction ''string'':''' Assoiciates the pymol commands in ''string'' with the current view. ''string'' must be enclosed in quotes and must contain only valid pymol commands separated by semicolons.&lt;br /&gt;
 &lt;br /&gt;
'''sappend''': Add the currently displayed view at the end of the list of views in slerpy&lt;br /&gt;
 &lt;br /&gt;
'''sappendaction ''string'':''' Adds the action(s) in ''string'' to the list of actions associated with the current view&lt;br /&gt;
 &lt;br /&gt;
'''sc''': Go to the slerpy active view&lt;br /&gt;
 &lt;br /&gt;
'''scrossfade ''startobject, endobject'':''' During the transition from the current view to the next view ''startobject'' will fade out and'' endobject'' will fade in. The two objects must be shown as sticks. They must be objects, not merely selections, as of pymol 0.99.&lt;br /&gt;
 &lt;br /&gt;
'''sdelaction''': Deletes the action associated with the current view. Be sure you're sure which view you're on before you use this.  This will also delete any actions etc. associated with the view so be careful.&lt;br /&gt;
 &lt;br /&gt;
'''sdelete''': Remove the slerpy active view from the list of views to be interpolated.&lt;br /&gt;
 &lt;br /&gt;
'''sdeletesetting: '''Remove the setting interpolation for the current view.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions: '''List all actions by frame.&lt;br /&gt;
 &lt;br /&gt;
'''sgo ''n'':''' Change the slerpy active view to view ''n''.&lt;br /&gt;
 &lt;br /&gt;
'''sinsert''': Add the currently displayed view after the slerpy active view.&lt;br /&gt;
 &lt;br /&gt;
'''sinterpsetting ''setting, selection, startval, endval'' :''' The pymol setting ''setting'' will be interpolated linearly from ''startval'' to ''endval'' during the transition from the current view to the next view. You can only interpolate one setting per transition. This is the hard way to, for example, fade out an object:&lt;br /&gt;
 &lt;br /&gt;
{{{&lt;br /&gt;
sinterpsetting stick_transparency, lig, 0.0, 1.0&lt;br /&gt;
}}}&lt;br /&gt;
 &lt;br /&gt;
'''slist''': List all views stored for interpolation. Also lists the number of frames in each transition.&lt;br /&gt;
 &lt;br /&gt;
'''smorph ''startmodel,endmodel'':''' The transition from the current frame to the next frame will consist of one frame per pymol state starting with state ''startmodel'' and ending with state ''endmodel''. Subsequent frames (i.e. from subsequent views) will revert to state 1. The state numbers apply to currently visible objects so you will most likely want to have an object with your starting conformation, an object with your multi-state morphing model, and an object with your final conformation. You would then sgo to the frame where you want the morph to start and add an action to hide the starting conformation object and show the multi-model morphing object, do an smorph 1,30 or whatever the number of states in your morph is, append another frame and give it an action where the multi-state model is hidden and the final conformation is shown.&lt;br /&gt;
 &lt;br /&gt;
'''sn''': Go to the next view&lt;br /&gt;
 &lt;br /&gt;
'''sp''': Go to the previous view.&lt;br /&gt;
 &lt;br /&gt;
'''sread ''filename'':''' Restore all the information written with swrite.  Does not read in the pse file (to avoid inadvertantly writing over some new selections, scenes or whatever).&lt;br /&gt;
 &lt;br /&gt;
'''srecord''': Records the movie&lt;br /&gt;
 &lt;br /&gt;
'''sreplace''': Replace the slerpy current view with the currently displayed view.&lt;br /&gt;
 &lt;br /&gt;
'''sscene''': Add a the currently displayed view after the slerpy active view and create a scene to go with it. The current pymol state, including which objects are displayed and how they are shown will therefor be captured.&lt;br /&gt;
 &lt;br /&gt;
'''ssetf''': Set the number of frames to use in the transition from the slerpy active view to the next view&lt;br /&gt;
 &lt;br /&gt;
'''ssetupview ''n'':''' This attempts to make sure that all objects are displayed (or not) as they would be when view ''n'' is arrived at in the movie. It goes through and executes all of the sactions from all preceeding views. For some reason this doesn't always work in complex cases.&lt;br /&gt;
 &lt;br /&gt;
'''sshow ''n,m'':''' This command records and shows a segment of the movie showing the transitions starting with view n and ending with view m. If the arguments m and n are omitted the transition from the current view to the next view will be shown.&lt;br /&gt;
 &lt;br /&gt;
'''sdumpactions''': Lists all of the currently assigned actions and their view numbers. Note that this list is a python dictionary and is therefore not in any particular order.&lt;br /&gt;
 &lt;br /&gt;
'''swrite ''filename'':''' Writes all the information used by slerpy to a file ''filename''.key. It also writes a pymol session file ''filename''.pse containing all of your current objects, selections etc. The format of the .key file is supposed to be human readable and it can be convenient to edit this file rather than using saction over and over. After editing it by hand besure to do an sread.&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Category:Script_Library&amp;diff=3881</id>
		<title>Category:Script Library</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Category:Script_Library&amp;diff=3881"/>
		<updated>2006-12-30T23:41:10Z</updated>

		<summary type="html">&lt;p&gt;Joelbard: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[WriteSS]] -- Writes secondary structural elements, for each residues, to a file.&lt;br /&gt;
&lt;br /&gt;
* [[Process_All_Files_In_Directory]] -- Do something to all files in a directory.  The examples show how to print the disulfide bond lengths, then in general all sulfur distances (not necessarily bound).&lt;br /&gt;
&lt;br /&gt;
* [[Kabsch]] -- Kabsch alignment of two sets of vectors.  (Part 2 of a protein alignment.)&lt;br /&gt;
&lt;br /&gt;
* [[Transform_odb]] -- Transform a selection of an existing object and output as a new object.  The transformation matrix is read from an &amp;quot;O&amp;quot;-style tranformation matrix file (.odb) written by &amp;quot;O&amp;quot; or by any of the Uppsala Software Factory programs (from Gerard Klegweit) such as LSQMAN.&lt;br /&gt;
&lt;br /&gt;
* [[Stereo_Ray]] -- This script will create two resolution specific ray traced images rotated appropriately for inclusion into a single file to represent a stereo view of the desired macromolecule.&lt;br /&gt;
&lt;br /&gt;
* [[Translate_And_Measure]] -- prints '''overlap''' if any of the atoms in molA or molB were within 4 Angstrom after translating by 1 along X&lt;br /&gt;
&lt;br /&gt;
* [[Show aromatics]] -- This script will display a backbone &amp;quot;worm&amp;quot; for your protein, with all of the sidechains for aromatic residues displayed as green &amp;quot;sticks&amp;quot;.  Usage: Save this as &amp;quot;show_aromatics.pml&amp;quot;, load your protein in PyMOL, and run the script (select &amp;quot;Run&amp;quot; from the &amp;quot;File&amp;quot; menu). (PyMOL script; TStout)&lt;br /&gt;
&lt;br /&gt;
* [[Show hydrophobics]] -- This script will display a backbone &amp;quot;worm&amp;quot; for your protein, with all of the sidechains for hydrophobic residues displayed as orange &amp;quot;sticks&amp;quot;.  Usage: Same as &amp;quot;show aromatics&amp;quot;. (PyMOL script; TStout)&lt;br /&gt;
&lt;br /&gt;
* [[Show charged]] -- This script will display a backbone &amp;quot;worm&amp;quot; for your protein, with all of the sidechains for charged residues displayed as red (negative) or blue (posititve) &amp;quot;sticks&amp;quot;.  Usage: Same as &amp;quot;show aromatics&amp;quot;. (PyMOL script; TStout)&lt;br /&gt;
&lt;br /&gt;
* [[Show hydrophilic]] -- This script will display a backbone &amp;quot;worm&amp;quot; for your protein, with all of the sidechains for hydrophilic residues displayed as green &amp;quot;sticks&amp;quot;.  Usage: Same as &amp;quot;show aromatics&amp;quot;. (PyMOL script; TStout)&lt;br /&gt;
&lt;br /&gt;
* [[Show NMR constrains]] -- This script will display the NMR constrains used for a structure calculation atop a structure.  Usage: Save this as &amp;quot;NMRcnstr.py&amp;quot; load your protein in PyMOL, and run the script. type upl('fname') or cns('fname') where fname is the filename with the NMR constrains you want to display. &lt;br /&gt;
&lt;br /&gt;
* [[Perp Maker]] -- Creates a perpendicular plane through the center of your protein with respect to the camera's current position.  (If you translate the protein towards the camera a bit, you get a nice surface, sometimes.) A stupid little script I wrote in response to a request a few months ago (and it doesn't even conform to the request!)  Load a protein, run the script (read the documentation in the script). (Jason Vertrees/[[User:Tree|Tree]])&lt;br /&gt;
&lt;br /&gt;
* [[PythonTerminal]] -- Allows execution of python commands from the PyMOL command line.&lt;br /&gt;
&lt;br /&gt;
* [[Axes]] -- Creates a 3D-CGO object that shows the three coordinate axes.&lt;br /&gt;
&lt;br /&gt;
* [[CGO Text]] -- Creates a 3D-CGO text object.&lt;br /&gt;
&lt;br /&gt;
* [[List Selection]] -- Prints a list of all residues in a selection (both Python and .pml).&lt;br /&gt;
&lt;br /&gt;
* [[List Colors]] -- Lists the color of all residues in a selection (both Python and .pml).&lt;br /&gt;
&lt;br /&gt;
* [[List Secondary Structures]] -- Secondary structures (both predefined and those calculated with the 'dss' command) can be exported as a long string ('HHHHLLLLSSS').&lt;br /&gt;
&lt;br /&gt;
* [[Split Movement]] -- Moves two parts of one object into different directions.&lt;br /&gt;
&lt;br /&gt;
* [[Selection Exists]] -- Python method that returns true if a selection of a given name exists.&lt;br /&gt;
&lt;br /&gt;
* [[Get Coordinates I]] -- Retrieves atom coordinates as Python objects.&lt;br /&gt;
&lt;br /&gt;
* [[Get Coordinates II]] -- Retrieves atom coordinates as Python array (list object).&lt;br /&gt;
&lt;br /&gt;
* [[grepset]] -- List all settings matching a given keyword. - ''by EHP''&lt;br /&gt;
&lt;br /&gt;
* [[apropos]] -- List all commands matching a given keyword or whose docs contain the keyword. - ''by EHP''&lt;br /&gt;
&lt;br /&gt;
* [[mouse_modes]] -- customize the default mouse bindings for Viewing or Editing modes. - ''by EHP''&lt;br /&gt;
&lt;br /&gt;
* [[Measure Distance]] -- Measures the distance between two atoms (Python script).&lt;br /&gt;
&lt;br /&gt;
* [[Read PDB-String]] -- Parses a string in PDB format to a PyMOL object.&lt;br /&gt;
&lt;br /&gt;
* [[Color Objects]] -- Colors all objects differently (Python script).&lt;br /&gt;
&lt;br /&gt;
* [[Key Wait]] -- Process key events in a Python script.&lt;br /&gt;
&lt;br /&gt;
* [[Bounding Box]] -- Create a bounding box around a selection (Python script; requires numarray and Scientific; gilleain)&lt;br /&gt;
&lt;br /&gt;
* [[Ellipsoid]] -- Create callback object (opengl) ellipsoids. (Python script;  gilleain)&lt;br /&gt;
&lt;br /&gt;
* [[pdbsurvey]] -- Surveys the pdb for recently added structures that are relevant to a user-specified keywords list (in a text file)&lt;br /&gt;
&lt;br /&gt;
* [[TransformSelectionByCameraView]] -- Transforms the selection by the camera view.&lt;br /&gt;
&lt;br /&gt;
* [[WFMesh]] -- Imports wavefront object mesh files; Starwars as an example!&lt;br /&gt;
&lt;br /&gt;
* [[grepsel]] -- Make named selections using regular expressions (protein sequence).&lt;br /&gt;
&lt;br /&gt;
* [[PowerMate Dial OS X]] -- Script and instructions to use the PowerMate dial on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
* [[Plane Wizard]] -- Wizard to draw planes between three picked points.&lt;br /&gt;
&lt;br /&gt;
* [[Slerpy]] -- Pymol command extensions for key frame animation movie making.&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting|Script Library]]&lt;/div&gt;</summary>
		<author><name>Joelbard</name></author>
	</entry>
</feed>