In this example we consider the modeling of a magnesium lattice as a simple example for a metallic system. For our treatment we will use the PBE exchange-correlation functional. First we import required packages and setup the lattice. Again notice that DFTK uses the convention that lattice vectors are specified column by column.

In [1]:

```
using DFTK
using Plots
using Unitful
using UnitfulAtomic
a = 3.01794 # bohr
b = 5.22722 # bohr
c = 9.77362 # bohr
lattice = [[-a -a 0]; [-b b 0]; [0 0 -c]]
Mg = ElementPsp(:Mg, psp=load_psp("hgh/pbe/Mg-q2"))
atoms = [Mg, Mg]
positions = [[2/3, 1/3, 1/4], [1/3, 2/3, 3/4]];
```

`Ecut`

is too small
as well as the minimal $k$-point spacing
`kspacing`

far too large to give a converged result.
These have been selected to obtain a fast execution time.
By default `PlaneWaveBasis`

chooses a `kspacing`

of `2π * 0.022`

inverse Bohrs, which is much more reasonable.

In [2]:

```
kspacing = 0.945 / u"angstrom" # Minimal spacing of k-points,
# in units of wavevectors (inverse Bohrs)
Ecut = 5 # Kinetic energy cutoff in Hartree
temperature = 0.01 # Smearing temperature in Hartree
smearing = DFTK.Smearing.FermiDirac() # Smearing method
# also supported: Gaussian,
# MarzariVanderbilt,
# and MethfesselPaxton(order)
model = model_DFT(lattice, atoms, positions, [:gga_x_pbe, :gga_c_pbe];
temperature, smearing)
kgrid = kgrid_from_minimal_spacing(lattice, kspacing)
basis = PlaneWaveBasis(model; Ecut, kgrid);
```

`0.8`

.
The default `LdosMixing`

should be suitable to converge metallic systems
like the one we model here. For the sake of demonstration we still switch to
Kerker mixing here.

In [3]:

```
scfres = self_consistent_field(basis, damping=0.8, mixing=KerkerMixing());
```

In [4]:

```
scfres.occupation[1]
```

Out[4]:

9-element Vector{Float64}: 1.9999999999941416 1.998551837628499 1.9905514388804668 1.2449692693582234e-17 1.2448840445943245e-17 1.0289493739024323e-17 1.0288617851515235e-17 2.988419344165716e-19 1.6623746630872163e-21

In [5]:

```
scfres.energies
```

Out[5]:

Energy breakdown (in Ha): Kinetic 0.7450614 AtomicLocal 0.3193178 AtomicNonlocal 0.3192778 Ewald -2.1544222 PspCorrection -0.1026056 Hartree 0.0061603 Xc -0.8615676 Entropy -0.0148387 total -1.743616749884

In [6]:

```
plot_dos(scfres)
```

Out[6]: