# 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 of the axes of the original lattice.

The following code achieves this for aluminium:

using DFTK
using LinearAlgebra
using ASEconvert

function aluminium_setup(repeat=1; Ecut=7.0, kgrid=[2, 2, 2])
a = 7.65339
lattice = a * Matrix(I, 3, 3)
atoms     = [Al, Al, Al, Al]
positions = [[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]
unit_cell = periodic_system(lattice, atoms, positions)

# Make supercell in ASE:
# We convert our lattice to the conventions used in ASE, make the supercell
# and then convert back ...
supercell_ase = convert_ase(unit_cell) * pytuple((repeat, 1, 1))
supercell     = pyconvert(AbstractSystem, supercell_ase)

# Unfortunately right now the conversion to ASE drops the pseudopotential information,
# so we need to reattach it:
supercell = attach_psp(supercell, Al="hgh/lda/al-q3")

# Construct an LDA model and discretise
# 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_LDA(supercell; temperature=1e-3, symmetries=false)
PlaneWaveBasis(model; Ecut, kgrid)
end;

As part of the code we are using a routine inside the ASE, the atomistic simulation environment for creating the supercell and make use of the two-way interoperability of DFTK and ASE. For more details on this aspect see the documentation on Input and output formats.

Write an example supercell structure to a file to plot it:

setup = aluminium_setup(5)
convert_ase(periodic_system(setup.model)).write("al_supercell.png")
Python None

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);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/XF0Hn/src/ASEconvert.jl:144
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298175770731                   -0.85    5.0
2   -8.300164919387       -2.70       -1.25    1.2    168ms
3   -8.300424099817       -3.59       -1.88    2.2    189ms
4   -8.300461200439       -4.43       -2.72    2.9    214ms
5   -8.300464124639       -5.53       -3.17    2.1    210ms
6   -8.300464367910       -6.61       -3.31   12.1    545ms
7   -8.300464494764       -6.90       -3.45    4.5    267ms
8   -8.300464575229       -7.09       -3.60    2.5    227ms
9   -8.300464628254       -7.28       -3.82    2.8    262ms
10   -8.300464637701       -8.02       -3.97    1.2    185ms
11   -8.300464643054       -8.27       -4.27    2.8    256ms
self_consistent_field(aluminium_setup(2); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/XF0Hn/src/ASEconvert.jl:144
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -16.64203981904                   -0.70    6.5
2   -16.67865468820       -1.44       -1.14    1.5    483ms
3   -16.67918808523       -3.27       -1.88    2.1    473ms
4   -16.67927470002       -4.06       -2.74    3.4    546ms
5   -16.67928548367       -4.97       -3.10    6.1    699ms
6   -16.67928619797       -6.15       -3.52    2.0    440ms
7   -16.67928621489       -7.77       -3.99    1.8    420ms
8   -16.67928622156       -8.18       -4.60    2.6    498ms
self_consistent_field(aluminium_setup(4); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/XF0Hn/src/ASEconvert.jl:144
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32587932626                   -0.56    7.2
2   -33.33279894596       -2.16       -1.00    1.0    1.53s
3   -33.33414973048       -2.87       -1.73    4.4    1.92s
4   -33.33428581119       -3.87       -2.65    2.2    1.62s
5   -33.33501490312       -3.14       -2.41    3.6    2.15s
6   -33.33694240686       -2.72       -2.54    9.4    2.31s
7   -33.33694273933       -6.48       -2.57    1.0    1.43s
8   -33.33690057208   +   -4.38       -2.49    3.2    1.63s
9   -33.33689517013   +   -5.27       -2.47    1.1    1.46s
10   -33.33689865166       -5.46       -2.49    1.0    1.41s
11   -33.33691257812       -4.86       -2.57    1.0    1.42s
12   -33.33691641804       -5.42       -2.60    1.0    1.46s
13   -33.33692151708       -5.29       -2.64    1.0    1.43s
14   -33.33693871238       -4.76       -2.96    1.2    1.40s
15   -33.33694184583       -5.50       -3.17    2.2    1.69s
16   -33.33694235590       -6.29       -3.23    1.9    1.44s
17   -33.33694376715       -5.85       -4.24    1.8    1.71s

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());
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/XF0Hn/src/ASEconvert.jl:144
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298337183387                   -0.85    5.2
2   -8.300281326991       -2.71       -1.58    1.0    132ms
3   -8.300428876651       -3.83       -2.55    3.2    227ms
4   -8.300388102546   +   -4.39       -2.31    5.5    279ms
5   -8.300463989148       -4.12       -3.31    1.0    144ms
6   -8.300464480045       -6.31       -3.66    3.9    250ms
7   -8.300464640355       -6.80       -4.32    2.4    215ms
self_consistent_field(aluminium_setup(4); tol=1e-4, mixing=SimpleMixing());
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/XF0Hn/src/ASEconvert.jl:144
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32463596485                   -0.56    7.0
2   -33.32751744969       -2.54       -1.27    1.0    1.25s
3   -24.93479817164   +    0.92       -0.60    5.6    2.39s
4   -33.17992984630        0.92       -1.43    5.6    2.62s
5   -33.27464144636       -1.02       -1.36    2.6    1.77s
6   -33.11649150024   +   -0.80       -1.39    3.2    1.83s
7   -33.26023191478       -0.84       -1.61    3.1    1.81s
8   -33.33552733563       -1.12       -2.28    2.5    1.55s
9   -33.33323264565   +   -2.64       -2.19    3.1    2.07s
10   -33.33555758947       -2.63       -2.44    1.9    1.58s
11   -33.33678280108       -2.91       -2.85    2.6    1.58s
12   -33.33691751738       -3.87       -3.17    3.4    1.85s
13   -33.33694034148       -4.64       -3.45    2.8    1.79s
14   -33.33694283594       -5.60       -3.65    2.6    1.76s
15   -33.33694065413   +   -5.66       -3.78    3.0    1.82s
16   -33.33694374106       -5.51       -4.39    2.6    1.62s

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.