How to Make Animated Movies of Phonons

by Stefan Kontur for exciting beryllium

Purpose: This tutorial shows you how to visualize the phonon modes found in an earlier phonon calculation, using a basic python script. As in other tutorials, we consider the diamond crystal as example.

### 0. Prerequisites

This tutorial assumes that you have already downloaded and installed exciting, and set the relevant environment variables. Otherwise, please have a look at Tutorial scripts and environment variables. The script which is relevant for this tutorial is

• PLOT-phonon-anim.py

Note: The symbol $at beginnings of lines in code segments below indicates the shell prompt. Continue in the working directory where you did the phonon calculation, e.g., /home/exciting-tutorial/diamond-phonons. In particluar you need to have the files input.xml and PHONON.OUT ready. The script will also read the relevant species files, C.xml in our example for diamond, in the path specified by$EXCITINGROOT/species.

### 1. Produce coordinate files of the animated phonon modes

To invoke the script, simply type

$PLOT-phonon-anim.py  The script will read phonon eigenvectors for all q-points contained in the file PHONON.OUT and plot a supercell of 6$\times$6$\times$6 unit cells to visualize them. Unit cells are taken as specified in input.xml and the dimensions are along lattice vectors. If you want to change the supercell size, e.g., type $ PLOT-phonon-anim.py 4 4 1


to obtain a supercell of 4$\times$4$\times$1 unit cells.

When executing the script PLOT-phonon-anim.py, you will be required to enter the number of steps in the animation which complete one period of the vibration.

$PLOT-phonon-anim.py ############################################ Supercell dimensions : 6 6 6 Number of steps in the animation? >>>> 20 -------------------------------------------- Total number of atoms : 2 Total number of q-points : 3 -------------------------------------------- q-point 1 is 0.0 0.0 0.0 mode 1 with frequency -0.0000 cm-1 mode 2 with frequency 0.0000 cm-1 mode 3 with frequency 0.0000 cm-1 mode 4 with frequency 1579.8263 cm-1 mode 5 with frequency 1579.8263 cm-1 mode 6 with frequency 1579.8263 cm-1 q-point 2 is 0.5 0.5 0.0 mode 1 with frequency 524.5318 cm-1 mode 2 with frequency 524.5318 cm-1 mode 3 with frequency 1096.7498 cm-1 mode 4 with frequency 1096.7498 cm-1 mode 5 with frequency 1127.1560 cm-1 mode 6 with frequency 1127.1560 cm-1 q-point 3 is 0.5 0.5 0.5 mode 1 with frequency 459.7583 cm-1 mode 2 with frequency 459.7583 cm-1 mode 3 with frequency 868.0174 cm-1 mode 4 with frequency 1239.1738 cm-1 mode 5 with frequency 1400.9692 cm-1 mode 6 with frequency 1400.9692 cm-1 ############################################$


Specify, e.g., 20 steps, as above. The screen output of the script is completed by information about the number of atoms, number of q-points, and the frequency (in cm-1) for each mode at each q-point.

Beyond this information, the script produces a number of files, named, e.g., q1_mode1.axsf and q1_mode1.xyz. One file is written for each mode at each q-point. These files contain atomic coordinates for the supercell at every step of the animation. The axsf format can be used in connection with XCrySDen (see next section), the files with extension xyz are simple xyz-coordinate files.

### 2. Plot the coordinate files and produce movies

##### 2.1) Using XCrySDen and the .axsf-files

If XCrySDen is installed on your system, you can use it to visualize the files with extension .axsf produced in the previous step. Invoke the program by typing

$xcrysden  Then, open a file through the open animated XSF files dialog: Choose a file, e.g., q1_mode4.axsf. The following two windows will apear: You can click on the larger window and keeping the click you can also change the angle of view to the cell. Now, you can use the arrow buttons in the smaller window to watch the animation of the mode. If XCrySDen is properly set up, the button Animated GIF/MPEG of the smaller window and the dialog that opens can be used to produce a movie of the animation, refer to the XCrySDen webpage for details. The temporary frame files can be reused at a later point to change the settings of the movie (see Section 3). Our example of the$T_{2g}$phonon mode (no. 4) of diamond at Γ would look like the following: ##### 2.2) Using the .xyz-files Many visualization packages can plot the files with extension .xyz. Here, we make use of VMD as an example, and assume that you have an installed and properly set up version available on you system. After starting the program by typing $ vmd &


use the buttons File and New Molecule to open a dialog to open files. Use Browse to choose a file in your working directory, e.g., q1_mode4.xyz, the file type should be determined automatically, and Load to yield the following windows:

Use the Graphics -> Representations button to change the appearance of atoms and bonds, colors and that like. You might also want to change to a non-perspective display or omit the axes in the image, using the Display menu.

An animated movie can be produced via Extensions -> Visualization -> Movie Maker, what opens a new window:

Adjust path, filename and movie duration according to your needs. Make sure you set Movie Settings -> User Defined Procedure and start the animation in the VMD Main window by pressing the bottom right arrow button, prior to pressing the Make Movie button. By default VMD produces an animated GIF using the convert. See the VMD webpage for details and other settings. Note that in order to be able to adjust the settings of your movie later, we recommend to keep the intermediate images by unchecking Movie Settings -> 4: Delete Image Files, see Section 3.

Our phonon mode no. 4 at the Γ point looks then like the following:

As another example, let us have a look at the acoustic mode 1 at q=(0.1, 0.1, 0), on the line Δ (i.e. Γ-X). You have to rerun the phonon calculation with this q-point added to the list, and invoke the script PLOT-phonon-anim.py once more, to obtain the appropriate .xyz-file.

### 3. More on the convert utility of ImageMagick

You can modify the movies of the phonon modes by using convert at the command line. This requires you, of course, to have all the individual images that are to be combined to the movie saved in your working directory. Let us assume that we have a series of images named

• q1_mode4.0000.ppm
• q1_mode4.0001.ppm

for the first, second, etc. frame. VMD uses the .ppm image file format by default. This format can also be chosen in XCrySDen, so we use it here exemplarily. For other file formats the procedure would be analogous. In general, it is not recommended to use .gif temporary files (as a necessary compression step should be done only when creating the movie).

A basic command to create an animated .gif movie could look like

$convert -delay 4 -loop 0 q1_mode4.*.ppm q1_mode4.gif  where -delay 4 keeps every frame displayed for 0.04 seconds and -loop 0 means to repeat the loop infinitely; the movie is output to file q1_mode4.gif. If you want to change the size and scale of your images at this point you can use, e.g. $ convert -crop 560x420+10+10 +repage -resize 80% -delay 4 -loop 0 q1_mode4.*.ppm q1_mode4.gif


where -crop 560x420+10+10 means that a rectangular region of 560x420 pixels, offset by 10 pixels in x and y, is used. The option +repage then resets the image canvas, and -resize 80% rescales images to 80%. The result is a smaller image size in the movie, with everything outside the region of 560x420 pixels cut off. There are many more options to the convert program, which are explained at the ImageMagick website.

More details on preparing animations can be found here.