Creating GIF animations of protein molecules with PyMOL

PyMOL is an open-source molecular visualization system useful for producing high-quality figures of protein structures. Besides static figures, PyMOL can also generate animations with the mpng command that writes movie frames to separate files. However, mpng provides no options to customize the produced images. Here we describe an appoach to get a customized looped animation in PyMOL and present a Python script implementing it. The script is based on Maximilian Ebert’s solution from the PyMOL mailing list.

PyMOL script to get animation frames

Following the PyMOL scripting guide, I composed the Python script that produces a series of PNG files for protein structure states (frames).

To use the script, one must import it to PyMOL using the run command in the PyMOL command line. Unlike mpng, a user can specify width and height of the frame PNG files.

Combining frames to a single file

Given a series of frame files in the PNG format, we can combine then to a single animated GIF file using the ImageMagick software suite. For a series of PNG files named from frame001.png to frame010.png, the following bash script will produce a looped animation GIF file.

for I in $( seq 1 $(( N - 1 )) ); do
cp "${PREFIX}$( printf %03d $(( $N - $I )) ).png" \
   "${PREFIX}$( printf %03d $(( $N + $I )) ).png"
convert "${PREFIX}*.png" animation.gif

The variable N denotes the number of frames in an animation and PREFIX is the first part of their filenames. The lines 3-6 copy all the frames except the last one to create a looped animation.

Example: SSADH animation

To illustrate the presented approach, we will get the GIF animation file of the human succinic semialdehyde dehydrogenase (SSADH) protein transformation described in my paper. The PDB file of the transformation is given in the Supporting Information item prot24937-sup-0004-suppinfo04.pdb.

First, we launch PyMOL, import the script and obtain the frame PNG files.

load prot24937-sup-0004-suppinfo04.pdb
show cartoon
hide lines
mpngAdvanced(800, 800, "ssadh")

Next, we process the frame PNG files in bash using the script given above which PREFIX variable was changed to ssadh”. Here is the resulting GIF file.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s