Simple Convergence Tests

by Pablo Garcia Risueno & Pasquale Pavone for exciting oxygen

Purpose: In this tutorial, you will investigate how the choice of computational parameters can affect the result of an exciting calculation. The procedure which is used in this case is often called convergence study and allows to obtain the best value of such parameters. Explicit examples are presented for the convergence of the total energy of silver and diamond with respect to the choice for the k-points sampling (related to the parameter ngridk) and the dimension of the basis set (related to the parameter rgkmax).


0. Define relevant environment variables

Read the following paragraphs before starting with the rest of this tutorial!

Before starting, be sure that relevant environment variables are already defined as specified in How to set environment variables for tutorials scripts. Here is a list of the scripts which are relevant for this tutorial with a short description.

  • SETUP-convergence-test.py: Python script for generating input files with different values of the main computational parameters.
  • EXECUTE-convergence-test.sh: (Bash) shell script for running a series of exciting calculations.
  • PLOT-convergence.py: Python script for visualization of convergence results.
  • PLOT-3d-convergence.gnu: Gnuplot script for visualization of convergence results.

From now on the symbol $ will indicate the shell prompt.


1. Convergence of total-energy calculations

A ground-state calculation using a DFT code like exciting fundamentally depends on 2 parameters

  • the mesh of k-points (groundstate attribute: ngridk);
  • the size of the basis set for expanding the wave function (groundstate attribute: rgkmax).

In order to be able to rely on your calculation, you need to understand what these two parameters mean and what is the effect of a change of their values on the physical quantities which are relevant for you. In this tutorial, we focus on the effect of such changes on the total energy of a crystal only for pedagogical reasons. In the general case, this kind of analysis must be made for all the properties of interest (e.g., lattice parameters, bulk modulus, equation of state, bandgap energies, etc.).

For more informations on these parameters, please expand the links below.


2. Running tests: Silver

In this first example, we investigate the dependence of the total energy on the parameters ngridk and rgkmax for the Ag crystal. To this end, we start by creating a working directory Ag-convergence-test and we move inside it.

$ mkdir Ag-convergence-test
$ cd Ag-convergence-test

Here, we create an exciting (xml) input file called input.xml which should appear as the one below.

<input>
 
   <title>Ag: Convergence test</title>
 
   <structure speciespath="$EXCITINGROOT/species"> 
 
      <crystal scale="7.7201">
         <basevect>0.5 0.5 0.0</basevect>
         <basevect>0.5 0.0 0.5</basevect>
         <basevect>0.0 0.5 0.5</basevect>
      </crystal>
 
      <species speciesfile="Ag.xml">
         <atom coord="0.0  0.0  0.0" />
      </species>
 
   </structure>
 
   <groundstate 
      xctype="GGA_PBE_SOL"
      ngridk="4 4 4" 
      rgkmax="5.0">
   </groundstate>
 
</input>

N.B.: Do not forget to replace in the input.xml the string "$EXCITINGROOT" by the actual value of the environment variable $EXCITINGROOT using the command

$ SETUP-excitingroot.sh

Now you can run exciting by simply typing

$ time exciting_smp &

Using the optional time command, the elapsed time will be displayed on the screen at the end of the execution. If you wish, you can follow the progress by displaying the output to INFO.OUT with the command

$ tail -f INFO.OUT

which needs to be killed after exciting has stopped using Ctrl+C.

After a few seconds, the calculation will be completed. Indeed, the calculation you have just performed uses very rough values for the parameters ngridk and rgkmax. The corresponding total energy (in Hartree) can be found as the last non empty line of the file TOTENERGY.OUT. You can save the value of parameters and total energy at a text file called convergence-test as indicated below (here, only the first value of the parameter ngridk is considered).

4  5.0  -5314.29682116   # ngridk rgkmax  total-energy

In order to improve the calculation, we should change the value of ngridk and rgkmax and repeat the calculation in a systematic way. To this end, we remove all output files from the previous calculation (be always careful when using the command rm).

$ rm *.OUT

Then, we change in the input file the values of one (or both) parameter, e.g.

...
   <groundstate
      xctype="GGA_PBE_SOL" 
      ngridk="6 6 6" 
      rgkmax="5.0">
   </groundstate>
...

and perform a new calculations using the command exciting_smp.

$ time exciting_smp &

Also this time we extract the value of the calculated total energy and add it to the file convergence-test, which now should appear as

4  5.0  -5314.29682116    # ngridk rgkmax  total-energy
6  5.0  -5314.31785570

Remove once more all output files from the last calculation.

$ rm *OUT*

Then, the same procedure can be repeated for other values of the parameters.

Using scripts for checking convergence

The procedure described above can be easily performed with the help of some useful script. For instance, the script SETUP-convergence-test.py can be used for preparing inputs for a sequence of calculations. You can execute the script, in the directory where you are already, in the following way.

$ SETUP-convergence-test.py 4 20 5 5

where the first 2 arguments are the minimum and maximum values (with a step of 2) for ngridk, respectively. The last 2 (integer!) entries are the minimum and maximum values (with a step of 1) for rgkmax, respectively. This means that, in this example, we are considering the convergence of the total energy as a function of ngridk at the constant value of rgkmax = "5".

