Simple Convergence Tests

for exciting lithium

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 nkgrid) and the dimension of the basis set (related to the parameter rgkmax).


0. Define relevant shell variables and download scripts

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

Before starting, be sure that relevant shell variables are already defined and that the excitingscripts directory has already been downloaded, as specified in Tutorial scripts and environment variables. 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 groundstate 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. In the general case, a similar analysis should be made for all other properties of interest.

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 ngridk="4 4 4" 
                rgkmax="5.0"
                maxscl="20">
   </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

$ excitingser

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 line of the file TOTENERGY.OUT. Save the value of parameters and total energy in the file convergence-test as indicated below (here, only the first value of the parameter ngridk is considered).

4  5.0  -5314.29995999    # 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 sistematic 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 ngridk="6 6 6" 
                rgkmax="5.0"
                maxscl="20">
   </groundstate>
...

and perform a new calculations using the command excitingser.

$ excitingser

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.29995999    # ngridk rgkmax  total-energy
6  5.0  -5314.32096561

This 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 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) or 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 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.2999599900
   6    5.00      -5314.3209656100
   8    5.00      -5314.3232090100
  10    5.00      -5314.3225649600
  12    5.00      -5314.3200963700
  14    5.00      -5314.3220530800
  16    5.00      -5314.3223799400
  18    5.00      -5314.3212710100
  20    5.00      -5314.3221104800

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
The resulting PostScript output (PLOT.ps) 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
$ cd workdir
$ PLOT-convergence.py k
  • Example 2: Run on rgkmax at fixed ngridk="12 12 12"
$ SETUP-convergence-test.py 12 12 5 9
$ EXECUTE-convergence-test.sh
$ cd workdir
$ PLOT-convergence.py r
  • Example 3: Two-dimentional run on both rgkmax and ngridk
$ SETUP-convergence-test.py 4 20 5 9
$ EXECUTE-convergence-test.sh
$ cd workdir
$ PLOT-3d-convergence.gnu Ag

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

  • Example 1 ag-rgkmax-9.png
  • Example 2 ag-ngridk-12.png
  • Example 3 ag-total.png

Notes on Examples

  • 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 as line entry a label for the plot (usually, the name of the crystal).
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.7890651300
   6    9.00      -5314.7932114900
   8    9.00      -5314.7947134200
  10    9.00      -5314.7953271200
  12    9.00      -5314.7956398900
  14    9.00      -5314.7958504700
  16    9.00      -5314.7959100400
  18    9.00      -5314.7959696600
  20    9.00      -5314.7959849900

Due to the fact that the difference between energies in contiguous rows becomes increasingly small 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, the 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 ngridk="4 4 4" 
                rgkmax="5.0"
                gmaxvr="14"
                maxscl="20">
   </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.

c-rgkmax-5.png
c-rgkmax-9.png
c-ngridk-12.png
c-total.png

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