# 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/yMJC2/src/ase_conversions.jl:100
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298717089349                   -0.85    5.2    150ms
2   -8.300237432302       -2.82       -1.26    1.1   74.3ms
3   -8.300442253457       -3.69       -1.89    3.4   95.0ms
4   -8.300460957488       -4.73       -2.76    1.1   70.6ms
5   -8.300464082518       -5.51       -3.10    2.2   87.3ms
6   -8.300464416259       -6.48       -3.30    1.6   76.4ms
7   -8.300464532072       -6.94       -3.45    3.8   93.7ms
8   -8.300464594175       -7.21       -3.60    1.0   70.2ms
9   -8.300464628680       -7.46       -3.78    1.5   75.9ms
10   -8.300464639138       -7.98       -3.95    1.0   70.9ms
11   -8.300464643593       -8.35       -4.33    1.0   68.9ms
self_consistent_field(aluminium_setup(2); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/yMJC2/src/ase_conversions.jl:100
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -16.65983184779                   -0.71    6.5    590ms
2   -16.67877347772       -1.72       -1.13    1.0    214ms
3   -16.67922456205       -3.35       -1.85    4.4    303ms
4   -16.67927562536       -4.29       -2.70    1.0    245ms
5   -16.67928562375       -5.00       -3.08    4.5    350ms
6   -16.67928613627       -6.29       -3.48    2.6    241ms
7   -16.67928621218       -7.12       -4.00    1.8    236ms
self_consistent_field(aluminium_setup(4); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/yMJC2/src/ase_conversions.jl:100
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32812713419                   -0.56    7.4    1.30s
2   -33.33473934737       -2.18       -1.00    1.4    717ms
3   -33.33602071491       -2.89       -1.72    5.8    1.01s
4   -33.33614884820       -3.89       -2.63    1.2    717ms
5   -33.33687548956       -3.14       -2.40    8.1    1.24s
6   -33.33689566170       -4.70       -2.48    3.4    740ms
7   -33.33694308052       -4.32       -3.71    1.0    656ms
8   -33.33694365714       -6.24       -3.73    5.6    1.22s
9   -33.33694370986       -7.28       -3.87    1.1    606ms
10   -33.33694377164       -7.21       -4.31    1.0    641ms

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/yMJC2/src/ase_conversions.jl:100
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -8.298762059920                   -0.85    5.5    130ms
2   -8.300304166633       -2.81       -1.59    1.0   55.9ms
3   -8.300441361363       -3.86       -2.65    2.2   70.2ms
4   -8.300425034425   +   -4.79       -2.45    4.8    113ms
5   -8.300464333065       -4.41       -3.36    1.0   62.4ms
6   -8.300464580858       -6.61       -3.78    3.0    113ms
7   -8.300464640239       -7.23       -4.30    1.4   83.8ms
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/yMJC2/src/ase_conversions.jl:100
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
1   -33.32334255839                   -0.56    8.0    1.27s
2   -33.32830250553       -2.30       -1.26    1.5    560ms
3   -23.48753826388   +    0.99       -0.57    6.4    1.22s
4   -33.01532813738        0.98       -1.29    5.4    1.11s
5   -33.21944727696       -0.69       -1.28    2.8    879ms
6   -33.32398799773       -0.98       -1.91    2.8    940ms
7   -32.64462432599   +   -0.17       -1.14    4.8    1.15s
8   -33.33416657074       -0.16       -2.27    4.8    1.10s
9   -33.33490428144       -3.13       -2.35    1.8    726ms
10   -33.33632282267       -2.85       -2.53    1.9    736ms
11   -33.33675309498       -3.37       -2.71    2.0    729ms
12   -33.33691512836       -3.79       -3.11    2.1    673ms
13   -33.33694040127       -4.60       -3.49    3.6    847ms
14   -33.33694346546       -5.51       -3.82    2.8    721ms
15   -33.33694334204   +   -6.91       -4.16    3.0    767ms

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.