PLAYMOL LOGO
 

pyMol - Protein Builder Animation

I have recieved some requests to share how I made the Protein Visualization using pyMol movie. So, that is just what I am going to do. The tutorial is quite general so that you can add your own style to it once you get the hang of it.

Making this kind of animation without a trajectory can in principle be devided into 3 parts:

  1. Choose how to represent the protein.
  2. Write a python script to create a series of images.
  3. Making the animation based on the image series.

In this tutorial I will use a small, but well known, enzyme called Lysozyme. Download lysozyme with pdb entry 1FSJ from The Protein Data Bank and load it in pymol. Alternatively, you can download it directly from pyMol with the fetch command. Then prepare the file so that it has no pdb header or any water molecules/ions (we do not need these). Open pymol and type in the command field:

  1. PyMol> fetch 1FSJ

    or if you downloaded the file:

    PyMol> load 1fsj.pdb

  2. PyMol> save lysozyme.pdb, 1fsj and not (resn HOH or resn NO3)

  3. PyMol> delete 1fsj

  4. PyMol> load lysozyme.pdb

Now you should have a clean pdb file without any of the crystallographic information that we do not need for this purpose.
Lysozyme without solvent.

1. Choosing how to represent the protein

The first thing to do is deciding how to represent the protein. This will totally depend on what your preferences are and what you think looks the best. A good start is therefore to play around with your structure in pymol (you can get some tips from pyMol - the basics tutorial) until you find a combination of colors etc. that you are happy with. We want the Lysozyme to build up to look for example like this:

How we want to represent the protein in the animation.
Here I have represented the protein with blue helices, yellow sheets and gray fat loops with rounded edges. To get this representation in pyMol, type the following in the command field:
  1. PyMol> set cartoon_color, gray, ss l

  2. where 'ss' stands for 'secondary structure' and 'l' for loop.
  3. PyMol> set cartoon_color, yellow, ss s

  4. where 's' stands for 'sheet'.
  5. PyMol> set cartoon_color, skyblue, ss h

  6. where 'h' stands for 'helix'.
  7. PyMol> set cartoon_loop_radius, 0.5

  8. for fatter loops.
  9. PyMol> set cartoon_loop_cap, 2

  10. for rounded loop edges.
    Finally, to see the result:
  11. PyMol> hide lines, all

  12. PyMol> show cartoon, all

Notice that we have used the 'set' command. We could have used 'color' to color the object, but then we would have to specify this over and over again for every object. By using 'set' we create a default for the representation cartoon which all objects will inherit.

Now, what we really want to do is to display one residue at the time until the entire enzyme is visible. This will give the impression of a growing enzyme. Just to give you an idea on how this works, try to type the following:

  1. PyMol> hide all

  2. PyMol> show cartoon, lysozyme and i. 1-2

  3. PyMol> show cartoon, lysozyme and i. 3

  4. PyMol> show cartoon, lysozyme and i. 4


  5. ...and so on ...
So, this would have to be repeated until the entire Lysozyme is visible, of course saving a snapshot for each round. This would have been extremely boring and time consuming. Luckily, with just a bit of python coding, all of this can happen while you spend you time on something more interesting.

2. Python script

PyMol and Python are like a hand in a glove, and you do not need to be an expert in the python language to take advantage of it together with pymol. If you know the pyMol commands for what you want to do, you are already off for a good start.

Let us start by making a script that can automatically displays the Lysozyme as above, but without typing all those commands everytime you start a new pyMol session. Open a text editor like textedit, gedit or notepad for example and type the following:

from pymol import *

cmd.set('cartoon_color','skyblue','ss h')
cmd.set('cartoon_color','yellow','ss s')
cmd.set('cartoon_color','gray','ss l')

cmd.set('cartoon_loop_radius','0.5')
cmd.set('cartoon_loop_cap','2')

cmd.hide('lines','all')
cmd.show('cartoon','all')

Save the file as 'settings.py' (or whatever you want, as long as it ends with '.py') in the directory where you launched pyMol. In pyMol, type the following commands:
  1. PyMol> reinitialize

  2. PyMol> load lysozyme.pdb

  3. PyMol> run settings.py

If everything went well, you will now have the same representation as we created above. Now, I guess you can see how this can become handy in the long run.

The next step is to write some code that can display one reisdue at the time and save a snapshot of it until the entire enzyme is visible. Lysozyme consists of 130 residues, so we are going to create 130 images. All we need to do here is to write a loop that cycles 130 time. The quasi code for this would look something like (this is not the actual code, just a more readable scetch):

for residue in range 1 to 130:
  display residue
  save image

And that is basically it. Before the loop starts we put the settings that we wrote in 'settings.py' so that the enzyme is displayed the way we intended too.

Write the following script and save it as 'createImages.py':

from pymol import *

cmd.set('cartoon_color','skyblue','ss h')
cmd.set('cartoon_color','yellow','ss s')
cmd.set('cartoon_color','gray','ss l')

cmd.set('cartoon_loop_radius','0.5')
cmd.set('cartoon_loop_cap','2')

cmd.hide('lines','all')

img=0

def fileName(n):
  if n < 10:
    image='000'+str(n)
  elif n < 100 and n > 9:
    image ='00'+str(n)
  elif n > 99 and n < 1000:
    image = '0'+str(n)
  elif n > 999:
    image = str(n)
  return image

for i in range (1,131):
  newRes=int(i)
  img = img + 1
  image = fileName(img)
  cmd.show('cartoon','i. %i' %newRes)
  cmd.ray('400','400')
  cmd.png(image)
  print 'Image %i written' % img

Once you get the hang of this, you can modify the script to do whatever you like. Explaining all the python syntax is not in the scope of this tutorial. If you have questions about it, please use the forum or follow the upcoming Python tutorials.

In pyMol, write the following commands to run the script and generate the images:

  1. PyMol> reinitialize

  2. PyMol> load lysozyme.pdb

  3. Orient it as you would like it to appear.
  4. PyMol> run createImages.py

This will take a minute or two, depending on your machine speed. Now you have created a series of images. All that is left is to combine them into movie.

3. Making the animation

Now you have a series of images (0001.png ... 0130.png) that needs to be animated. There are several tools for doing this, such as QuickTime, iMovie, adobe premiere etc. Personally I prefere ImageMagick for creating gifs or FFmpeg to create mp4.

If you decide to use ImageMagick to create a gif animation, open a terminal window and type the following code in the directory where your image series is located:

convert -set delay 3 -loop 0 -scale 100% *.png Output.gif

Animation
That is it! If you have any remaining questions, please use the forum .

Happy modeling!