{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Calculating absorption spectra\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"In this exercise we are going to calculate the absorption spectra of the material you have considered so far.\n",
"In general, the absorption spectrum is given by the imaginary part of the macroscopic dielectric function. This means that our computational task is to calculate the macroscopic dielectric function for our material, and then plot the imaginary part. For more information about the dielectric function please consult:\n",
"\n",
"https://wiki.fysik.dtu.dk/gpaw/tutorialsexercises/opticalresponse/dielectric_response/dielectric_response.html\n",
"\n",
"To calculate the dielectric function, we will use the Random Phase Approximation (RPA) correlation energy (so we say we calculate the absorption spectrum within the random phase approximation).\n",
"(Details about RPA to calculate the total energy can be found here: https://wiki.fysik.dtu.dk/gpaw/documentation/xc/rpa.html#rpa)\n",
"\n",
"As discussed earlier, it is of greatest importance to make sure our calculations are converged. Since the convergence parameters is not necessarily the same for band gaps and RPA absorption spectra (and any other material property) with respect to for instance plane-wave cut-off or k-points, we need to do do a new ground state calculation with parameters. For RPA absorption spectra we will here look at the number of bands included in the calculation and the k-point mesh. We will therefore restart from the previous ground state file, and update some of the parameters. First we will look at a too rough k-point mesh and then do more calculations with a finer k-point mesh. In this way we can see the importance of converging the calculations.\n",
"\n",
"The new ground state is calculated below. For BN use (24,24,1) k-points while for the bulk materials use (12,12,4) k-points.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"from gpaw import GPAW\n",
"from gpaw.mpi import world\n",
"from gpaw.occupations import FermiDirac\n",
"\n",
"\n",
"#Load and initialize ground state gpw file from previous exercise\n",
"calc_old = GPAW('.gpw', txt=None)\n",
"\n",
"#Extract number of valence bands:\n",
"nval = calc_old.wfs.nvalence\n",
"\n",
"# Do new ground state calculations with more k-points.\n",
"# This is because in general RPA calculations requires more k-poins to be converged.\n",
"\n",
"calc = GPAW('???.gpw').fixed_density(\n",
" kpts=???,\n",
" nbands=8 * nval, # number of bands to include in calculation\n",
" convergence={'bands': 6 * nval}, # number of bands to convergence\n",
" txt = '???',\n",
" occupations=FermiDirac(width=1e-4))\n",
"\n",
"\n",
"calc.get_potential_energy()\n",
"#Now save the .gpw file. 'all' means we save all the wave functions to the gpw file. This is required for the rpa calculations\n",
"calc.write('', 'all')\n"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Now that we have obtained the ground state, it is time to calculate the dielectric function. This is done below where we first initialize the parameters needed for an RPA calculation, then calculate the dielectric function, and finally obtain the polarizability. Note that one also would have to converge the parameters initialized below, for a fully converged study, however in the interest of time and computational power we will not consider this here. The principle is however exactly the same, as you will see with the different k-point meshes we will employ here.\n",
"\n",
"These calculations are both time-wise and memory-wise heavier than what you previously encountered. Therefore we will need to submit these calculations to the databar so they can run over night. Open a new SSH terminal, edit and copy the below code into a script format (.py file), and submit the calculations from the terminal using the following command:\n",
"\n",
"mq submit -R 8:15h script.py\n",
"\n",
"This will submit the script with the name \"script.py\" to 8 cores with a maximum time of 15 hours.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#Define parameters for rpa calculations. You should change the name of the output file so it corresponds with your calculation:\n",
"from gpaw import GPAW\n",
"from gpaw.mpi import world\n",
"from gpaw.occupations import FermiDirac\n",
"from gpaw.response.df import DielectricFunction\n",
"\n",
"#Insert the name of your structure and the k-point grid you are using instead of \"???\".\n",
"\n",
"calc_old = GPAW('.gpw', txt=None)\n",
"nval = calc_old.wfs.nvalence\n",
"\n",
"#Note: For a 2D material (here BN) we use an additional keyword in the parameters below: 'truncation': '2D'\n",
"#This truncates the Coulomb interaction in the lateral direction to avoid non-physical periodic interactions.\n",
"\n",
"kwargs = {\n",
" 'frequencies': {\n",
" 'type': 'nonlinear',\n",
" 'domega0': 0.01}, # Define spacing of frequency grid\n",
" 'eta': 0.05, # Broadening parameter\n",
" 'intraband': False, # Here we do not include intraband transitions for calculating the absorption spectrum\n",
" 'nblocks': 8, # Number of blocks used for parallelization\n",
" 'ecut': 50, # Plane wave cutoff in eV\n",
" 'nbands': 3 * nval} # Number of bands included in rpa calculation\n",
"\n",
"#Calculate dielectric function. Takes ground state calculation and defined parameters in \"kwargs\" as input:\n",
"df = DielectricFunction('.gpw', **kwargs)\n",
"\n",
"\n",
"#Finally we calculate he polarizability in the x, y, and z direction. The output is a .csv file (one for each direction) which can be plotted.\n",
"#Consider the symmetries of your material and figure out if calculating the absorption spectrum in all 3 directions\n",
"#is needed or two or more of them will be the same. In that case only do the directions you will need (this is for saving\n",
"#time and memory). Also remember to change the filename so it fits with your calculation.\n",
"\n",
"df.get_polarizability(xc='RPA', #We want to calculate the absorption spectrum within RPA\n",
" q_c = [0, 0, 0], #We consider the zero momentum wave vector\n",
" direction = 'x', #Define real space direction\n",
" filename='=???_rpa_x.csv' #Name of output file\n",
"\n",
"df.get_polarizability(xc='RPA',\n",
" q_c = [0, 0, 0],\n",
" direction = 'y',\n",
" filename='=???_rpa_y.csv'\n",
"df.get_polarizability(xc='RPA',\n",
" q_c = [0, 0, 0],\n",
" direction = 'z',\n",
" filename='=???_rpa_z.csv'\n"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Now it is time to do more calculations with finer k-point mesh to see the importance of converging our calculations. Repeat the above calculations with the following parameters:\n",
"\n",
"For BN try: (24,24,1), (40,40,1), and (60,60,1) k-points\n",
"For bulk materials try e.g.: (12,12,4), (18,18,6), and (24,24,8) k-points\n",
"(Remember to use a meshes according to the length of lattice vectors.)\n",
"\n",
"For the calculations with more k-points you probably want to combine the (new) ground state calculation and the calculation of the absorption spectrum into one script which you will submit over night.\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "CAMD2022",
"language": "python",
"name": "camd2022"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}