by Pasquale Pavone & Konstantin Lion for exciting nitrogen
Purpose: In this tutorial you will learn how to set up and execute a series of calculations for strained structures. Additionally, it will be explained how to obtain the derivatives of the energyvsstrain curves at zero strain and how these quantities are related to elastic constants.
Table of Contents

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.
 SETUPelasticstrain.py: Python script for generating strained structures.
 EXECUTEelasticstrain.sh: (Bash) shell script for running a series of exciting calculations.
 CHECKFITenergyvsstrain.py: Python script for extracting derivatives at zero strain of energyvsstrain curves.
 PLOTenergy.py: Python visualization tool for energyvsstrain curves.
 PLOTstatus.py: Python visualization tool for RMS deviations of the SCF potential as a function of the iteration number during the SCF loop.
 PLOTmaxforce.py: Python visualization tool for the maximum amplitude of the force on the atoms during relaxation.
 PLOTcheckderiv.py: Python visualization tool for the calculation of derivatives at zero strain using the fit of energyvsstrain curves.
 PLOToptimizedgeometry.py: Python visualization tool for relaxed coordinates of atoms in the unit cell.
From now on the symbol $ will indicate the shell prompt.
Requirements: Bash shell. Python numpy, lxml, matplotlib.pyplot, and sys libraries.
1. Theoretical background
The energy of a crystal depends on the state of distorsion in which the crystal is found. Usually, the "measure" of the state of distortion is given either in terms of the physicalstrain matrix:
(1)or in terms of the Lagrangianstrain matrix:
(2)where $\pmb{\varepsilon}$ and $\pmb{\eta}$ are symmetric matrices and are related to each other by the relationship
(3)The actual deformation of the crystal is given by
(4)Using the previous definitions, the total energy of a crystal can be written as a Taylor expansion in terms of powers of the Lagrangian strain
(5)where $\sigma^0_{ij}=0$ is the reference (unstrained) configuration is the equilibrium one. The other coefficients in this Taylor expansion are defined as elastic constants of different order, e.g., the elastic constants of the 2nd order (called also linear elastic constants) are
(6)The results above are often expressed in terms of the Voigt notation, which is a way to represent a symmetric tensor by reducing its order. Thus, following this notation the strain matrices above can be represented as vectors in a sixdimentional space:
(7)The Taylor expansion of the elastic energy can be rewritten using Voigt notation as
(8)where $\pmb{C}^{(2)}$ is the 6$\times$6 matrix
(9)For a given crystal structure, the number of independent elasticconstants components can be reduced using the crystal symmetry. For instance, for cubic systems the matrix of the elastic constants reduces to
(10)2. Set up the calculations
i) Preparation of the input file
The first step is to create a directory for each system that you want to investigate. Here, we consider the calculation of the energyvsstrain curves for carbon in the diamond structure. However, the procedure we show you is valid for any system. Thus, we will create a directory diamondelasticstrain and we move inside it.
$ mkdir diamondelasticstrain
$ cd diamondelasticstrain
Inside this directory, we create (or copy from a previous calculation) the file input.xml corresponding to a calculation for the equilibrium structure of diamond. This file could look like the following.
<input> <title>Diamond: Equilibrium structure</title> <structure speciespath="$EXCITINGROOT/species"> <crystal scale="6.714"> <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" rmt="1.25"> <atom coord="0.00 0.00 0.00" /> <atom coord="0.25 0.25 0.25" /> </species> </structure> <groundstate ngridk="8 8 8" swidth="0.0001" gmaxvr="14" xctype="GGA_PBE_SOL"> </groundstate> <relax/> </input>
Please, remember that the input file for an exciting calculation must always be called input.xml.
Be sure to set the correct path for the exciting root directory (indicated in this example by $EXCITINGROOT) to the one pointing to the place where the exciting directory is placed. In order to do this, use the command
$ SETUPexcitingroot.sh
Be sure to have in your file the appropriate command for performing the structure optimization: Deforming your system may change the relative positions of the atoms in the unit cell.
<relax/>
ii) Generation of input files for distorted structures
All strains considered in this tutorial are Lagrangian strains.
In order to generate input files for a series of distorted structure, you have to run the script SETUPelasticstrain.py. Notice that the script SETUPelasticstrain.py always generates a working directory containing input files for different strains. Results of the current calculations will be also stored in the working directory. The directory name can be specified by adding the name in the command line.
$ SETUPelasticstrain.py DIRECTORYNAME
If no name is given, the script use the default name workdir. Very important: The working directory is overwritten each time you execute the script SETUPelasticstrain.py. Therefore, choose different names for different calculations.
The script SETUPelasticstrain.py produces the following output on the screen (using deformation0 as working directory).
$ SETUPelasticstrain.py deformation0
Enter maximum Lagrangian strain [smax] >>>> 0.10
Enter the number of strain values in [smax,smax] >>>> 11