The complete run is performed by the script EXECUTE-convergence-test.sh.

$ EXECUTE-convergence-test.sh

The result of all calculations are now stored in a new directory called workdir. Notice that the script SETUP-convergence-test.py always generates a directory called workdir containing the results of the calculation. Very important: The directory workdir will be overwritten each time you execute the script SETUP-convergence-test.py. Therefore, before performing a new run, please rename an already exsisting workdir directory to a different name. Keeping this in mind, you can now move inside the directory workdir for analysing the result.

$ cd workdir

The result of this sequence of calculation is summarized automatically in the file convergence-test, which now should appear as

   4    5.00      -5314.29682116
   6    5.00      -5314.31785570
   8    5.00      -5314.32020692
  10    5.00      -5314.31951738
  12    5.00      -5314.31699324
  14    5.00      -5314.31899799
  16    5.00      -5314.31931338
  18    5.00      -5314.31818230
  20    5.00      -5314.31905093

To visualize these results you can use the command (the line entry k indicates the running on different values of ngridk)

$ PLOT-convergence.py k

This command generates a plot which can be visualized both as a PostScript (PLOT.ps) and a PNG (PLOT.png) file. You can tune the size of the PNG output image by using the command

$ export DPIPNG=70

prior to doing the plot.

The resulting output image should look like this.
ag-rgkmax-5.png

If you want to run again the script, move back to the parent directory and move the directory workdir to another name, e.g., test-1.

$ cd ..
$ mv workdir test-1

Then, you can run one or more of the following examples.

  • Example 1: Run on ngridk at fixed rgkmax = "9"
$ SETUP-convergence-test.py 4 20 9 9
$ EXECUTE-convergence-test.sh
$ mv workdir example-1
$ cd example-1
$ PLOT-convergence.py k
  • Example 2: Run on rgkmax at fixed ngridk = "12 12 12"
$ cd ..
$ SETUP-convergence-test.py 12 12 5 9
$ EXECUTE-convergence-test.sh
$ mv workdir example-2
$ cd example-2
$ PLOT-convergence.py r
  • Example 3: Two-dimentional run on both rgkmax and ngridk
$ cd ..
$ SETUP-convergence-test.py 4 20 5 9
$ EXECUTE-convergence-test.sh
$ mv workdir example-3
$ cd example-3
$ PLOT-3d-convergence.gnu Ag 5 9 >/dev/null 2>&1

If examples run correctly, correspondingly, you should obtain the following plots.

  • Example 1
ag-convergence1.png
  • Example 2
ag-convergence2.png
  • Example 3
ag-convergence3.png

Notes on Examples

  • Please, notice that the scripts SETUP-convergence-test.py and EXECUTE-convergence-test.sh must be executed in the same directory where the original input file input.xml is located.
  • In Example 2 the script PLOT-convergence.py takes the line entry r (run on different values of rgkmax) instead of k (run on different values of ngridk) .
  • In Example 3 the script PLOT-3d-convergence.gnu has been used for plotting the convergence behaviour with respect to both rgkmax and ngridk.
  • In Example 3 the script PLOT-3d-convergence.gnu takes 3 line entries: a label for the plot (usually, the name of the crystal), the number of used values for rgkmax, and the number of used k-point meshes.
How to quantify convergence

In this subsection we refer to the results of Example 1. In this case the convergence-test file is

   4    9.00      -5314.79400824
   6    9.00      -5314.79814432
   8    9.00      -5314.79964595
  10    9.00      -5314.80025313
  12    9.00      -5314.80059990
  14    9.00      -5314.80081015
  16    9.00      -5314.80084355
  18    9.00      -5314.80090859
  20    9.00      -5314.80092347

Due to the fact that the difference between energies in contiguous rows becomes (increasingly) smaller going to large values of ngridk, this difference can be interpreted as a measure of the accuracy in the value of the calculated energy.


3. Running tests: Diamond

Repeat what you have done in the previous section for diamond. In contrast to silver, which is a metal, diamond an insulator. The corresponding input for exciting (input.xml) could look like the following.

<input>
 
   <title>Diamond: Convergence test</title>
 
   <structure speciespath="$EXCITINGROOT/species"> 
 
      <crystal scale="6.719">
         <basevect>0.5 0.5 0.0</basevect>
         <basevect>0.5 0.0 0.5</basevect>
         <basevect>0.0 0.5 0.5</basevect>
      </crystal>
 
      <species speciesfile="C.xml">
         <atom coord="0.00 0.00 0.00" />
         <atom coord="0.25 0.25 0.25" />
      </species>
 
   </structure>
 
   <groundstate
      xctype="GGA_PBE_SOL" 
      ngridk="4 4 4" 
      rgkmax="5.0"
      gmaxvr="14">
   </groundstate>
 
</input>

As in the previous section, do not forget to replace in the input.xml the string "$EXCITINGROOT" by the actual value of the environment variable $EXCITINGROOT.

Finally, on the basis of what you learned above, try to reproduce the results for Diamond displayed in the following.

conv-diamond1.png
conv-diamond2.png
conv-diamond3.png
conv-diamond4.png

4. Final questions

  • Is convergence with respect to the values of ngridk faster for silver or diamond? Why?
  • What about the convergence with respect to the values of rgkmax?
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License