Volume Optimization for Cubic Systems¶
by Pasquale Pavone for exciting sodium
(Jupyter notebook by Tejus Rohatgi, Mara Voiculescu & Martin Kuban)
Purpose: In this tutorial you will learn how to set up and execute a series of calculations at different volumes for a cubic crystal. Additionally, it will be explained how to fit the energy-vs-volume curves with either polynomial of various degree or other types of equation of state in order to obtain the corresponding equilibrium volume and bulk modulus.
0. Before Starting¶
Read the following paragraphs before starting with the rest of this tutorial!
Before running any Jupyter tutorials, please refer to the 00_before_starting.md document on how to correctly set up the environment. This only needs to be done once. After which, the venv can be (re)activated from exciting's root directory:
source $EXCITINGROOT/tools/excitingjupyter/venv/excitingvenv/bin/activate
Here is a list of the scripts which are relevant for this tutorial with a short description.
setup.volume_optimization.py: Python script for generating structures at different volumes.execute.volume_optimization.py: Python script for running a series ofexcitingcalculations.checkfit.energy_vs_volume.py: Python script for fitting energy-vs-volume curves.plot.poly.py: Python script for fitting energy-vs-volume curves using a polynomial fit in the volume.plot.vinet.py: Python script for fitting energy-vs-volume curves using the Vinet equation of state.plot.newbirch.py: Python script for fitting energy-vs-volume curves using the Birch-Murnaghan equation of state (BM-EoS) in polynomial form.plot.birch.py: Python script for fitting energy-vs-volume curves using BM-EoS.plot.pbirch.py: Python script for fitting pressure-vs-volume curves using BM-EoS.plot.bbirch.py: Python script for fitting bulk-modulus-vs-volume curves using BM-EoS.
1. 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. In this tutorial, we consider as an example the calculation of the energy-vs-volume curves for silver in the fcc cubic structure. Thus, we will create a directory silver-volume-optimization.
%%bash
mkdir -p silver-volume-optimization
Inside this directory, we create (or copy from a previous calculation) the file input.xml corresponding to a SCF calculation at a reference lattice constant for silver. A possible choice for this reference value is the experimental lattice constant of 7.729 Bohr. The input file could look like the following.
<input>
<title>Silver</title>
<structure speciespath="$EXCITINGROOT/species">
<crystal scale="7.729">
<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.00 0.00 0.00" />
</species>
</structure>
<groundstate
ngridk="8 8 8"
swidth="0.01"
rgkmax="7.5"
xctype="GGA_PBE_SOL">
</groundstate>
</input>
Please, remember that the input file for an exciting calculation must always be called input.xml.
- N.B. (1): Do not forget to replace in the input.xml the string "$EXCITINGROOT" by the actual value of the environment variable
$EXCITINGROOTusing the command
%%bash
cd silver-volume-optimization
python3 -m excitingscripts.setup.excitingroot
cd ..
- N.B. (2): If the crystal symmetry allows for the relaxation of the position of the atoms in the unit cell, the complete optimization requires the inclusion in the input file of the element
relaxjust after the elementgroundstate
...
<groundstate
... >
...
</groundstate>
<relax/>
...
(for further details, see Simple examples of structure optimization).
ii) Generation of input files for different volumes
In order to generate input files for a series of volumes you have to run the script setup.volume_optimization.py. Notice that the script setup.volume_optimization.py always generates a working directory containing input files for different volumes. 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.
%%bash
cd silver-volume-optimization
python3 -m excitingscripts.setup.volume_optimization -r vol-opt-1 11
cd ..
Very important: The working directory is overwritten each time you execute the script setup.volume_optimization.py. Therefore, choose different names for different calculations.
In this example, the working directory is named vol-opt-1. Entry values must be given as arguments. This entry (in our example 11) is the number of structures which are generated with equally spaced intervals of the lattice constant with a variation of between -5% and +5% from the reference lattice constant.
2. Execute the calculations¶
To execute the series of calculations with input files created by setup.volume_optimization.py you have to run the script execute.volume_optimization.py. If a name for the working directory has been specified, then you must give it here, too. Further the number of volume values need to be mentioned as well.
%%bash
cd silver-volume-optimization
python3 -m excitingscripts.execute.volume_optimization -r vol-opt-1 11
cd ..
After the complete run, the results of the calculation for the input file are contained in the subdirectory (of the working directory vol-opt-1) volume-i where i is running from 1 to the total number of volumes. The data for the energy-vs-volume curve are contained in the file energy-vs-volume inside vol-opt-1.
Hint: You can check the status of the calculations by plotting the energies that have been already obtained while other calculations are still running. In order to do this, open a new terminal window, move inside vol-opt-1 and run the script plot.energy.py
%%bash
cd silver-volume-optimization/vol-opt-1
python3 -m excitingscripts.plot.energy
cd ../../
This way, you obtain a PLOT.png file that you can visualize using the standard tools of your operating system. Here is an example:
3. Post-processing: Calculating the optimal volume¶
In order to analyse the results of the calculations, if you have not done before, you first have to move to the working directory.
At this point, you can use the python script checkfit.energy_vs_volume.py for performing the polynomial fit and extracting the equilibrium volume and the bulk modulus.
%%bash
cd silver-volume-optimization/vol-opt-1
python3 -m excitingscripts.checkfit.energy_vs_volume -o 2 --isym 3
cd ../..
===============================
Lattice symmetry codes
-------------------------------
1 --> Simple cubic (sc)
2 --> Body-centered cubic (bcc)
3 --> Face-centered cubic (fcc)
-------------------------------
0 --> Others
===============================
Verification lattice symmetry code >>>> 3
##############################################
Optimal volume = 114.678508 [Bohr^3]
Lattice constant = (fcc) 7.712242 [Bohr]
Bulk modulus = 104.654586 [GPa]
Log(chi) = -3.39
##############################################
Entry values must be given as arguments. The first entry (in our example -o 2) represents the order of the polynomial for the fit. The second entry (in our example --isym 3) corresponds to the appropriate choice of the lattice symmetry (face-centered cubic in our example). This enables us to extract the value of the lattice constant and of the bulk modulus as reported in the screen output.
The script generates an output file PLOT.png (Portable Network Graphics), which can be used to visualize the fitting results. An example of the script output is the following.
4. Additional exercises¶
- Improve the accuracy of the fit by adding more data points.
- If the optimal volume is far from the middle volume in the figure, choose as a new reference lattice constant a value corresponding to the optimal volume.
- Check the accuracy of the calculations by choosing other values for the main computational parameters. An example, corresponding to the choice
ngridk= "12 12 12",rgkmax= "8.0", and using a 4th-order polynomial fit, is the following.
- Compare your results with the ones obtained performing a fit using the Birch-Murnaghan equation of state. In order to do this, use the script
plot.newbirch.py, which can be called in the running directory as:
python3 -m excitingscripts.plot.newbirch
The results should look like this:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
V0 B0 Bp a-sc a-bcc a-fcc log(chi)
112.86526 117.308 5.821 4.8327 6.0888 7.6714 -5.11
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The output on the screen describes the optimal parameters for the fit, as well as a mesure of the quality of the fit log(chi), lower values of this quantity mean better fit accuracy). The script generates the output file PLOT.png, an example can be found in the following.
- Compare your results with the ones obtained performing a fit using the Vinet equation of state.
python3 -m excitingscripts.plot.vinet
- Compare your results with the ones obtained performing a fit using a sixth order polynomial.
python3 -m excitingscripts.plot.poly -o 6
You may also check the effect of using polynomials of different order.
python3 -m excitingscripts.plot.poly -o 8
- Use the script
plot.pbirch.pyto visualize the comparison between the pressure calculated using the Birch-Murnaghan equation of state and the one obtained from a finite-differentiation of the calculated energies.
python3 -m excitingscripts.plot.pbirch
- Use the script
plot.bbirch.pyto visualize the comparison between the bulk modulus calculated using the Birch-Murnaghan equation of state and a second-order finite-differentiation of the calculated energies.
python3 -m excitingscripts.plot.bbirch
- Choose a new cubic material and repeat all the steps.