List of deformation codes for strains in Voigt notation

0 => ( eta, eta, eta, 0, 0, 0)  volume strain
1 => ( eta, 0, 0, 0, 0, 0)  linear strain along x
2 => ( 0, eta, 0, 0, 0, 0)  linear strain along y
3 => ( 0, 0, eta, 0, 0, 0)  linear strain along z
4 => ( 0, 0, 0, eta, 0, 0)  yz shear strain
5 => ( 0, 0, 0, 0, eta, 0)  xz shear strain
6 => ( 0, 0, 0, 0, 0, eta)  xy shear strain
7 => ( 0, 0, 0, eta, eta, eta)  shear strain along (111)
8 => ( eta, eta, 0, 0, 0, 0)  xy inplane strain
9 => ( eta, eta, 0, 0, 0, 0)  xy inplane shear strain
10 => ( eta, eta, eta, eta, eta, eta)  global strain
11 => ( eta, 0, 0, eta, 0, 0)  mixed strain
12 => ( eta, 0, 0, 0, eta, 0)  mixed strain
13 => ( eta, 0, 0, 0, 0, eta)  mixed strain
14 => ( eta, eta, 0, eta, 0, 0)  mixed strain

Enter deformation code >>>> 0
$
In this example, (on screen) input entries are preceded by the symbol ">>>>". Entry values must be typed on the screen when requested. The first entry (in our example 0.10) represents the absolute value of the maximum strain for which we want to perform the calculation. The second entry (11) is the number of deformed structures equally spaced in strain, which are generated between the maximum negative strain and the maximum positive one. The third (last) entry (0) is a selfexplained label indicating the type of deformation. The latter is always referred to 2dimensional strain tensors in the Voigt notation (so that, e.g., a strain value of 0.10 corresponds, for the choice 1 of the deformation code, to a linear deformation of 10% along the x direction).
After running the script, a directory called deformation0 is created, which contains input files for different strain values.
3. Execute the calculations
To execute the series of calculation with input files created by SETUPelasticstrain.py you have to run the script EXECUTEelasticstrain.sh. If a name for the working directory has been specified, then you must give it here, too.
$ EXECUTEelasticstrain.sh deformation0
===> Output directory is "deformation0" <===
Running exciting for file input01.xml 
...
Run completed for file input11.xml 
$
After the complete run, move to the working directory deformation0.
$ cd deformation0
Inside this directory, results of the calculation for the input file inputi.xml are contained in the subdirectory rundiri where i is running from 01 to the total number of strain values. The data for energyvsstrain curves are contained in the file energyvsstrain.
4. Postprocessing: Extract energy derivatives
At this point, inside the directory deformation0, you can use the python script CHECKFITenergyvsstrain.py for extracting derivatives at zero strain of energyvsstrain curves.
$ CHECKFITenergyvsstrain.py
Enter maximum strain for the fit >>>> 0.10
Enter the order of derivative >>>> 2
###########################################
Fit data
Deformation code ==> 0
Deformation label ==> EEE000
Maximum value of the strain ==> 0.10000000
Number of strain values used ==> 11
Fit results for the derivative of order 2
Polynomial of order 2 ==> 4467.25 [GPa]
Polynomial of order 3 ==> 4467.25 [GPa]
Polynomial of order 4 ==> 4053.38 [GPa]
Polynomial of order 5 ==> 4053.38 [GPa]
Polynomial of order 6 ==> 4060.24 [GPa]
Polynomial of order 7 ==> 4060.24 [GPa]
###########################################
$
In this example, input entries are preceded by the symbol ">>>>". Entry values must be typed on the screen when requested. The first entry (in our example 0.10) represents the absolute value of the maximum strain for which we want to perform the calculation. The second entry (2) is the order of the derivative that we want to obtain.
The script generates the output files checkenergyderivatives and orderofderivative, which can be used in the postprocessing analysis. Results of this script can be analyzed using the visualization tool PLOTcheckderiv.py.
5. Postprocessing: Visualization tools
All the scripts mentioned here must be executed in the directory where the energyvsstrain, checkenergyderivatives, and orderofderivative files are located. The scripts produce as output a PostScript file named PLOT.ps as well as a png file (PLOT.png).
i) PLOTenergy.py
This script allows for the visualization of the energyvsstrain curve. It is executed as follows.
$ PLOTenergy.py
ii) PLOTcheckderiv.py
This is a very important tool that allows to represent the dependence of the calculated derivatives of the energyvsstrain curve on
 the range of points included in the fitting procedure ("maximum lagrangian strain"),
 the maximum degree of the polynomial used in the fitting procedure ("n").
The script PLOTcheckderiv.py requires as input the checkenergyderivatives and orderofderivative files generated by CHECKFITenergyvsstrain.py and is executed as follows.
$ PLOTcheckderiv.py YMIN YMAX
The previous plots can be used to determine the best range of deformations and order of polynomial fit for each distortion. By analyzing the plot, we note that curves corresponding to the higher order of the polynomial used in the fit show a horizontal plateau at about 4060 GPa. This can be assumed to be the converged value for the second derivative, from the point of view of the fit (further information on this topic can be found here). For this distortion type, this value equals 9 times the bulk modulus. Thus, the extracted value of the bulk modulus is about 451 GPa.
iii) PLOTstatus.py
Python visualization tool for the RMS deviations of the effective SCF potential as a function of the iteration number during the SCF loop. It is executed as follows.
$ PLOTstatus.py LABEL
Different line segments correspond to SCF calculations for different geometries during the relaxation.
iv) PLOTmaxforce.py
Python visualization tool for the maximum amplitude of the force on atoms during relaxation. It is useful for deformations which allow for internal relaxation of atomic positions, e.g., for the deformation with the code 7. It is executed as follows.
$ PLOTmaxforce.py LABEL
The input entry definition is the same as for the script PLOTstatus.py. If the symmetry of the deformation applied to the crystal is such that no extra force is applied to the atoms (e.g., as it happens for deformation 1 and 2) the output of the script PLOTmaxforce.py will be
Either data file not (yet) ready for visualization
or maximum force target reached already at the initial configuration.
The red points show the calculated value at each optimization step, whereas the blue line indicates the target value of the maximum amplitude of the force for stopping the relaxation.
v) PLOToptimizedgeometry.py
Python visualization tool for showing the optimized geometry compared to the reference (unrelaxed) geometry for the relative atomic coordinates of two atoms in the unit cell as a function of Lagrangian strain. It is useful for deformations which allow for internal relaxation of atomic positions, e.g., for the deformation with the code 7. It is executed as follows.
$ PLOToptimizedgeometry.py ATOM1 ATOM2 YMIN YMAX
Here, (Δ1, Δ2, Δ3) and (Δ1_{ref}, Δ2_{ref}, Δ3_{ref}) represent the position difference vector, $\bf r$_{ATOM2}  $\bf r$_{ATOM1}, expressed in lattice coordinates, for the optimized geometry and the unrelaxed (reference) case, respectively.
6. Postprocessing: How to derive elastic constants
Second derivatives calculated at zero strain of energyvsstrain curves are combinations of the elastic constants C_{ij} where the indexes i,j=1,2,…,6 are given in the Voigt notation. In the example that we are considering here, carbon in the cubic diamond structure, only 3 different elastic constants are non vanishing
 C_{11}
 C_{12}
 C_{44}
In order to extract these three elastic constants, three different deformation types must be used. For cubic systems the best choice is represented by the following deformation types
 Volume strain (in our script corresponding to the label 0)
 Uniaxial strain in the 100 direction (label 1)
 Shear strain along the 111 direction (label 7)
Which in turns correspond to the following combination of elastic constants:
 label 0: 3 C_{11}+ 6 C_{12} = 9 B_{0}
 label 1: C_{11}
 label 7: 3 C_{44}
where B_{0} is the bulk modulus.
Experimental reference values for diamond:
 C_{11} = 1076 GPa
 C_{12} = 125 GPa
 C_{44} = 577 GPa
 B_{0} = 452 GPa