Creating and modelling metallic supercells

In this section we will be concerned with modelling supercells of aluminium. When dealing with periodic problems there is no unique definition of the lattice: Clearly any duplication of the lattice along an axis is also a valid repetitive unit to describe exactly the same system. This is exactly what a supercell is: An $n$-fold repetition along one (or multiple) axes of the original lattice.

The following code achieves this for aluminium:

using AtomsBuilder
using DFTK
using LinearAlgebra
using Unitful
using UnitfulAtomic

function aluminium_setup(repeat=1; Ecut=7.0, kgrid=[2, 2, 2])
# Use AtomsBuilder to setup aluminium cubic unit cell (4 Al atoms)
# with provided lattice constant, see [AtomsBase integration](@ref) for details.
unit_cell = bulk(:Al; a=7.65339u"bohr", cubic=true)

# Make a supercell and attach pseudopotential information:
supercell = unit_cell * (repeat, 1, 1)
supercell = attach_psp(supercell; Al="hgh/lda/al-q3")

# Construct an LDA model and discretize
# Note: We disable symmetries explicitly here. Otherwise the problem sizes
#       we are able to run on the CI are too simple to observe the numerical
#       instabilities we want to trigger here.
model = model_DFT(supercell; functionals=LDA(), temperature=1e-3, symmetries=false)
PlaneWaveBasis(model; Ecut, kgrid)
end;

As expected we obtain the unit cell for repeat=1:

aluminium_setup(1)
PlaneWaveBasis discretization:
architecture         : DFTK.CPU()
num. mpi processes   : 1

Ecut                 : 7.0 Ha
fft_size             : (24, 24, 24), 13824 total points
kgrid                : MonkhorstPack([2, 2, 2])
num.   red. kpoints  : 8
num. irred. kpoints  : 8

Discretized Model(lda_x+lda_c_pw, 3D):
lattice (in Bohr)    : [7.65339   , 0         , 0         ]
[0         , 7.65339   , 0         ]
[0         , 0         , 7.65339   ]
unit cell volume     : 448.29 Bohr³

atoms                : Al₄
atom potentials      : ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")

num. electrons       : 12
spin polarization    : none
temperature          : 0.001 Ha
smearing             : DFTK.Smearing.FermiDirac()

terms                : Kinetic()
AtomicLocal()
AtomicNonlocal()
Ewald(nothing)
PspCorrection()
Hartree()
Xc(lda_x, lda_c_pw)
Entropy()

and 5-fold as large supercell with repeat=5:

aluminium_setup(5)
PlaneWaveBasis discretization:
architecture         : DFTK.CPU()
num. mpi processes   : 1

Ecut                 : 7.0 Ha
fft_size             : (96, 24, 24), 55296 total points
kgrid                : MonkhorstPack([2, 2, 2])
num.   red. kpoints  : 8
num. irred. kpoints  : 8

Discretized Model(lda_x+lda_c_pw, 3D):
lattice (in Bohr)    : [38.267    , 0         , 0         ]
[0         , 7.65339   , 0         ]
[0         , 0         , 7.65339   ]
unit cell volume     : 2241.5 Bohr³

atoms                : Al₂₀
atom potentials      : ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")
ElementPsp(Al; psp="hgh/lda/al-q3")

num. electrons       : 60
spin polarization    : none
temperature          : 0.001 Ha
smearing             : DFTK.Smearing.FermiDirac()

terms                : Kinetic()
AtomicLocal()
AtomicNonlocal()
Ewald(nothing)
PspCorrection()
Hartree()
Xc(lda_x, lda_c_pw)
Entropy()

As we will see in this notebook the modelling of a system generally becomes harder if the system becomes larger.

• This sounds like a trivial statement as per se the cost per SCF step increases as the system (and thus $N$) gets larger.
• But there is more to it: If one is not careful also the number of SCF iterations increases as the system gets larger.
• The aim of a proper computational treatment of such supercells is therefore to ensure that the number of SCF iterations remains constant when the system size increases.

For achieving the latter DFTK by default employs the LdosMixing preconditioner [HL2021] during the SCF iterations. This mixing approach is completely parameter free, but still automatically adapts to the treated system in order to efficiently prevent charge sloshing. As a result, modelling aluminium slabs indeed takes roughly the same number of SCF iterations irrespective of the supercell size:

M. F. Herbst and A. Levitt. Black-box inhomogeneous preconditioning for self-consistent field iterations in density functional theory. J. Phys. Cond. Matt 33 085503 (2021). ArXiv:2009.01665

