How to generate an animation out of protein rotation in VMD
Table of Contents
Here is how you can animate a protein rotation in VMD. For the gif file shown below, I used the result from cavity water visualization of ABC transporters described in this tutorial.
1 Snapshots in VMD
We need to rotate the protein in a loop to by one degree and make a snapshot of each rotation step. You need to paste the following function in Tk console of VMD:
proc make_rotation_movie_files {} { set frame 0 for {set i 0} {$i < 720} {incr i 2} { set filename [format "%04d" $frame] render snapshot $filename incr frame rotate y by 1 } }
Once we define this function, we can call it using:
make_rotation_movie_files
The files are saved in the current directory without any file extension. This is because I found that the function does not work correctly under GNU/Linux when you have it defined. In windows however, you can do the following:
proc make_rotation_movie_files {} { set frame 0 for {set i 0} {$i < 720} {incr i 2} { set filename snap.[format "%04d" $frame].jpg render snapshot $filename incr frame rotate y by 1 } }
This generates 360 images for you with the tga format.
2 Making a gif under GNU/Linux
We need to retrieve the file extensions. In GNU/Linux run the following command in the folder with generated pictures:
ls -1tr * | while read filename; do mv $filename $filename.tga; ((counter++)); done
We need to convert these files to jpeg:
mkdir converted ls -1tr *.tga | while read filename; do convert $filename converted/$filename.jpg; ((counter++)); done
And finally, we merge all of them to a gif file:
convert -fuzz 1% -delay 1x30 -loop 0 *.jpg -coalesce -layers OptimizeTransparency apoFinal.gif
If you want to decrease the gif size, do the following:
gifsicle -U apoFinal.gif --delay 3 `seq -f "#%g" 0 6 359` -O3 --colors 128 --scale .5 -o apoOptimized2.gif
Here you can remove some frames. This is what `seq -f "#%g" 0 6 359`
does, it takes every sixth frame for final file. --colors
decreases the number of colors and --scale
scales with the factor written in front. Also -O3 optimizes the gif file as much as possible.
3 Making a video under Windows
To do all these steps in windows, you can install VirtualDub software. Open first file and export as avi.