Up

Creating Movies with PyMOL

Any molecular visualization program allows the user to save individual views of a structure into a set of image files. These image files can then be converted into one movie file. The difference between programs lies in the ease of automation, and the level of control over the creation of image files. With PyMOL, thanks to the underlying Python-based language, you easily perform simple tasks. For example, it is easy to create a movie of a rotating or a rocking molecule. Furthermore, with some more effort you can create complex sequences of images that zoom in to specific regions, highlight interesting aspects, or convey the sense of dynamics in the system. Using external tools to manipulate the geometry of molecules (e.g. molecular dynamics) or interpolate between two experimental structures (e.g. morphing between the R and T state of hemoglobin) one can create animations that provide an approximate representation of conformational changes when a ligand binds to the protein.

Fortunately, there are several excellent tutorials online that demonstrate how to create movies with PyMOL. We will learn how to create a simple movie of a small rotating helical peptide. This is a low-cost movie: you need PyMOL (free), ImageMagick (free), a movie player (free), and an operating system (free if you choose wisely). To make thinks little more interesting, we will first custom-build the peptide.

Get your actor and (un)dress it to your preferences

You get to direct a movie that rotates the peptide! To be a successful movie director, you need attractive actors ... and think about the message that you want to deliver to your audience. We worry about getting attractive actors first.

  1. Under Build, select Residue, then pick Helix.
  2. Build a peptide (10-12 amino acids) of your choice by successively selecting amino acids from Build, Residue. You are trying to get a nice alpha helix, so avoid prolines.
  3. Notice that the N-terminus and the C-terminus are not complete. We'll fix the N-terminus first. Change to the Mouse Editing Mode and click on the N-terminal nitrogen atom. Then select Make (pk1) Positive from the Build menu. Now, select Fill Hydrogens on (pk1) to create a proper NH3 group at the N-terminus. Fixing the C-terminus is a little different. Click on the C-terminal carbon to select it as (pk1). Now type attach O,2,2 to add the oxygen atom with two valences. Click on the selected carbon to deselect it.
  4. From the right-hand toolbox, under Actions, select assign sec. struct., then show the peptide backbone as a cartoon with atoms shown as lines.
  5. From the Settings menu, pick Edit All. This menu allows you to customize almost everything about how PyMOL behaves. Double click cartoon_transparency, and enter a value of 0.4. Double click on cartoon_oval_length and enter a value of 0.9. Hit Done.
  6. Type show sticks, name c or name o or name ca or name n or name h at the command line to emphasize the backbone atoms.
  7. Type dist (name o), (name h), 1.8 to show the hydrogen bonds in the backbone. Type hide labels.
  8. Type hide lines, elem h and (neighbor elem c) to hide nonpolar hydrogens.

Let the play begin!

OK, on with our Molecular Hollywood! To be a successful movie director, you also need to know how to "speak the speak". Few key words to remember are "states" and "frames". After you figure this out, all you have to do is to yell, "mrock" or "mroll", and shoot.

  1. Orient the molecule such that the helix is vertical.
  2. Predefine 180 movie frames, each showing the state 1 (we have only one structure, thus one state) by typing mset 1,180
  3. Use a predefined action, in this case rotating the molecule for one full turn (or walking the camera around the object for one full term) and snapping 180 evenly spaced frames, by typing util.mroll 1, 180, 1
  4. We will raytrace the frames to create a slicker image: set ray_trace_frames, 1
  5. No need to cache frames in memory while shooting a movie: set cache_frames, 0
  6. Under the File menu, select Save Movie. Create a new directory, e.g. PNG in a suitable location. Under Windows, Desktop could be used. Save the sequence of PNG file with a unique file name, e.g. helix in this directory. Hit OK; the PyMOL is ray tracing every frame and writing it into a PNG file. Sit back and relax ... or browse the pretty pictures behind this link.
  7. Minimize PyMOL.

This little thing before we can claim our Oscars

Converting a sequence of images into a movie can be achieved by many different means depending on the operating system and the available software. A free cross-platform converter and editor is provides by the ImageMagick suite of programs (thanks to J. Cristy, ImageMagick Studio LLC). In particular, the mogrify program can annotate a sequence of images, and the convert program will create an MPG movie with the help of the free mpeg4encode program. Under Windows, open a Command Prompt from Accessories. Navigate to the directory where the PNG files are (C:\"Documents and Settings"\blake.gillespie\Desktop\PNG), and type something like:

  1. mogrify -draw " text 20, 30 'Hello, world!' " -fill yellow -pointsize 18 helix005* helix010* helix015*
  2. convert -quiet -delay 1 *png helix_mov.mpg
  3. Play the movie file by double-clicking on the image file.

Somehow, the ImageMagick installation here does not recognize the PNG files … Arghhh!. A temporary workaround is to use the Photoshop to convert the PNG files into JPG via the Web Photo Gallery in the File, Automate menu. Define the source and destination directories for images, and hit OK. Wait until the conversion is done, then navigate to the directory that contains the JPG files (e.g. JPG/images) and type:

  1. mogrify -draw " text 20, 30 'Hello, world!' " -fill yellow -pointsize 18 helix005* helix010* helix015*
  2. convert -quiet -delay 1 *jpg helix_mov.mpg
  3. Play the movie file by double-clicking on the image file.

This was a pretty good start, your inner critic probably says now. But you can do a lot more. With only little more practice, you could create movies like this this protein helix or this DNA double helix. Somewhat more complex examples can be seen at Cooperativity in Proteins page.

To work with more advanced movies, the following resources will be helpful: