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)
Al = ElementPsp(:Al; psp=load_psp("hgh/lda/al-q3"))
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/I2wvg/src/ase_conversions.jl:100
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.298672246630 -0.85 5.1 153ms
2 -8.300234082817 -2.81 -1.26 1.0 80.8ms
3 -8.300445091237 -3.68 -1.90 1.8 88.2ms
4 -8.300461883520 -4.77 -2.77 1.9 91.3ms
5 -8.300464333566 -5.61 -3.17 2.8 110ms
6 -8.300464518279 -6.73 -3.32 2.6 105ms
7 -8.300464582919 -7.19 -3.46 1.0 83.1ms
8 -8.300464617572 -7.46 -3.60 1.0 76.3ms
9 -8.300464636789 -7.72 -3.79 1.0 76.3ms
10 -8.300464641238 -8.35 -3.94 1.0 80.4ms
11 -8.300464643653 -8.62 -4.22 1.0 75.5ms
self_consistent_field(aluminium_setup(2); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/I2wvg/src/ase_conversions.jl:100
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -16.65625816281 -0.71 6.8 378ms
2 -16.67882259220 -1.65 -1.12 1.0 209ms
3 -16.67923209481 -3.39 -1.85 2.4 217ms
4 -16.67927613382 -4.36 -2.63 3.9 240ms
5 -16.67928513960 -5.05 -3.09 5.0 286ms
6 -16.67928612924 -6.00 -3.45 2.4 216ms
7 -16.67928620583 -7.12 -4.15 1.6 189ms
self_consistent_field(aluminium_setup(4); tol=1e-4);
┌ Warning: Skipping atomic property pseudopotential, which is not supported in ASE.
└ @ ASEconvert ~/.julia/packages/ASEconvert/I2wvg/src/ase_conversions.jl:100
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -33.31959461740 -0.56 7.5 1.32s
2 -33.32116873025 -2.80 -1.00 2.1 714ms
3 -33.33575172476 -1.84 -1.63 5.0 917ms
4 -33.33609488010 -3.46 -2.14 1.1 650ms
5 -33.33684796492 -3.12 -2.35 4.4 904ms
6 -33.33688588721 -4.42 -2.46 4.9 825ms
7 -33.33694124688 -4.26 -3.34 1.2 660ms
8 -33.33694350761 -5.65 -3.62 6.0 1.05s
9 -33.33694367013 -6.79 -3.80 1.8 640ms
10 -33.33694377083 -7.00 -4.38 1.9 664ms
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/I2wvg/src/ase_conversions.jl:100
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.298519379028 -0.85 5.0 148ms
2 -8.300266517198 -2.76 -1.59 1.5 67.6ms
3 -8.300439818376 -3.76 -2.71 1.2 65.2ms
4 -8.300448431344 -5.06 -2.64 7.1 160ms
5 -8.300464355368 -4.80 -3.35 1.0 70.5ms
6 -8.300464596714 -6.62 -3.82 2.0 95.4ms
7 -8.300464640645 -7.36 -4.45 1.4 83.3ms
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/I2wvg/src/ase_conversions.jl:100
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -33.32179825061 -0.56 7.9 1.29s
2 -33.26192709381 + -1.22 -1.23 1.5 571ms
┌ Warning: Eigensolver not converged
│ n_iter =
│ 8-element Vector{Int64}:
│ 17
│ 15
│ 7
│ 8
│ 7
│ 8
│ 7
│ 5
└ @ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
3 +24.38581082909 + 1.76 -0.18 9.2 1.66s
4 -33.30268221709 1.76 -1.56 6.4 1.41s
5 -32.98719657136 + -0.50 -1.18 3.5 918ms
6 -28.24296210456 + 0.68 -0.71 5.2 1.01s
7 -33.30809022829 0.70 -1.75 5.0 947ms
8 -33.33448311146 -1.58 -2.10 2.0 644ms
9 -33.33356498131 + -3.04 -2.06 2.5 787ms
10 -33.33525736259 -2.77 -2.43 1.8 642ms
11 -33.33645734849 -2.92 -2.66 1.5 601ms
12 -33.33671849076 -3.58 -2.84 3.1 742ms
13 -33.33692256881 -3.69 -3.27 3.0 749ms
14 -33.33692960567 -5.15 -3.45 3.2 746ms
15 -33.33693376002 -5.38 -3.55 2.4 693ms
16 -33.33693967719 -5.23 -3.73 3.2 796ms
17 -33.33694361470 -5.40 -4.34 1.8 612ms
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.