# 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.

In [1]:
using DFTK

a = 5.42352  # Bohr
lattice = a / 2 * [[-1  1  1];
[ 1 -1  1];
[ 1  1 -1]]
atoms = [Fe => [zeros(3)]];


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

In [2]:
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, Ecut; kgrid=kgrid)

scfres_nospin = self_consistent_field(basis_nospin, tol=1e-6, mixing=KerkerMixing());

n     Free energy       Eₙ-Eₙ₋₁     ρout-ρin   Diag
---   ---------------   ---------   --------   ----
1   -16.64728119134         NaN   3.28e-01    5.5
2   -16.64777994357   -4.99e-04   7.77e-02    1.0
3   -16.64782767753   -4.77e-05   3.29e-03    1.3
4   -16.64783287147   -5.19e-06   1.81e-03    3.0
5   -16.64783419209   -1.32e-06   3.69e-04    1.5
6   -16.64783430541   -1.13e-07   1.01e-04    2.0

In [3]:
scfres_nospin.energies

Out[3]:
Energy breakdown:
Kinetic             15.9217387
AtomicLocal         -5.0697469
AtomicNonlocal      -5.2207791
Ewald               -21.4723040
PspCorrection       1.8758831
Hartree             0.7794635
Xc                  -3.4438016
Entropy             -0.0182880

total               -16.647834305414


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.

In [4]:
magnetic_moments = [Fe => [4, ]];


!!! tip "Units of the magnetisation and magnetic moments in DFTK" 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.

In [5]:
model = model_LDA(lattice, atoms, magnetic_moments=magnetic_moments, temperature=0.01)
basis = PlaneWaveBasis(model, Ecut; kgrid=kgrid)
ρspin = guess_spin_density(basis, magnetic_moments)
scfres = self_consistent_field(basis, tol=1e-6, ρspin=ρspin, mixing=KerkerMixing());

n     Free energy       Eₙ-Eₙ₋₁     ρout-ρin   Magnet   Diag
---   ---------------   ---------   --------   ------   ----
1   -16.65997813723         NaN   3.41e-01    2.620    4.4
2   -16.66626178749   -6.28e-03   6.92e-02    2.428    1.1
3   -16.66694036542   -6.79e-04   8.44e-03    2.349    2.3
4   -16.66698659362   -4.62e-05   3.61e-03    2.320    2.1
5   -16.66699462109   -8.03e-06   6.67e-04    2.309    2.0
6   -16.66699628953   -1.67e-06   3.60e-04    2.301    2.1
7   -16.66699652132   -2.32e-07   2.56e-05    2.297    1.9

In [6]:
scfres.energies

Out[6]:
Energy breakdown:
Kinetic             16.3014804
AtomicLocal         -5.2260152
AtomicNonlocal      -5.4135666
Ewald               -21.4723040
PspCorrection       1.8758831
Hartree             0.8201275
Xc                  -3.5395226
Entropy             -0.0130791

total               -16.666996521318


!!! note "Model and magnetic moments" 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

In [7]:
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.6478343054138
Magnetic case:    -16.66699652131841
Difference:       -0.0191622159046112


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:

In [8]:
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.999998813959927, 0.9999988139500723, 0.9999988139248156, 0.9585663615238899, 0.9585660825517692, 1.1540005460226977e-29]
(scfres.occupation[idown])[1:7] = [1.0, 0.8326963305887993, 0.8326946468307682, 0.8326940758162382, 7.841244883316987e-6, 7.84117085952528e-6, 1.5498955163930567e-32]


Similarly the eigenvalues differ

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

(scfres.eigenvalues[iup])[1:7] = [-0.06926582057791496, 0.35688336276284666, 0.35688344585323595, 0.35688365879873407, 0.4619187983956415, 0.4619188686355841, 1.1596495861551466]
(scfres.eigenvalues[idown])[1:7] = [-0.030407774628023503, 0.47728367074213734, 0.47728379160303536, 0.4772838325904908, 0.6108933066872386, 0.6108934010915362, 1.2257776101585878]


!!! note "k-points in collinear calculations" 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.

In [10]:
using Plots
plot_dos(scfres)

Out[10]:

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

In [11]:
using Unitful
using UnitfulAtomic
plot_bandstructure(scfres, kline_density=3, unit=u"hartree")

Computing bands along kpath:
Γ -> H -> N -> Γ -> P -> H  and  P -> N
Diagonalising Hamiltonian kblocks: 100%|████████████████| Time: 0:00:03

Out[11]: