Linux Setup Notes

name and address
created jul 12, 2008; updated apr 16, 2010

Creating Animated Molecule Movies in Chimera

PDB Files and Molecular Modeling Software

Molecule displayed in Chimera Chimera output, using POV-ray raytracing

E ventually, almost every chemist will need to include an image of some kind of molecule in a PowerPoint presentation. The best way to convey the true shape of a molecule is with a rotating three-dimensional model. Since PowerPoint is the common standard for presentations these days, that means you have to make a movie.

The first step in making a movie of a molecule is to obtain a PDB file. PDB files can be downloaded from a number of places, including www.rcsb.org/pdb, or they can be created using a molecule editor (see below). Even though PDB is a text format, you can't just create a PDB file by hand; it must be optimized with Ammp, Mopac (a closed-source, commercial program), or some other software algorithm to find the correct energy-minimized structure. Don't bother with molecule formats other than PDB; some of them don't uniquely describe a molecule and will happily convert your carefully crafted molecule to a chemical abomination from hell.

Next, you need some molecular modeling software or a molecule viewer. The three best ones to my knowledge are Chimera (Linux, Windows, OS X, Irix, HP Tru64 Unix, and FreeBSD), Viewmol (Linux, FreeBSD, SunOS, AIX, Irix), and Vmd (Linux, OS X, and Windows). Chimera is the best for making movies because it has scripting, which is essential for smooth movement. Best of all, Chimera is free. It was developed under an NIH grant--which means, if you're an American taxpayer, you paid for it already, probably several times over.

For general molecule rendering, these other software packages may work. I have only minimally tested them.

  1. Swiss PDB viewer (deepview) (Windows/Mac only)
  2. moilin (Windows only)
  3. yasara (Linux, Windows, OSX)
  4. ymol (Linux, Windows, FreeBSD, IRIX, OSF/1, ULTRIX, AIX, Solaris, HP-UX) (I could not get it to compile in Linux).
  5. pymol (Linux, Windows, Mac) - would not compile in Linux Suse 10.0 but compiled in older versions. To compile and run pymol, issue the following commands:
    su
    python setup.py install
    python setup2.py install
    exit
    ./pymol

If you want to create a new molecule, you need a molecule editor that can create PDB files, like one of these:

  1. VegaZZ (Windows only) - An easy to use viewer. Even though it only handles one molecule at a time, you can use VegaZZ to interactively create a molecule and optimize its 3D structure, then save the result as a PDB file. It is free, but unfortunately the program is spyware: it contacts the vendor over the Internet every time you start it up. It is also drop-dead software: the registration expires after one year, forcing you to re-register. When the company disappears, your copy will automatically stop working. It also stops working if you upgrade your PC. My experience has been that sometimes it works, sometimes not. Best not to get dependent on it.
  2. ICM Browser Pro (commercial)
  3. Amira (commercial)
  4. JME - a crude web-based 2D structure editor. Doesn't create PDBs.
  5. Webmo - is difficult to install. This software is a bunch of cgi scripts, and it's necessary to change your webserver configuration to install it.

Displaying a molecule in high resolution in Chimera

Next, get the molecules to their starting position. It's essential to make the resolution as high as possible, because when it's converted to an MPEG or MP2 to accommodate the limitations of Windows, much of the resolution will be lost. These are the settings I use to make high-resolution molecules in Chimera:

  1. File → Open for each molecule
  2. Favorites → Model Panel. This can be used to link or unlink two or more molecules.
  3. Make the molecules as big as practicable and rotate to their starting position.
    left mouse = rotate
    center mouse = translate
    right mouse = scale
  4. Presets → Interactive → All atoms. Activates the ability to set the color of carbon atoms.
  5. Actions → Color by Element. Sets each element to a different color.
  6. Favorites → Model Panel. This is the control panel that determines whether to rotate one or both of your molecules, and also sets their properties. Click on the small colored box next to 'ID' to change the backbone color of the desired molecule.
  7. Actions → Atoms → Bonds → Ball and Stick.
  8. Tools → Viewing Controls → Lighting - make molecule less bright
    • Increase key to fill ratio to 8
    • Depth Cueing on, Start Ratio 0.98
    • Subdivision Quality 20
    • Rotation Center of Rotation Method = Center of Models
  9. Model panel → Attributes → Ball Scale = 0.3. This makes the spheres bigger.
  10. Actions → Color → Click 'Background' → Click Dim Gray. If you click a color first, your molecule is messed up, and you have to re-start from the 'presets' step.
  11. Session → Save → Mymolecule.py. Save the session in case the result is no good.
  12. To save an image for publication, use File → Save Image → Retrace with POV-Ray = True. This will create a PNG file. Never use JPEGs for any type of scientific or technical image.

Creating a movie in Chimera

phosphate Animated rendering of a simple phosphate molecule. Click on image to view or download movie (MPEG format).

