Making animations and images with Pymol


Animation made using PyMol
Animation made using PyMol

PyMol is one of the best open source software for visualizing the bio-molecules.  Still many computational chemists, don’t use it for day -to-day  modelling or for generating a high quality images and animations, partly because other software (such as Molden, Gaussview) can generate figures very easily although with not such a good quality and with limited number of representations. I was one among them, so I thought of exploring it and infact stunned by the abilities of Pymol. In this post I will be presenting a code to generate an animated gif and a high quality ray-traced png file.

The best way I found to deal with  not so friendly Pymol is through its command line interface. All the commands should be placed in commands.pml file and then it should be run using the following command.

  • pymol -c commands.pml

Pymol code

The next step is to see how to write the code.  Most of the commands are similar to python programming language and its surprisingly as shown below.

load test.pdb
hide all
reset
select qplex, resid 4-6+10-12+16-18+22-24
select ligand, resname 1-3+7-9+13-15+19-21+25+26
show sticks, qplex
show spheres, qplex
rotate y,90
set sphere_scale, 0.2
set stick_radius,0.15
bg_color white
set antialias,1
set depth_cue, 0
mset 1 x360
util.mroll(1,360,2)
set ray_trace_frames=1
set cache_frames=0
mclear
mpng mov

Have a close look, the commands look like a conversation with the PyMol. When you run the code it generates a lot of png files. Now convert these png files to either animated gif file (using convert *.png animated.gif command)or a .mp4 or .mov (using ffmpeg or avconv command) files. You will get a gif similar to the one above. I used the pymol command examples from the PyMol wiki to make this command file, so explore it and share if you make something new . Hope it’s useful for you.

*** Most important thing to know is the structure of .pdb file format and the more you know about it, easier it will be to handle PyMol. 

Making animations and images with Pymol

One thought on “Making animations and images with Pymol

  1. Andrey R says:

    This was quite helpful, thanks! On a 12-core i7 circa 2018 it took about 3 seconds to write a 120-frame stack of PNGs, and gif is a good compromise (no need to mess around with codecs etc)

Leave a comment