# Collinear spin and magnetic systems

In this example we consider iron in the BCC phase. To show that this material is ferromagnetic we will model it once allowing collinear spin polarization and once without and compare the resulting SCF energies. In particular the ground state can only be found if collinear spins are allowed.

First we setup BCC iron without spin polarization using a single iron atom inside the unit cell.

```
using DFTK
a = 5.42352 # Bohr
lattice = a / 2 * [[-1 1 1];
[ 1 -1 1];
[ 1 1 -1]]
atoms = [ElementPsp(:Fe, psp=load_psp("hgh/lda/Fe-q8.hgh"))]
positions = [zeros(3)];
```

To get the ground-state energy we use an LDA model and rather moderate discretisation parameters.

```
kgrid = [3, 3, 3] # k-point grid (Regular Monkhorst-Pack grid)
Ecut = 15 # kinetic energy cutoff in Hartree
model_nospin = model_LDA(lattice, atoms, positions, temperature=0.01)
basis_nospin = PlaneWaveBasis(model_nospin; kgrid, Ecut)
scfres_nospin = self_consistent_field(basis_nospin; tol=1e-4, mixing=KerkerDosMixing());
```

```
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -16.65003392089 -0.48 5.0
2 -16.65070116177 -3.18 -1.01 1.0 21.9ms
3 -16.65080966005 -3.96 -2.32 1.5 23.7ms
4 -16.65082419857 -4.84 -2.81 2.5 29.9ms
5 -16.65082462593 -6.37 -3.27 1.8 25.3ms
6 -16.65082469060 -7.19 -3.79 2.0 27.7ms
7 -16.65082469744 -8.16 -4.28 2.0 27.9ms
```

`scfres_nospin.energies`

```
Energy breakdown (in Ha):
Kinetic 15.9207771
AtomicLocal -5.0692860
AtomicNonlocal -5.2201935
Ewald -21.4723040
PspCorrection 1.8758831
Hartree 0.7793330
Xc -3.4467465
Entropy -0.0182879
total -16.650824697440
```

Since we did not specify any initial magnetic moment on the iron atom, DFTK will automatically assume that a calculation with only spin-paired electrons should be performed. As a result the obtained ground state features no spin-polarization.

Now we repeat the calculation, but give the iron atom an initial magnetic moment. For specifying the magnetic moment pass the desired excess of spin-up over spin-down electrons at each centre to the `Model`

and the guess density functions. In this case we seek the state with as many spin-parallel $d$-electrons as possible. In our pseudopotential model the 8 valence electrons are 2 pair of $s$-electrons, 1 pair of $d$-electrons and 4 unpaired $d$-electrons giving a desired magnetic moment of `4`

at the iron centre. The structure (i.e. pair mapping and order) of the `magnetic_moments`

array needs to agree with the `atoms`

array and `0`

magnetic moments need to be specified as well.

`magnetic_moments = [4];`

Unlike all other quantities magnetisation and magnetic moments in DFTK are given in units of the Bohr magneton $μ_B$, which in atomic units has the value $\frac{1}{2}$. Since $μ_B$ is (roughly) the magnetic moment of a single electron the advantage is that one can directly think of these quantities as the excess of spin-up electrons or spin-up electron density.

We repeat the calculation using the same model as before. DFTK now detects the non-zero moment and switches to a collinear calculation.

```
model = model_LDA(lattice, atoms, positions; magnetic_moments, temperature=0.01)
basis = PlaneWaveBasis(model; Ecut, kgrid)
ρ0 = guess_density(basis, magnetic_moments)
scfres = self_consistent_field(basis, tol=1e-6; ρ=ρ0, mixing=KerkerDosMixing());
```

