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
    num. julia threads   : 1
    num. DFTK  threads   : 1
    num. blas  threads   : 2
    num. fft   threads   : 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
    num. julia threads   : 1
    num. DFTK  threads   : 1
    num. blas  threads   : 2
    num. fft   threads   : 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.298680696951                   -0.85    5.4    154ms
  2   -8.300233602263       -2.81       -1.25    1.1   76.8ms
  3   -8.300441320452       -3.68       -1.89    1.9   88.4ms
  4   -8.300460490553       -4.72       -2.77    2.1    120ms
  5   -8.300464305034       -5.42       -3.15    2.4   99.2ms
  6   -8.300464511909       -6.68       -3.32    1.5   82.1ms
  7   -8.300464578344       -7.18       -3.47    1.1   74.8ms
  8   -8.300464613870       -7.45       -3.62    1.0   78.6ms
  9   -8.300464635788       -7.66       -3.81    1.0   70.5ms
 10   -8.300464639256       -8.46       -3.90    1.0   71.5ms
 11   -8.300464643124       -8.41       -4.14    1.1   80.2ms
self_consistent_field(aluminium_setup(2); tol=1e-4);
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
  1   -16.67570509555                   -0.70    6.2    403ms
  2   -16.67880551051       -2.51       -1.14    1.0    215ms
┌ Warning: Eigensolver not converged
  n_iter =
   8-element Vector{Int64}:
    2
    8
    3
    3
    2
    8
    1
    1
@ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
  3   -16.67923143554       -3.37       -1.87    3.5    305ms
  4   -16.67927635629       -4.35       -2.75    2.8    274ms
  5   -16.67928575326       -5.03       -3.21    3.5    291ms
  6   -16.67928617806       -6.37       -3.49    3.0    251ms
  7   -16.67928621254       -7.46       -3.92    1.2    196ms
  8   -16.67928622036       -8.11       -4.49    3.0    273ms
self_consistent_field(aluminium_setup(4); tol=1e-4);
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
  1   -33.32046006145                   -0.56    6.8    1.37s
  2   -33.33269450034       -1.91       -1.00    1.2    779ms
  3   -33.33410165654       -2.85       -1.74    4.6    1.56s
  4   -33.33426810564       -3.78       -2.66    1.2    709ms
  5   -33.33438764802       -3.92       -2.81    5.4    1.06s
  6   -33.33694135860       -2.59       -2.58    9.6    1.11s
  7   -33.33694004970   +   -5.88       -2.52    2.0    679ms
  8   -33.33694042618       -6.42       -3.25    1.6    678ms
  9   -33.33694220045       -5.75       -3.29    3.8    844ms
 10   -33.33694372202       -5.82       -3.90    1.2    677ms
 11   -33.33694377078       -7.31       -4.17    3.9    860ms

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.298651418613                   -0.85    5.2    154ms
  2   -8.300283950260       -2.79       -1.59    1.1   64.1ms
  3   -8.300439197919       -3.81       -2.69    2.2   88.4ms
  4   -8.300441988813       -5.55       -2.57    3.5    115ms
  5   -8.300464413735       -4.65       -3.37    1.0   62.7ms
  6   -8.300464602450       -6.72       -3.84    1.6   85.2ms
  7   -8.300464642175       -7.40       -4.49    1.6   75.7ms
self_consistent_field(aluminium_setup(4); tol=1e-4, mixing=SimpleMixing());
┌ Warning: Eigensolver not converged
  n_iter =
   8-element Vector{Int64}:
    11
     6
    12
     1
     8
     4
    10
     2
@ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime
---   ---------------   ---------   ---------   ----   ------
  1   -33.17692415455                   -0.56    6.8    1.38s
  2   -33.28231046266       -0.98       -1.24    3.5    745ms
  3   +0.775353850444   +    1.53       -0.29    6.1    1.52s
  4   -33.14936727115        1.53       -1.28    6.4    1.44s
  5   -33.16301067905       -1.87       -1.27    3.9    1.00s
  6   -32.36903314338   +   -0.10       -1.07    4.5    1.02s
  7   -33.17359225816       -0.09       -1.44    4.8    1.72s
  8   -33.32346760266       -0.82       -1.70    3.5    826ms
  9   -33.33184886496       -2.08       -2.11    1.8    707ms
 10   -33.33583104012       -2.40       -2.44    1.6    730ms
 11   -33.33691831622       -2.96       -2.99    2.5    754ms
 12   -33.33688976701   +   -4.54       -3.11    3.8    925ms
 13   -33.33692841985       -4.41       -3.34    2.8    833ms
 14   -33.33694172770       -4.88       -3.70    1.8    691ms
 15   -33.33694288980       -5.93       -3.98    2.0    678ms
 16   -33.33694340429       -6.29       -4.23    3.4    903ms

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.