# 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]]
Fe = ElementPsp(:Fe, psp=load_psp("hgh/lda/Fe-q8.hgh"))
atoms = [Fe => [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, temperature=0.01)
basis_nospin = PlaneWaveBasis(model_nospin; kgrid, Ecut)
scfres_nospin = self_consistent_field(basis_nospin, tol=1e-6, mixing=KerkerMixing());
```

n Free energy Eₙ-Eₙ₋₁ ρout-ρin α Diag --- --------------- --------- -------- ---- ---- 1 -16.64697437770 NaN 3.28e-01 0.80 5.2 2 -16.64775196596 -7.78e-04 7.79e-02 0.80 1.0 3 -16.64782644420 -7.45e-05 3.28e-03 0.80 2.2 4 -16.64783292037 -6.48e-06 1.85e-03 0.80 3.5 5 -16.64783426501 -1.34e-06 2.91e-04 0.80 2.0 6 -16.64783431092 -4.59e-08 1.97e-05 0.80 2.2

`scfres_nospin.energies`

Energy breakdown (in Ha): Kinetic 15.9223265 AtomicLocal -5.0700773 AtomicNonlocal -5.2211015 Ewald -21.4723040 PspCorrection 1.8758831 Hartree 0.7795593 Xc -3.4438321 Entropy -0.0182884 total -16.647834310915

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 = [Fe => [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, magnetic_moments=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=KerkerMixing());
```

n Free energy Eₙ-Eₙ₋₁ ρout-ρin Magnet α Diag --- --------------- --------- -------- ------ ---- ---- 1 -16.65996737574 NaN 3.11e-01 2.620 0.80 4.6 2 -16.66626008598 -6.29e-03 6.98e-02 2.428 0.80 1.0 3 -16.66694926207 -6.89e-04 9.42e-03 2.349 0.80 2.9 4 -16.66698692798 -3.77e-05 4.33e-03 2.320 0.80 2.8 5 -16.66699444786 -7.52e-06 1.79e-03 2.309 0.80 2.2 6 -16.66699631155 -1.86e-06 5.51e-04 2.301 0.80 1.5 7 -16.66699651931 -2.08e-07 4.58e-05 2.297 0.80 1.5

`scfres.energies`

Energy breakdown (in Ha): Kinetic 16.3014779 AtomicLocal -5.2260052 AtomicNonlocal -5.4135574 Ewald -21.4723040 PspCorrection 1.8758831 Hartree 0.8201243 Xc -3.5395374 Entropy -0.0130777 total -16.666996519311

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.647834310915375 Magnetic case: -16.66699651931134 Difference: -0.019162208395965052

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.99999881436976, 0.9999988143603802, 0.999998814358606, 0.9585782155714087, 0.958577798743015, 1.1545020537717335e-29] (scfres.occupation[idown])[1:7] = [1.0, 0.8324274751885015, 0.8324256725568625, 0.8324252349732398, 7.827641875448094e-6, 7.827584219756814e-6, 1.5495596710464032e-32]

Similarly the eigenvalues differ

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

(scfres.eigenvalues[iup])[1:7] = [-0.06926962988492687, 0.3568792908676717, 0.3568793699795571, 0.3568793849438789, 0.46191519752927435, 0.46191530250740737, 1.1596446254586257] (scfres.eigenvalues[idown])[1:7] = [-0.030402398907591242, 0.47730234118108367, 0.4773024704088698, 0.4773025017783741, 0.6109100540875425, 0.610910127744917, 1.2257791614620697]

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)
```