```
n Energy log10(ΔE) log10(Δρ) Magnet Diag Δtime
--- --------------- --------- --------- ------ ---- ------
1 -16.66160573500 -0.51 2.618 4.6
2 -16.66810567562 -2.19 -1.09 2.445 1.4 46.2ms
3 -16.66904720737 -3.03 -2.06 2.338 2.2 55.9ms
4 -16.66909978758 -4.28 -2.72 2.303 2.0 88.0ms
5 -16.66910285123 -5.51 -2.94 2.296 1.9 53.9ms
6 -16.66910414134 -5.89 -3.48 2.286 1.8 51.2ms
7 -16.66910416882 -7.56 -3.77 2.286 1.8 52.2ms
8 -16.66910417410 -8.28 -4.27 2.285 1.8 52.5ms
9 -16.66910417505 -9.02 -5.01 2.286 1.8 51.1ms
10 -16.66910417508 -10.45 -5.33 2.286 2.1 57.6ms
11 -16.66910417508 + -11.15 -5.75 2.286 1.2 47.7ms
12 -16.66910417508 -11.06 -6.15 2.286 1.6 51.7ms
```

`scfres.energies`

```
Energy breakdown (in Ha):
Kinetic 16.2947210
AtomicLocal -5.2227270
AtomicNonlocal -5.4100289
Ewald -21.4723040
PspCorrection 1.8758831
Hartree 0.8191965
Xc -3.5406835
Entropy -0.0131612
total -16.669104175085
```

DFTK does not store the `magnetic_moments`

inside the `Model`

, but only uses them to determine the lattice symmetries. This step was taken to keep `Model`

(which contains the physical model) independent of the details of the numerical details such as the initial guess for the spin density.

In direct comparison we notice the first, spin-paired calculation to be a little higher in energy

```
println("No magnetization: ", scfres_nospin.energies.total)
println("Magnetic case: ", scfres.energies.total)
println("Difference: ", scfres.energies.total - scfres_nospin.energies.total);
```

```
No magnetization: -16.65082469743987
Magnetic case: -16.669104175084577
Difference: -0.018279477644707498
```

Notice that with the small cutoffs we use to generate the online documentation the calculation is far from converged. With more realistic parameters a larger energy difference of about 0.1 Hartree is obtained.

The spin polarization in the magnetic case is visible if we consider the occupation of the spin-up and spin-down Kohn-Sham orbitals. Especially for the $d$-orbitals these differ rather drastically. For example for the first $k$-point:

```
iup = 1
idown = iup + length(scfres.basis.kpoints) ÷ 2
@show scfres.occupation[iup][1:7]
@show scfres.occupation[idown][1:7];
```

```
(scfres.occupation[iup])[1:7] = [1.0, 0.9999987814402852, 0.9999987814402852, 0.9999987814402852, 0.9582253809004873, 0.9582253809004858, 1.1266796572455569e-29]
(scfres.occupation[idown])[1:7] = [1.0, 0.843893617898422, 0.843893617898422, 0.8438936178983847, 8.140867317653034e-6, 8.140867317652775e-6, 3.969117672041059e-33]
```

Similarly the eigenvalues differ

```
@show scfres.eigenvalues[iup][1:7]
@show scfres.eigenvalues[idown][1:7];
```

```
(scfres.eigenvalues[iup])[1:7] = [-0.06935856820419611, 0.3568855527238579, 0.3568855527238608, 0.3568855527238561, 0.46173600956460076, 0.46173600956460115, 1.1596208775809411]
(scfres.eigenvalues[idown])[1:7] = [-0.03125744573995039, 0.47618906282004236, 0.47618906282004236, 0.4761890628200452, 0.6102500070477195, 0.6102500070477198, 1.2391315925978825]
```

For collinear calculations the `kpoints`

field of the `PlaneWaveBasis`

object contains each $k$-point coordinate twice, once associated with spin-up and once with down-down. The list first contains all spin-up $k$-points and then all spin-down $k$-points, such that `iup`

and `idown`

index the same $k$-point, but differing spins.

We can observe the spin-polarization by looking at the density of states (DOS) around the Fermi level, where the spin-up and spin-down DOS differ.

```
using Plots
plot_dos(scfres)
```

Similarly the band structure shows clear differences between both spin components.

```
using Unitful
using UnitfulAtomic
plot_bandstructure(scfres; kline_density=6)
```