Difference between revisions of "MovieSchool"

From PyMOLWiki
Jump to: navigation, search
(Motions & Representations)
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<center><p style="font-size: 28px; text-decoration: underline;">'''PyMOLWiki's Movie School'''</p></center>
 
<center><p style="font-size: 28px; text-decoration: underline;">'''PyMOLWiki's Movie School'''</p></center>
  
Here you will learn all the latest and greatest techniques for making PyMOL movies.  These make you look like a '''master of PyMOL''' when you can show them off in a presentation or even in MPEG/AVI format.
+
== Welcome ==
 +
Here you will learn all the latest and greatest techniques for making movies in PyMOL.  These make you look like a '''master of PyMOL''' when you can show them off in a presentation or even in MPEG/AVI format.  For your ease of learning I have commented all of the movie scripts and tried to ensure that they work in PyMOL if you just copy/paste the code.
  
* All scripts are commented
+
If you have any comments on this tutorial, please feel free to add them to the discussion page. If you have corrections, improvements or additions, as always, please feel free to improve the pages.
* All scrips can be directly copy/pasted into '''newer''' PyMOLs, which should then result is a movie being created (and possible automatically played, too).
 
* Please leave off-topic stuff or requests to this page's discussion page.
 
* As the rest of the wiki, this page is editable by all (registered) users.  If you have a tip or movie you'd like to add, please feel free to do so.
 
  
== Movie Making ==
+
* NB: While this is pretty expansive (hence the 6 lessons) it is still incomplete and surely rough in some places.
While PyMOL's capability to produce static images is quite powerful, there are some stories that are better told through movies, than static images alone. This little page will provide the necessary ideas, links, code and examples for making movies in PyMOL.
+
* NB: Make sure you have the newest [http://www.pymol.org/ PyMOL v1.2r0].
  
== Your First Movie ==
+
== Movie Making Roadmap ==
Movies can be very simple, for example, animating an NMR ensemble:
+
* [[MovieSchool_1|Introduction & Movie Making for the Impatient]]
<source lang="python">
+
:: The basics; '''movies in 60 seconds'''.
# Your first movie.
 
fetch 1nmr
 
mplay
 
  
# to stop the movie when you're ready
+
* [[MovieSchool_2|Terminology & Movie Related Commands]]
# type 'mstop'.
+
:: Definitions; commands; settings;
</source>
 
  
What PyMOL did here was to [[fetch]] the file from the PDB and load it into an object with 20 states.  Somewhere between then and issuing [[mplay]] PyMOL created 20 frames for your object and assigned one state to each frame.  This created the animated effect as we scroll through the frames.
+
* [[MovieSchool_3|PyMOL GUI for Movie Making]]
 +
:: Using the GUI to make movies
  
 +
* [[MovieSchool_4|Simple Movie Examples]]
 +
:: Easy copy/paste examples
  
== Terminology ==
+
* [[MovieSchool_5|Putting it All Together]]
Imagine a complex movie for a moment, a movie that has camera motions, objects moving independently or in concert with other objects, changing colors and representations.  To handle camera motions PyMOL must know at all times where the camera is located and what it's pointed toward (as well as clipping planes).  For objects to move around or be rotated without regard to the camera (the objects themselves rotate/translate, not just the camera), PyMOL has to store the coordinates and matrices for these objects, too.  Changing colors and representations for each object must somehow also be stored.  So, as you can see this is a multidimensional problem: at each time point in your movie, PyMOL must remember positions and representations, as well as make it easy for you to transition between them (interpolation).
+
:: More advanced examples; using states, scenes, and object motions
 
 
Despite these complexities, PyMOL tries to enable movie making for even novice users.  Let's start by defining a few PyMOL concepts&mdash;states, frames and scenes.
 
 
 
=== Basic Movie Terminology ===
 
[[Image:Movies.png|right|thumb|frame|Schematic of how frames, scenes and states link together.]]
 
 
 
'''object'''
 
::An object is any PyMOL-object loaded into PyMOL, like atoms, molecules, complexes, etc.  When you load an PDB from disk/net it is loaded into PyMOL as an object.
 
:: [[:Category:Objects|All pages regarding objects]]
 
 
 
'''selection'''
 
:: A selection is a specifically chosen set of atoms, molecules, complexes etc. in PyMOL.  A selection is not an object, it's a subset of stuff from a (collection of) object(s).  Selections can be named and when named have are distinguished from objects by having parentheses around their names.  For example, ''foo'' would be an object and ''(foo)'' would be some selection.  When you pick an atom (and get the default '''(sele)''' selection) or issue the ever-popular [[Select]]ion command, you get a selection.
 
:: [[:Category:Selections|All pages regarding selections]]
 
 
 
'''states'''
 
:: A state is a particular conformation (set of coordinates) for a given object.  For example an NMR ensemble could contain the same molecule, but in 20 different states.  PyMOL can make movies from states.  States '''do not store representations''' in PyMOL (eg. cartoons vs. sticks).
 
:: See also [[:Category:States|All pages regarding states]]
 
 
 
'''scenes'''
 
:: A '''scene''' as I understand stores the orientation/position of the camera, all object activity information, all atom-wise visibility, color, representations, and the global frame index.
 
:: See [[:Category:Scenes]] and [[Scene]] for more information.  The [[Scene]] page has information on how to quickly add/remove and change scenes--''suggested reading!''
 
 
 
'''interpolation'''
 
:: A scene is the staged representations of objects and the orientation of the camera.
 
:: See also [[:Category:Scenes|All pages regarding scenes]]
 
 
 
'''frames'''
 
:: A frame can be thought of as a single frame in a movie reel.  A frame stores state information and scene information.
 
:: See also [[:Category:Frames|All pages regarding frames]]
 
 
 
'''Movie Panel'''
 
:: The movie panel is a frame indicator strip at the bottom of the screen.  It shows a little icon for which frame you're currently on, and whether or not the camera has been set for that frame.
 
:: See [[movie_panel]] for more information.
 
 
 
== What is a Movie? ==
 
Now the we have the appropriate terminology to talk about movies in PyMOL, we can discuss what a movie really is.  A movie in PyMOL is a series of frames stitched together in some way so as to create the desired animation.  Once a movie is made in PyMOL, we have a few options for exporting it to other formats like png arrays or MPEG moves.
 
 
 
== Movie Making Commands ==
 
This tutorial assumes you have some basic knowledge about how to use PyMOL (eg. mousing, choosing and setting your representations, etc).  If you're not yet at this level, please check out [[:Category:Tutorials|the Tutorial Category]] of pages (most notably the beginner tutorials).
 
 
 
I think it's help to think of the movie as a set of frames, like in a movie reel, so let's start there.  (Each command below links to the command's PyMOL wiki page, so feel free to click through for more info.)
 
 
 
=== [[frame]]===
 
This command tells PyMOL to set the current frame to whichever you desire.  To use it, just issue the command, <source lang="python">frame X</source> where '''X''' is some integer number indicating the frame you want to go to.  If you issue a frame number greater than the number of frames, PyMOL sets the frame to the highest-numbered frame you have (similarly for negative numbers or numbers smaller than the minimum numbered frame).
 
 
 
Let's try a quick example with [[frame]],
 
<source lang="python">
 
# create an empty 90 frame movie
 
mset 1 x90
 
# turn on the movie panel (bottom of screen)
 
set movie_panel, on
 
# goto frame one
 
frame 1       
 
# try some intermediate frames; notice the blue indicator in the movie panel       
 
frame 10
 
frame 50
 
frame 90
 
# try going beyond the end and see what PyMOL does
 
frame -1
 
frame 100
 
# play through the empty movie
 
mplay
 
# stop the movie
 
mstop
 
</source>
 
 
 
 
 
=== [[States|set state]] ===
 
Again, states are particular stored conformations of objects.  Here we use PyMOL to set and get the states, and see how PyMOL mapped them to our earlier movie example.
 
 
 
This command has a similar idea of [[frame]], but works a little differently.  Instead of typing,
 
<source lang="python">
 
# invalid command
 
state 40
 
</source>
 
in PyMOL we [[set]] the [[States|state]]:
 
<source lang="python">
 
# how to set a state in PyMOL
 
set state, stateNo, objectName
 
 
 
# for example
 
# set state to 40
 
set state, 40
 
 
 
# also, get state
 
get state
 
</source>
 
 
 
==== States &amp; Frames (optional reading) ====
 
As an example, look at the code from the "first movie":
 
<source lang="python">
 
fetch 1nmr
 
mplay
 
# issue mstop, to stop the movie
 
</source>
 
 
 
We can do a couple things now, let's try counting the number of states and frames PyMOL now knows about:
 
<source lang="python">
 
# how many frames does PyMOL know about?
 
count_frames
 
 
 
# what about states?
 
count_states
 
</source>
 
 
 
and now let's see how PyMOL mapped frames to states.  Using the above commands and a little Python, let's see how PyMOL mapped the frames to states:
 
<source lang="python">
 
python
 
for x in range(1,cmd.count_frames()+1):
 
  cmd.frame(x)
 
  print "Frame => %s; and State => %s" % ( str(x), str(cmd.get('state')))
 
python end
 
</source>
 
which should show a 1-1 mapping of states to frames.
 
 
 
=== [[mset]] ===
 
[[mset]] is a very powerful command.  This command tells PyMOL how to assign states to frames.  So, now you see why it's necessary to clearly distinguish between and use the two.  Let's learn how to use [[mset]].
 
 
 
The syntax for [[mset]] can be a little tricky at first. I would write the syntax as:
 
<source lang="python">
 
mset stateSpec, frameSpec
 
</source>
 
which assigns the states in '''stateSpec''' to the frames in '''frameSpec'''., where '''stateSpec''' is any mset-valid state specification.  PyMOl supports to patterns for '''stateSpec'''.  You can do simply supply a number eg
 
<source lang="python">
 
mset 1
 
</source>
 
or you can specify a range of states&mdash;like 1 through 55 as
 
<source lang="python">
 
# setting states 1 through 55
 
# caution: notice the space: 1 -55, not 1-55 (this is a PyMOL parser caveat)
 
mset 1 -55
 
</source>
 
Simple enough.  Now for '''frameSpec''' you can specify a single frame number like so or you can specify ''how many frames PyMOL should use to map to your specified states'' with the '''xNumber''' command.  This will make sense with an example
 
<source lang="python">
 
# Recall: mset stateSpec frameSpec
 
# so we are setting STATE 1 across a span of 90 frames
 
mset 1 x90
 
 
 
# Recall: mset stateSpec frameSpec
 
# so we are setting states 1..120 to the next 120 frames
 
mset 1 -120 x120
 
</source>
 
 
 
NB: Actually the syntax is a little more complicated than this as PyMOL's mset command has the ability to remember in which frame the prior specification left the movie.  So, you can sort of chain the specifications.  Type ''help mset'' in PyMOL for more info or see [[mset]].
 
 
 
=== [[mview]] ===
 
The [[mview]] command can be intimidating, but all we need to know about it at present is that it can store the (1) camera position or (2) a given object position.  The idea is to essentially make 'way points' in your movie and have PyMOL interpolate the in-between positions/coordinates, etc.  For example, if I wanted to make a 100-frame movie of a zoom into an object, I could store and manually set 100 camera positions, or I could do the starting position and the final position and ask PyMOL to just interpolate that over 100 frames.  The latter idea is obviously much simpler.  So simple in fact, let's make a super-quick movie that does exactly what I just mentioned&mdash;100 frames of a slow zoom into some object.  Start with a fresh PyMOL session ([[reinitialize]]) and then copy/paste the following:
 
<source lang="python" line=1>
 
# let's initialize the movie to 100 frames, all of state 1
 
# it's ONLY state 1, because we're only moving the camera around, not
 
# changing structure coordinates of the leucine:
 
mset 1 x100
 
 
 
# show a leucine
 
frag leu
 
 
 
# position the residue
 
orient
 
 
 
# let's store the current camera position
 
mview store
 
 
 
# now set our way point to be frame 100
 
frame 100
 
 
 
# now let's zoom into some atom on the fragment
 
zoom ID 10
 
 
 
# now save this view at frame 100
 
mview store
 
 
 
# last thing is to tell PyMOL to interpolate the 100 frame zoom
 
# so we don't have to do those 100 snapshots:
 
mview reinterpolate
 
 
 
# voila, you have a movie.  To watch it go back to frame 1 and play it
 
frame 1
 
mplay
 
 
 
# mstop when you're ready
 
</source>
 
 
 
'But, hold on!' you might say.  Why is it so herky-jerky?  We have smooth zooming but then a snap and back to frame one!  Well, we never gave PyMOL any number of frames to interpolate the change from frame 100 back to frame 1 (since it wraps).  If we wanted an a '''zoom in''' that was equally as fast as the '''zoom out''' we would simply '''replace line #16''' with
 
<source lang="python">
 
# now set our way point to be frame 100
 
frame 100
 
</source>
 
but, if we wanted a slow, zoom in and a ''fast'' zoom out we could do
 
<source lang="python">
 
# now set our way point to be frame 100
 
frame 80
 
</source>
 
instead which would only give PyMOL 20 frames with which to zoom us out.  Try it!
 
 
 
==== Very Basic Mview Syntax ====
 
''This is a simple overview, see [[mview]] for complete details.''
 
 
 
Using [[mview]] as you can see from above is pretty simple.  The very basic syntax is:
 
<source lang="python">
 
# store the camera OR some object given by objName (if it's supplied)
 
mview store[, object=objName]
 
 
 
# reinterpolate (link together the positions) for the saved camera or object
 
mview reinterpolate[, object=objName]
 
</source>
 
If you leave off the '''object=objName''' then you're storing the '''camera information only'''&mdash;and so none of your objects will be moving anywhere&mdash;just the camera.  If you include an object name, then it stores that object's position information in the current frame.  The '''mview store''' tells PyMOL to store the camera or objects coordinates, while the '''mview reinterpolate''' command tells PyMOL to link together the saved positions for the camera or the selected object in a smooth, cool way.
 
 
 
== Simple Movie Examples ==
 
We now the ability to make some pretty simple, but cool movies.  So, let's try a few.
 
 
 
=== Multiple Zooming ===
 
Let's try making a movie where we zoom into each ligand that's not water.  In order to make this movie, I had to find a protein with suitable ligands, so you can do the same for your own protein.  Just replace the hard-coded residue numbers.
 
 
 
'''Goal:''' Make a movie that zoom into the three ligands, stays on that ligand for 2 seconds, then moves to the next.  I also want smooth zoom out at the end.  Don't let the length of this movie script throw you off, you've seen all of the movie commands and the initial commands are just loading the and making it look good.
 
<source lang="python">
 
# setup PyMOL for the movie
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
 
 
# load the PDB, make selections for the ligands and
 
# make the protein look snazzy.
 
#load /spc/pdb/2jep.pdb
 
fetch 2jep, asyn=0
 
remove resn HOH
 
orient
 
select l1, c. A and i. 1397
 
select l2, c. A and i. 1396
 
select l3, c. B and i. 1396
 
as cartoon
 
color grey
 
show sticks, het
 
color magnesium, het
 
 
 
# At 30 FPS this is then a 16 second movie.
 
# We look at the structure for 2 seconds, zoom in to each ligand
 
# and look at it for another 2 seconds, then, zoom out and look again
 
# at everything for another 2 seconds.
 
 
 
# initialize the 480 frame movie
 
mset 1 x480
 
 
 
# zoom all ('scene #1')
 
frame 1
 
mview store
 
# stay here for 2 seconds
 
frame 60
 
mview store
 
 
 
# zoom on ligand 1  ('scene #2')
 
frame 120
 
zoom l1
 
mview store
 
# stay here for 2 seconds
 
frame 180
 
mview store
 
 
 
# zoom on ligand 2  ('scene #3')
 
frame 240
 
zoom l2
 
mview store
 
# stay for 2 seconds
 
frame 300
 
mview store
 
 
 
# zoom to ligand 3  ('scene #4')
 
frame 360
 
zoom l3
 
mview store
 
# stay for 2 seconds
 
frame 420
 
mview store
 
 
 
# zoom out  ('back to scene #1')
 
frame 480
 
zoom
 
mview store
 
 
 
# interpolate the frames
 
mview reinterpolate
 
 
 
# play the awesome movie!
 
mplay
 
 
 
# stop when you want
 
# mstop
 
</source>
 
 
 
 
 
 
 
=== Animating an Alignment ===
 
<source lang="python">
 
# setup PyMOL for the movie
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
 
 
# load the PDBs
 
fetch 1cll 1ggz, async=0
 
 
 
# orient the scene
 
as cartoon
 
orient
 
 
 
# make 100-frame movie
 
mset 1 x100
 
# goto frame 1
 
frame 1
 
 
 
# store the camera position and object
 
# positions in frame 1
 
mview store
 
mview store, object=1cll
 
mview store, object=1ggz
 
 
 
# goto frame 90
 
frame 90
 
# align the two proteins
 
super 1cll, 1ggz
 
# we rezoom to center the camera on the
 
# two aligned proteins
 
zoom
 
# store the camera positions
 
mview store
 
# store the new object position(s)
 
mview store, object=1cll
 
mview store, object=1ggz
 
 
 
# have PyMOL stitch together the scenes.
 
mview reinterpolate
 
mview reinterpolate, object=1cll
 
mview reinterpolate, object=1ggz
 
 
 
# rewind
 
frame 1
 
# get some popcorn!  :-)
 
mplay
 
</source>
 
 
 
=== BB Inspector ===
 
This movie will walk down the alpha carbons inspecting each one for 1/3 of a second.  :-)  What would be cool would be to calculate the difference vector from i. n+1 to i. n and then walk that path.  Anyhow, here you go:
 
 
 
<source lang="python">
 
# usual setup
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
 
 
# fetch 1CLL to work on; this will only work on 1cll
 
# or any other protein with 144 AAs starting at resi 4.
 
fetch 1cll, async=0
 
as lines, n. C+O+N+CA
 
color marine
 
zoom i. 4+5
 
 
 
# 10 frames per AA
 
mset 1 x1440
 
mview store
 
 
 
# this code maps the zooming of
 
# one AA and it's neighbor to 10 frames
 
python
 
for x in range(0,144):
 
  cmd.zoom( "n. CA and i. " + str(x) + "+" + str(x+1))
 
  cmd.frame((10*x)+1)
 
  cmd.mview("store")
 
python end
 
 
 
# goto the end and interpolate all the frames
 
frame 288
 
mview store
 
mview reinterpolate
 
 
 
# I know, it's not smooth & cool like the other ones
 
mplay
 
</source>
 
 
 
== Putting It All Together ==
 
Now that we understand the basic PyMOL commands for movie making, we build a few ideas--which have already been hinted at--that lead to the final goal: allowing you to generate PyMOL movies to tell the stories you want to tell.  We start simple and build up the complexity.  Here's an outline of the ideas:
 
* '''camera motions'''&mdash;just moving the camera around your scene
 
* '''object motions'''&mdash;keeping the camera still, but moving the objects around the scene
 
* '''camera &amp; object motions '''&mdash;moving both the camera and objects around
 
* '''representations'''&mdash;changing representations in a movie (eg. sticks to cartoons to surface; hiding/showing, etc.)
 
* '''motions &amp; representations '''&mdash;adding all the motions and representations together
 
* '''extras'''&mdash;pseudoatom labels; scene messages, etc.
 
* '''final example movies'''&mdash;some examples combining the above knowledge
 
 
 
If you've read through most the above article on movie making, then these sections should be more of a review.  There are some tricks in here that might be worth reading, however.
 
 
 
Many of the movie scripts below assume that you have readied PyMOL for movie generation.  To do that use the following code:
 
<source lang="python">
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
set scene_buttons, 1
 
set cache_frames, 1
 
config_mouse three_button_motions, 1
 
 
 
# initialize a 100 frame movie
 
mset 1 x100
 
</source>
 
 
 
===Camera Motions===
 
One of our first movies above was a very simple zoom on an atom in an amino acid.  The first 'scene' was the entire amino acid and the 2nd 'scene' was the zoomed in atom.  We just connected the two scenes and asked PyMOL to make the transition between the two smooth.  This is the idea of camera motions in PyMOL.  (You may not know that when you click on a protein and rotate it or drag it in PyMOL you're actually moving the camera, not the protein.)
 
 
 
Assuming you had readied PyMOL to make your movie to get a camera motion you do the following:
 
* '''save the camera's first position information''': Once you have the protein/object aligned and shown in the representation of your choice, set the '''camera''' position information
 
<source lang="python">
 
# goto the first frame
 
frame 1
 
# store the CAMERA positions ONLY
 
mview store
 
</source>
 
* '''save the cameras second position information''': Now using the mouse (or scripted commands) move the camera to its new position--say zooming in on an important ligand or catalytic residue.  Once that's done, tell PyMOL to store the new camera position in this frame:
 
<source lang="python">
 
# goto the first frame
 
frame 88
 
# store the CAMERA positions ONLY
 
mview store
 
 
 
# now link the two stored camera positions together:
 
mview reinterpolate
 
 
 
# play your movie
 
mplay
 
</source>
 
 
 
Hints:
 
* '''mview reinterpolate, power=1" will turn off the smoothed starting and stopping of camera motions between the scenes.  The smoothing gives a nicer feel to transitions.  Try both, see which you prefer.
 
* check out mview's other options--like 'wrap'
 
* using the three_button_motions option, you can pretty much make the entire movie w/your mouse: All->M->Store is the same as, ''mview store'', and All->M->Reinterpolate is the same as ''mview reinterpolate''.
 
* '''[[mview]] reset''' unstores the camera position information for this frame.
 
 
 
==== Camera Motions Movie Example ====
 
This idea should be pretty sound at this point, but examples rock, so here's another.  The pattern is:
 
* frame XYZ
 
* script the view
 
* mview store
 
 
 
<source lang="python">
 
# setup PyMOL for movies
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
set scene_buttons, 1
 
set cache_frames, 1
 
config_mouse three_button_motions, 1
 
 
 
fetch 1te1, async=0
 
extract AA, c. A
 
extract BB, c. B
 
color marine, AA
 
color grey, BB
 
as surface, BB
 
as cartoon, AA
 
 
 
mset 1 x620
 
 
 
orient
 
 
 
wizard message, "Can you see the blue protein inhibiting the gray protein?"
 
 
 
frame 1
 
mview store
 
frame 30
 
mview store
 
 
 
### cut below here and paste into script ###
 
set_view (\
 
    0.307660401,    0.011366921,    0.951428533,\
 
    0.930296898,  -0.213488042,  -0.298277378,\
 
    0.199727684,    0.976880252,  -0.076255992,\
 
    0.000000000,    0.000000000, -196.781448364,\
 
    27.129878998,  68.309677124,  51.827075958,\
 
  155.143981934,  238.418914795,  -20.000000000 )
 
### cut above here and paste into script ###
 
 
 
# slowly show the inhibition
 
frame 120
 
mview store
 
 
 
# wait 3 seconds
 
frame 180
 
mview store
 
 
 
# define the inhib as the binding loop
 
select inhib, AA and i. 148-155
 
select (none)
 
 
 
# slowly zoom in
 
frame 300
 
zoom inhib
 
mview store
 
 
 
# stop a second
 
frame 330
 
mview store
 
 
 
# look around the binding pocket
 
frame 390
 
turn y, 150
 
mview store
 
 
 
# wrap back more quickly...
 
frame 420
 
turn y, -150
 
mview store
 
 
 
# one more gratuitous view
 
frame 500
 
### cut below here and paste into script ###
 
set_view (\
 
    0.943371952,    0.309539229,  -0.119302809,\
 
    -0.044248745,  -0.239008784,  -0.970008850,\
 
    -0.328769624,    0.920357347,  -0.211777285,\
 
    0.000000000,    0.000000000,  -30.773454666,\
 
    35.418403625,  72.805625916,  52.437019348,\
 
    20.233829498,  41.313076019,  -20.000000000 )
 
### cut above here and paste into script ###
 
mview store
 
 
 
frame 560
 
mview store
 
 
 
mview reinterpolate
 
mplay
 
</source>
 
 
 
===Object Motions===
 
 
 
Now that we're experts at moving the PyMOL camera around, let's start moving objects around while keeping the camera steady.  To do this '''you must have matrix_mode set to 1''', otherwise PyMOL won't save your object's repositioning.
 
 
 
Let's use the same proteins as from the above inhibitor example.  This time, let's try to get a simple movie that shows one of the proteins and then have the other one fly in to do the inhibiting.
 
 
 
<source lang="python">
 
# setup PyMOL for movies
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
set scene_buttons, 1
 
set cache_frames, 1
 
config_mouse three_button_motions, 1
 
 
 
# download the complex and setup it up
 
fetch 1te1, async=0
 
extract AA, c. A
 
extract BB, c. B
 
color marine, AA
 
color grey, BB
 
as surface, BB
 
as cartoon, AA
 
 
 
# intialize the movie
 
mset 1 x410
 
 
 
# orient the scene
 
set_view (\
 
    0.423117876,    0.061672822,    0.903973043,\
 
    0.789699256,  -0.514252067,  -0.334546506,\
 
    0.444237947,    0.855418444,  -0.266292989,\
 
    0.000107866,  -0.000027858, -196.784057617,\
 
    28.171787262,  70.919288635,  52.095287323,\
 
  155.143981934,  238.418914795,  -20.000000000 )
 
 
 
# move the inhibitor off the screeen
 
translate [0,0,100], object=AA
 
 
 
# first movie scene
 
frame 1
 
wizard message, "Let's watch the binder float it, while the camera doesn't move."
 
mview store, object=AA
 
mview store, object=BB
 
 
 
# 2 second pause for the user to catch up
 
frame 60
 
mview store, object=AA
 
mview store, object=BB
 
 
 
frame 300
 
# slide the inhibitor in from over the camera.  :-)
 
translate [0,0,-100], object=AA
 
mview store, object=AA
 
mview interpolate, object=AA
 
 
 
# store & wait 2 seconds...
 
frame 360
 
mview store, object=AA
 
mview store, object=BB
 
mview reinterpolate, object=AA
 
mview reinterpolate, object=BB
 
 
 
# 'explode' apart
 
frame 380
 
translate [-70, 70, 70], object=AA
 
translate [70, -70, -70], object=BB
 
mview store, object=AA
 
mview store, object=BB
 
mview reinterpolate, object=AA
 
mview reinterpolate, object=BB
 
 
 
mplay
 
</source>
 
 
 
Hints:
 
* Use the mouse to get the 'right orientation &amp; zoom'.  Then use [[get_view]] to get the view matrix.  Finally, store that camera-position view matrix in your script.  Works every time.
 
* For object motions, the command '''translate [-70,70,70], object=AA''' would be the same as using the mouse and moving the object AA -70 units on the X-axis, +70 units on the Y and 70 on the Z.  If you don't use the '''object=''' you will not get the desired effect.
 
* For the above 'explosion' you can get quick motions by interpolating a large change over just a few frames.
 
 
 
===Camera &amp; Object Motions===
 
Now let's combine the above two sections into one movie that has both object and camera motions.  This should be cool...
 
 
 
''' FIXME '''
 
 
 
<source lang="python">
 
# setup PyMOL for movies
 
reinitialize
 
set matrix_mode, 1
 
set movie_panel, 1
 
set scene_buttons, 1
 
set cache_frames, 1
 
config_mouse three_button_motions, 1
 
 
# download the complex and set it up
 
fetch 1te1, async=0
 
extract AA, c. A
 
extract BB, c. B
 
color marine, AA
 
color grey, BB
 
as surface, BB
 
as cartoon, AA
 
 
 
mset 1 x120
 
# overview of the scene
 
frame 1
 
mview store
 
mview store, object=AA
 
mview store, object=BB
 
 
 
# zoom into the binding pocket- setting the view means
 
# that this will be a camera motion from frames 1 to 120.
 
frame 120
 
set_view (\
 
    0.993863702,    0.110482253,  -0.005255031,\
 
    0.054543663,  -0.530888498,  -0.845684826,\
 
    -0.096224494,    0.840209842,  -0.533656776,\
 
    0.000000000,    0.000000000,  -50.366786957,\
 
    34.781314850,  71.208221436,  52.535022736,\
 
    39.709556580,  61.024017334,  -20.000000000 )
 
mview store
 
mview store, object=AA
 
mview store, object=BB
 
 
 
# wiggle the inhibitor, like it's trying to escape
 
python
 
for x in range(20):
 
  cmd.madd("1 x3"); cmd.frame(1000);
 
  cmd.rotate("x", 2.0, object="AA")
 
  cmd.mview("store", object="AA")
 
  cmd.interpolate(object="AA",power=1)
 
 
 
  cmd.madd("1 x3"); cmd.frame(1000);
 
  cmd.rotate("x", -2.0, object="AA")
 
  cmd.mview("store", object="AA")
 
  cmd.interpolate(object="AA",power=1)
 
python end
 
mview store
 
 
 
madd 1 x40
 
frame 470
 
mview store
 
mview store, object=AA
 
mview store, object=BB
 
 
 
mview interpolate, object=AA
 
mview interpolate, object=BB
 
mview reinterpolate
 
 
 
mplay
 
 
 
</source>
 
 
 
===Representations===
 
 
 
Scenes are the only way to change representations (eg sticks to cartoon).  In PyMOL to show representation changes we need to have a list of scenes, that we then assign to a given frame.  Once this is done we can reinterpolate through scenes to have beautifully smooth transitions.
 
 
 
PyMOL makes it very easy to setup your scenes--for that ''look''--and save them in a stack (and, now, even move them around).  We covered scenes already in the tutorial, so please check that if you need more help on scenes, or see [[:Category:Scenes]] for more commands and hints.
 
 
 
In PyMOL, to attach a scene to a frame (or, technically a frame to a scene) we simply do the following:
 
<source lang="python">
 
mview store, scene=sceneName
 
</source>
 
 
 
Let's take a look at a simple movie that changes the representation of some object.  This will show a tryptophan going from lines to sticks and back.
 
<source lang="python" line=1>
 
set scene_buttons, 1
 
set movie_panel, 1
 
 
 
# make a 90 frame movie, all STATE 1.
 
mset 1 x90
 
 
 
# load a trypotphan fragment
 
frag trp
 
 
 
# Tell PyMOL to call this current view '001'.
 
scene 001, store
 
# goto frame 1 and store this scene & camera
 
frame 1
 
mview store, scene=001
 
 
 
# setup the next 'view'
 
as sticks
 
scene 002, store
 
 
 
# goto frame 60 and show sticks
 
frame 45
 
mview store, scene=002
 
 
 
mview reinterpolate
 
mplay
 
</source>
 
 
 
To show you how easy adding camera motions + representations is, simply insert after line 17 (''as sticks'') a new line 18 that only has
 
<source lang="python">
 
orient
 
</source>
 
 
 
Here's what's happening in the movie, above.  Lines 1&mdash;2 set PyMOL up to show you [[scene_buttons|scene buttons]] and the [[Movie_panel|movie panel]].  Line 5 makes a 90 '''frame''' movie that only spans the first state.  Line 8 makes the TRP fragment from PyMOL's stored knowledge of residues.  Line 11 asks PyMOL to store this current 'view' as a [[scene]] and call that scene ''001''.  Now that a scene is made, we need to associate with a frame.  So, we goto frame 1 in line 13.  In line 14 we actually make the scene-to-frame assignment with the [[mview]] store command, specifying the mapping between scene 001 and frame 1.  Lines 17 and 18 change the representation from lines to sticks and then orients the TRP residue (which causes the camera to move).  In line 19, we save this new camera position and the sticks representation of TRP in the scene called ''002''.  Next, in line 22, we go somewhere ahead in the movie, here 1/2 way to the end.  Line 23 assigns scene ''002'' to frame 45.  Lastly, because we changed the camera position, we need to reniterpolate it's movement, and that's done in line 25.  As you know [[mplay]] just plays the movie.
 
 
 
* '''Hint''': Clear frames with '''mview clear'''
 
* '''Hint''': Clear scenes with '''scene sceneName, delete'''; you can delete all scenes with '''scene *, delete'''.
 
 
 
 
 
Now that we have that, let's learn more complex tricks with motion and representations!
 
 
 
===Motions &amp; Representations ===
 
 
 
Let's look at the inhibitor complex again, (pdb 1TE1).  This time, we would like to make a more compex movie that shows moving objects (not the camera) and changing representations.  I do not want wrapping b/c I slide the molecule off the sceen.  To ensure that, I allow 0 transition frames, by setting the last frame in the movie  by '''mview store'''.
 
 
 
<source lang="python" line=1>
 
# b/c there will be motions, we need matrix_mode
 
reinitialize
 
set matrix_mode, 1
 
set scene_buttons, 1
 
set movie_panel, 1
 
 
 
# setup the movie for 410 frames
 
mset 1 x240
 
 
 
# load the complex & set it up
 
fetch 1te1, async=0
 
as cartoon
 
remove resn HOH
 
extract AA, c. A
 
extract BB, c. B
 
 
 
# zoom in on the binding pocket
 
### cut below here and paste into script ###
 
set_view (\
 
    0.478582859,  -0.269358903,    0.835705996,\
 
    0.805654645,  -0.243718535,  -0.539927721,\
 
    0.349110991,    0.931690335,    0.100370787,\
 
    0.000000000,    0.000000000,  -49.810981750,\
 
    35.418403625,  72.805625916,  52.437019348,\
 
    39.271358490,  60.350605011,  -20.000000000 )
 
### cut above here and paste into script ###
 
 
 
# store object AA's position
 
frame 1
 
scene 001, store, message="This doesn't quite give us a good feel for what's going on."
 
mview store, object=AA
 
mview store, scene=001
 
 
 
# change up the scene a bit
 
frame 60
 
color grey, AA
 
color marine, BB
 
scene 002, store, message="Recoloring helps a little."
 
mview store, scene=002
 
 
 
# show chain B as surface
 
frame 120
 
as surface, BB
 
mview store, object=AA
 
scene 003, store, message="Surface helps alot."
 
mview store, 120, scene=003
 
 
 
# show more
 
frame 180
 
select inhib, AA and i. 148-155;
 
show sticks, inhib
 
color magenta, inhib
 
select nn, BB within 7 of inhib; deselect;
 
set transparency, 0.65, nn
 
show sticks, nn
 
set_bond stick_color, chartreuse, nn
 
scene 004, store, message="Coloring, transparency, and other objects help more..."
 
mview store, object=AA
 
mview store, 180
 
 
 
# move AA away
 
frame 240
 
translate [20, 10, 80], object=AA
 
mview store, object=AA
 
mview reinterpolate, object=AA
 
mview store, 240
 
mview reinterpolate
 
 
 
</source>
 
 
 
 
 
* '''Hint''': Use '''mview store, frameNo, scene=sceneName''' to save complex scenes.  If you do:
 
<source lang="python">
 
frame X
 
scene Y
 
mview store X, scene=Y
 
</source>
 
then the PyMOL GUI may not have caught up to the correct place before saving the scene information.
 
* '''Hint''': Things can get confusing with frames, states and whatnot.  A good idea is to ALWAYS set your frame when setting a new scene.  If you don't '''mview store''' might save a different frame number than you think you're on.  Or, you can save the frame number too with, '''mview store, frameNo, scene=XXX, object=YYY'''.
 
* '''Hint''': Use [[deselect]] in a script to hide the dots from making a new selection.
 
* '''Hint''': Use [[set_bond]] to set bond properties, like colors, on [[sticks]] representations.
 
 
 
=== Extras ===
 
 
 
== Exporting your Movie ==
 
This wiki already has lots of information on how to convert your PyMOL movie to another format.  Check out [[Making_Movies|those]] [[Software_Codecs|pages]].
 
 
 
Once you've setup your movie as in any of the previous examples, you have a couple options for making a movie.
 
 
 
'''Export from PyMOL''': Newer PyMOLs support
 
*File->Save Movie As->MPEG
 
*File->Save Movie As->PNG Images
 
from the menu.
 
 
 
'''mpng''': You can still use the good old [[mpng]] option to save all your frames to disk.  You can then compile them into a MPEG (see below).
 
 
 
'''Old Style''': One of the older scripting styles was to make minor changes and dump PNGs.  This is essentially obviated with PyMOL's new movie-making functionality.  The '''old style''' was to simply call cmd.png every time you made a scene change.
 
 
 
Hints:
 
* Movie not ray traced?  Make sure you set ray_trace_frames to 1.
 
 
 
=== Codecs ===
 
See [[Software_Codecs]] for information on how to stitch together movies from PNGs and optimize them for great crisp-looking movies.
 
  
 +
* [[MovieSchool_6|Exporting & Using your Movie]]
 +
:: Using your movie, once it's made
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:Movies]]
 
[[Category:Movies]]

Latest revision as of 10:02, 1 September 2009

PyMOLWiki's Movie School

Welcome

Here you will learn all the latest and greatest techniques for making movies in PyMOL. These make you look like a master of PyMOL when you can show them off in a presentation or even in MPEG/AVI format. For your ease of learning I have commented all of the movie scripts and tried to ensure that they work in PyMOL if you just copy/paste the code.

If you have any comments on this tutorial, please feel free to add them to the discussion page. If you have corrections, improvements or additions, as always, please feel free to improve the pages.

  • NB: While this is pretty expansive (hence the 6 lessons) it is still incomplete and surely rough in some places.
  • NB: Make sure you have the newest PyMOL v1.2r0.

Movie Making Roadmap

The basics; movies in 60 seconds.
Definitions; commands; settings;
Using the GUI to make movies
Easy copy/paste examples
More advanced examples; using states, scenes, and object motions
Using your movie, once it's made