# Calculating band gap using the GLLB-sc functional¶

In this tutorial, we use the GLLB-sc to calculate the band gap of KTaO3 using the XC functional GLLB-sc. This functional uses the GLLB response potential to replace the PBEsol response potential of the exchange. [GLLB-sc] This has been shown to improve the band gap description as shown in the figure below taken from [Castelli2012].

A GLLB-sc band gap calculation is performed as given here:

```
from __future__ import print_function
from gpaw import *
from ase import *
import numpy as np
atom = Atoms(symbols='KTaO3',
pbc=np.array([ True, True, True], dtype=bool),
cell=np.array(
[[ 4., 0., 0.],
[ 0., 4., 0.],
[ 0., 0., 4.]]
),
positions=np.array(
[[ 0., 0., 0.],
[ 2., 2., 2.],
[ 2., 2., 0.],
[ 0., 2., 2.],
[ 2., 0., 2.]]
),
)
calc = GPAW(h=0.16,
kpts=(10,10,10),
xc='GLLBSC',
txt='KTaO3.out',
occupations=FermiDirac(width=0.05),
)
atom.set_calculator(calc)
atom.get_potential_energy()
#Important commands for calculating the response and the
#derivatice discontinuity
response = calc.hamiltonian.xc.xcs['RESPONSE']
response.calculate_delta_xc()
EKs, Dxc = response.calculate_delta_xc_perturbation()
# fundamental band gap
# EKs = kohn-sham bandgap
# Dxc = derivative discontinuity
Gap = EKs+Dxc
print("Calculated band gap:", Gap)
```

## Spin-polarized GLLB-SC¶

Spin-polarized GLLB-SC is currently implemented to svn trunk. However there are some convergence issues releated to fermi smearing and the reference energy of highest orbital. Also some parts are still untested. The code will be improved to robust version soon, but in the meanwhile please contact mikael.kuisma@tut.fi before using.

[GLLB-sc] | M. Kuisma, J. Ojanen, J. Enkovaara, and T. T. Rantala1,
PHYSICAL REVIEW B 82, 115106 (2010),
Kohn-Sham potential with discontinuity for band gap materials,
DOI: 10.1103/PhysRevB.82.115106 |

[Castelli2012] | Ivano E. Castelli, Thomas Olsen, Soumendu Datta,
David D. Landis, Søren Dahl, Kristian S. Thygesena
and Karsten W. Jacobsen,
Energy Environ. Sci., 2012, 5, 5814,
Computational screening of perovskite metal oxides for optimal solar light
capture,
DOI: 10.1039/c1ee02717d |