/******************************************************
// Jmol generated povray script.
//
// This script was generated on :
// Thu, June 19, 2003 at 10:48 AM
//
// Frame comment:SCF Done: E(RHF) =
-262.282442230 A.U. after 12 cycles
//******************************************************
//******************************************************
// Declare the resolution, camera, and light sources.
//******************************************************
// NOTE: if you plan to render at a different resoltion,
// be sure to update the following two lines to maintain
// the correct aspect ratio.
#declare Width = 320;
#declare Height = 240;
#declare Ratio = Width / Height
#declare zoom = 2.9692285;
You'll notice that the background in the previous image is white and only the molecule is present. At this point we no longer use Jmol and focus only on POV-Ray. There are a few things to take care of to work with POV. We have to define a povray.ini file, this will come in pretty handy when doing the animation. You should have a povray.ini file in your working directory with at least the following variables:
The Jitter, *_Frame and *_Clock variables will take different values when we are ready to do the animation. Notice the Output_File_Type = P, specifying a ppm type file. We need ppm files to feed to the netpbm utilities later on.
You can leave the white background like that, or you could add things like a sky sphere or a checkered plane, if only to give the eye a few more reference points. In my case, I wanted to illustrate how the movement preserved symmetry elements, and that meant adding mirror planes. To make it evident that I had a mirror plane, I needed to add more reference points, thus the sky and the plane. See an example:
This image is in PNG format, because raytraced images generate many more colors than the GIF format can store. It is possible to generate GIF images, but you have to quantize the colormap (see "Creating an animated GIF") and then you would see color banding in the final GIF, like this:
The banding is evident mostly on the red atoms and a little bit in the sky above the horizon.
The next step is to add movement to the molecule. Remember that we are animating a vibrational mode. For this, we need the atomic x,y,z displacements calculated by our quantum chemistry package. They are usually provided in a form like this:
We only need the numbers under the X, Y and Z columns. We know that atom number 1 (the carbon atom) has a displacement of 0.29 Bohr along the Y axis in this vibrational mode. So the first thing we do is open our pov file, locate the carbon atom coordinates, and add that displacement to the y coordinate:
/***********************************************
// List of all of the atoms
//***********************************************
make_C_atom( 0.0, -0.3+(SineTime*0.153), 0.0)
[snip,snip]
Do not forget that Jmol exports distances in angstroms, but the displacements are in Bohr, so we need to convert the units. You can see that 0.29 Bohr = 0.153 Angstrom. We do the same for all the coordinates for all the atoms. But... hold it! What is this "SineTime" factor that multiplies the displacement? This is actually the heart of the animation. POV-Ray defines a "clock" variable to do animations. For more details, see the POV-Ray manual.
To animate things, we need to couple the change in coordinates to the clock variable so we have a full displacement in one clock cycle. The way I do this is by defining SineTime:
#declare SineTime = sin(clock*2*3.141592);
This way, the displacement is applied gradually in a cyclic fashion, and the end point is the same as the starting point, yielding a smooth movement.
Now, to produce the frames for animation, we need to change a few things in the povray.ini file:
Antialias = on
Jitter = off
Initial_Frame = 0
Final_Frame = 30
Initial_Clock = 0.0
Final_Clock = 1.0
Of course, the number of frames is your choice. Notice the assignment "Jitter = off". This is to avoid an annoying effect due to part of the antialiasing process. See the POV-Ray manual for details.
After running povray <pov filename>, we end up with 30 ppm files that we want to put together as a MPEG video or an animated GIF. It is a good thing that POV-Ray generates the filenames automatically, by appending the frame number to the input file name. So, if my pov file is named 718.pov, POV-Ray generates 31 files named 71800.ppm to 71830.ppm
To generate the MPEG video, we need ppmtompeg. Use of ppmtompeg is fairly complex, because it requires a parameter file that defines the frames to take, how to encode them and a bunch of (to me) esoteric algorithms for video processing. After some net surfing and trial and error I defined my parameters file as follows:
PATTERN IBBPBBPBBPI
FORCE_ENCODE_LAST_FRAME
OUTPUT 718.mpg
INPUT_DIR .
INPUT
718*.ppm [00-30]
END_INPUT
BASE_FILE_FORMAT PNM
INPUT_CONVERT *
GOP_SIZE 5
PIXEL HALF
IQSCALE 10
PQSCALE 10
BQSCALE 10
RANGE 2
PSEARCH_ALG LOGARITHMIC
SLICES_PER_FRAME 10
BSEARCH_ALG SIMPLE
REFERENCE_FRAME DECODED
ASPECT_RATIO 1.0
FRAME_RATE 29.97
BUFFER_SIZE 20
You can copy and paste the previous code into a *.par file. Do not leave a blank line at the beginning of the file. I usually name the file "anim.par" for all my animations, and the only things I have to change are the value of OUTPUT, and the line after INPUT. 718*.ppm [00-30] means "take all the files from 71800.ppm to 71830.ppm for making the video". BASE_FILE_FORMAT is PNM, because PPM is a subset of PNM. You may also consider altering FRAME_RATE.
Now, let's see a checklist before we attempt to make the video:
There you have it. Now you should have a nice *mpg file.
Let's assume that we have all the ppm files generated by POV-Ray and we want to make an animated GIF. The first thing we need to do is reduce the number of colors present in the colormap for the image. GIF images can store up to 256 colors, but raytraced images can easily generate thousands of colors (POV-Ray uses 24-bit color depth, so it has a maximum of 16,777,216 colors). Reduction of the number of colors is also called "quantization" of the colormap. We use "ppmquant" to accomplish this and the command line is as follows:
the output file will be a ppm file with 256 colors, at most. Then using ppmtogif will translate the quantized ppm images to GIFs:
and finally, gifsicle puts all the GIFs together in an animated GIF:
To make my life simpler, I wrote a little shell script (named "makeanim"), that simplifies things considerably:
#!
povray filename.pov
ppmtompeg anim.par
foreach i ( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 28 29 30)
ppmquant 256 filename$i.ppm > temp$i.ppm
ppmtogif temp$i.ppm > filename$i.gif
end
gifsicle --loopcount --colors 256 filename*.gif > output.gif
rm temp*.ppm
rm filename*.gif
rm filename*.ppm