Once the molecule is displayed at the highest possible resolution, create a command script to rotate the molecule while creating a movie file. This is essential for getting smooth movement. The alternative, rotating the molecule by hand and saving each frame, is too time-consuming to be practical.

This should be done on a fast computer, because it can take several hours to create a ten-second movie.

  1. Edit a text file named movie.cmd. You must use MPEG if movie will be used in PowerPoint. Even though some newer versions of PowerPoint might be able to handle mp4 files, you cannot always predict what computer your presentation will be run on. For example, Office 2000 can only handle MPEG and MP2. The other three options (AVI, MP4, and MOV (Quicktime)), which provide much higher quality, don't work. Even this low standard requires Windows XP for the movie to be displayed. In Windows 2000, it's very difficult to play any kind of movie in PowerPoint.
    Another problem: a presentation created on one version of PowerPoint may hang on another version if it contains a movie. Also, although PowerPoint doesn't warn you about this, the original mpeg file has to be in the same location that it was when you inserted it, or the animation won't run. In other words, your MPEG is not included in the PowerPoint file.
  2. Here is a minimal movie.cmd file:
    # Anything after a '#' is a comment
    movie record framerate 10 raytrace true
    wait
    turn y 3 120
    wait
    movie stop
    movie encode mformat mpeg bitrate 4000 output mymovie3.mpeg

    A complete list of commands is at: http://www.cgl.ucsf.edu/chimera/docs/UsersGuide/framecommand.html

  3. Open the text file 'movie.cmd' as a command file. The movie is created and saved automatically in the specified filename.
  4. Don't touch your keyboard or mouse until Chimera is done, or an error message will pop up and Chimera will stop.

Notes

Creating a movie in Linux

It's also possible to create a movie from individual image frames. This can be done with ffmpeg. See http://electron.mit.edu/~gsteele/ffmpeg/ for more details. However, ffmpeg is very user-unfriendly and its documentation, quite frankly, sucks. Basically, you must use a "%0nd.jpg" (where n is the number of digits in your filename) to specify the input files, and your files must be numbered sequentially. Using "*.jpg" will not work. Even though the "%nd" looks like a shell wildcard, it's not; ffmpeg is not using the shell. The specifier "%05d" is C for a five-digit integer padded on the left with zeroes.

For example, if chimera hangs or crashes, you can still create a movie from the files left behind in /tmp, using the following commands:
cd /tmp
for f in *png ; do convert -quality 100 $f `basename $f png`jpg; done
ffmpeg -b 4000 -i chimovie_cxva-%5d.jpg test.mpeg

(The four letters 'cxva'will be different each time you run Chimera.) Although it doesn't seem to be documented anywhere, ffmpeg uses the extension of the output file specified to determine what to create. The "-b 4000" sets the bitrate; setting a large value is essential to get acceptable quality. A value of 4000 is a good compromise between file size and quality. Another useful command line option is '-r', which sets the frame rate. However, this only works in later formats such as mp4, not mpeg.

Here's another example:

  1. Convert all images to jpegs with 100% quality:
    for f in *png ; do convert -quality 100 $f `basename $f png`jpg; done 
  2. Use ffmpeg to convert to mp4. The filenames must contain a fixed number of sequentially ordered digits (e.g., abc001.jpg for frame 1, abc002.jpg for frame 2, etc). The first example creates an mp4 with 10 frames per second and 1800 kbps. The second creates an mpeg at the default rate (25 fps, 200 kbps).
    ffmpeg -r 10 -b 1800 -i %03d.jpg test.mp4 
    ffmpeg -i %03d.jpg test.mpeg
         
  3. Use a media viewer or download Quicktime from Apple to view the image.

Problems

Unable to create a movie. Chimera says, "Usually this means your image files are corrupted."

Solution: The numbers in the filenames must begin with 1. For example, if your ffmpeg command specifies chimovie_ABCD-%5d.jpg, the first filename must be chimovie_ABCD-00001.jpg. The reason for the filenames being wrong is usually that Chimera crashed in the previous attempt and left the image files in /tmp.

What file formats are supported?

Type ffmpeg -formats for a list. Type ffmpeg -h for a summary of options.

Powerpoint animation plays on the computer, but does not move when shown on the projector.

Solution: There are several possible causes for this:

(1) The movie may be in a different location. In PowerPoint, movies are not stored in the .ppt file. Only a link to the movie file is stored, along with the first frame. This means the movie must be in the same location it was in when the Powerpoint was created, or it will not be found and there will be no animation. The solution is to copy the movie to a memory stick and insert this copy into your powerpoint.

(2) Not enough video memory. On many laptops, activating both the projector and the laptop screen at the same time uses too much memory, and the movie will not be animated. Turn off the laptop display (usually Fn-F5).

(3) The powerpoint may have been created in an old version of Powerpoint or in Windows 2000, which is no good for movies.

(4) The movie may be in the wrong video format. Always assume the lowest common denominator, which at the time of this writing is Windows XP. XP can only handle mpeg.

ΨΩd   ʕ▽王  ∠ηᚆ ႶθΨ

Back