self_consistent_field(aluminium_setup(1); tol=1e-4);
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298674011822                   -0.85    5.4    144ms
2   -8.300226725651       -2.81       -1.25    1.2   73.2ms
3   -8.300439523098       -3.67       -1.89    3.2   98.5ms
4   -8.300460171145       -4.69       -2.76    1.0   70.5ms
5   -8.300464131658       -5.40       -3.11    2.1   90.6ms
6   -8.300464457790       -6.49       -3.30    1.2    116ms
7   -8.300464549583       -7.04       -3.45    1.0   67.6ms
8   -8.300464599257       -7.30       -3.60    1.1   69.0ms
9   -8.300464631597       -7.49       -3.80    1.2   71.4ms
10   -8.300464635902       -8.37       -3.88    1.0   67.9ms
11   -8.300464642427       -8.19       -4.12    1.0   70.1ms
self_consistent_field(aluminium_setup(2); tol=1e-4);
┌ Warning: Eigensolver not converged
│   n_iter =
│    8-element Vector{Int64}:
│      8
│      9
│      7
│      3
│     11
│      6
│      5
│      7
└ @ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -16.66621202357                   -0.71    7.0    394ms
2   -16.67873072739       -1.90       -1.13    1.2    213ms
3   -16.67921893779       -3.31       -1.86    2.8    221ms
4   -16.67926956364       -4.30       -2.70    2.4    215ms
5   -16.67928464257       -4.82       -3.07    5.2    315ms
6   -16.67928613856       -5.83       -3.46    1.5    181ms
7   -16.67928620525       -7.18       -3.96    1.8    186ms
8   -16.67928621973       -7.84       -4.45    3.4    234ms
self_consistent_field(aluminium_setup(4); tol=1e-4);
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32234078063                   -0.56    7.6    1.31s
2   -33.33463781585       -1.91       -1.00    1.5    661ms
3   -33.33600901766       -2.86       -1.72    6.6    948ms
4   -33.33612334766       -3.94       -2.64    1.8    721ms
┌ Warning: Eigensolver not converged
│   n_iter =
│    8-element Vector{Int64}:
│      5
│      3
│      3
│     18
│     10
│      7
│      2
│      9
└ @ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
5   -33.33678663416       -3.18       -2.23    7.1    1.09s
6   -33.33684314959       -4.25       -2.33    1.0    628ms
7   -33.33694276398       -4.00       -3.66    1.2    682ms
8   -33.33694366257       -6.05       -3.65    6.6    1.19s
9   -33.33694373941       -7.11       -3.87    1.0    584ms
10   -33.33694377229       -7.48       -4.30    1.0    653ms

When switching off explicitly the LdosMixing, by selecting mixing=SimpleMixing(), the performance of number of required SCF steps starts to increase as we increase the size of the modelled problem:

self_consistent_field(aluminium_setup(1); tol=1e-4, mixing=SimpleMixing());
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298617922453                   -0.85    5.4    156ms
2   -8.300274663013       -2.78       -1.59    1.1   63.9ms
3   -8.300436306820       -3.79       -2.70    2.1   79.1ms
4   -8.300442855252       -5.18       -2.58    3.5    126ms
5   -8.300464312669       -4.67       -3.32    1.0   65.5ms
6   -8.300464597873       -6.54       -3.78    2.1    144ms
7   -8.300464640978       -7.37       -4.44    1.6   75.3ms
self_consistent_field(aluminium_setup(4); tol=1e-4, mixing=SimpleMixing());
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32369422115                   -0.56    7.6    1.29s
2   -33.32645771699       -2.56       -1.26    1.6    558ms
3   -21.75825743191   +    1.06       -0.53    6.1    1.21s
4   -33.03102096704        1.05       -1.30    5.4    1.18s
5   -33.23115870570       -0.70       -1.25    3.2    901ms
6   -33.07076117151   +   -0.79       -1.35    3.4    849ms
7   -33.28561343448       -0.67       -1.69    3.2    786ms
8   -33.33526559400       -1.30       -2.22    1.8    600ms
9   -33.33450990158   +   -3.12       -2.32    3.5    762ms
10   -33.33586315813       -2.87       -2.47    1.8    667ms
11   -33.33664589278       -3.11       -2.70    2.0    699ms
12   -33.33690053331       -3.59       -3.07    2.2    657ms
13   -33.33693847493       -4.42       -3.38    3.8    873ms
14   -33.33694230824       -5.42       -3.65    2.5    792ms
15   -33.33694361119       -5.89       -4.23    1.9    645ms

For completion let us note that the more traditional mixing=KerkerMixing() approach would also help in this particular setting to obtain a constant number of SCF iterations for an increasing system size (try it!). In contrast to LdosMixing, however, KerkerMixing is only suitable to model bulk metallic system (like the case we are considering here). When modelling metallic surfaces or mixtures of metals and insulators, KerkerMixing fails, while LdosMixing still works well. See the Modelling a gallium arsenide surface example or [HL2021] for details. Due to the general applicability of LdosMixing this method is the default mixing approach in DFTK.