Skip to content

Commit 00c9c48

Browse files
authored
Crude import of some material from DFTK school (#941)
1 parent 7f7e5d6 commit 00c9c48

21 files changed

+1074
-49
lines changed

docs/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ src/guide/tutorial.md
55
src/guide/tutorial.ipynb
66
src/guide/periodic_problems.ipynb
77
src/guide/periodic_problems.md
8+
src/guide/atomic_chains.ipynb
9+
src/guide/atomic_chains.md
10+
src/guide/self_consistent_field.ipynb
11+
src/guide/self_consistent_field.md
12+
src/guide/discretisation.ipynb
13+
src/guide/discretisation.md
814
src/tricks/scf_checkpoints.ipynb
915
src/tricks/scf_checkpoints.md
1016
/Artifacts.toml

docs/make.jl

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ PAGES = [
1717
"Home" => "index.md",
1818
"features.md",
1919
"Getting started" => [
20-
# Installing DFTK, tutorial, theoretical background
2120
"guide/installation.md",
22-
"Tutorial" => "guide/tutorial.jl",
23-
"guide/periodic_problems.jl",
21+
"guide/tutorial.jl",
22+
],
23+
"Background" => [
24+
# Theoretical background
2425
"guide/introductory_resources.md",
26+
"guide/periodic_problems.jl",
27+
"guide/discretisation.jl",
28+
"guide/atomic_chains.jl",
29+
"guide/density_functional_theory.md",
30+
"guide/self_consistent_field.jl",
2531
"school2022.md",
2632
],
2733
"Basic DFT calculations" => [
@@ -40,7 +46,6 @@ PAGES = [
4046
"Response and properties" => [
4147
"examples/polarizability.jl",
4248
"examples/forwarddiff.jl",
43-
"examples/dielectric.jl",
4449
],
4550
"Ecosystem integration" => [
4651
# This concerns the discussion of interfaces, IO and integration
@@ -60,6 +65,7 @@ PAGES = [
6065
"examples/custom_solvers.jl",
6166
"examples/scf_callbacks.jl",
6267
"examples/compare_solvers.jl",
68+
"examples/analysing_scf_convergence.jl",
6369
],
6470
"Nonstandard models" => [
6571
"examples/gross_pitaevskii.jl",

docs/src/guide/atomic_chains.jl

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# # Modelling atomic chains
2+
#
3+
# In [Periodic problems and plane-wave discretisations](@ref periodic-problems) we already
4+
# summarised the net effect of Bloch's theorem.
5+
# In this notebook, we will explore some basic facts about periodic systems,
6+
# starting from the very simplest model, a tight-binding monoatomic chain.
7+
# The solutions to the hands-on exercises are given at the bottom of the page.
8+
9+
# ## Monoatomic chain
10+
#
11+
# In this model, each site of an infinite 1D chain is a degree of freedom, and
12+
# the Hilbert space is $\ell^2(\mathbb Z)$, the space of square-summable
13+
# biinfinite sequences $(\psi_n)_{n \in \mathbb Z}$.
14+
#
15+
# Each site interacts by a "hopping term" with its neighbors, and the
16+
# Hamiltonian is
17+
# ```math
18+
# H = \left(\begin{array}{ccccc}
19+
# \dots&\dots&\dots&\dots&\dots \\
20+
# \dots& 0 & 1 & 0 & \dots\\
21+
# \dots&1 & 0 &1&\dots \\
22+
# \dots&0 & 1 & 0& \dots \\
23+
# \dots&\dots&\dots&\dots&…
24+
# \end{array}\right)
25+
# ```
26+
#
27+
# !!! tip "Exercise 1"
28+
# Find the eigenstates and eigenvalues of this Hamiltonian by
29+
# solving the second-order recurrence relation.
30+
#
31+
# !!! tip "Exercise 2"
32+
# Do the same when the system is truncated to a finite number of $N$
33+
# sites with periodic boundary conditions.
34+
#
35+
# We are now going to code this:
36+
37+
function build_monoatomic_hamiltonian(N::Integer, t)
38+
H = zeros(N, N)
39+
for n = 1:N-1
40+
H[n, n+1] = H[n+1, n] = t
41+
end
42+
H[1, N] = H[N, 1] = t # Periodic boundary conditions
43+
H
44+
end
45+
46+
# !!! tip "Exercise 3"
47+
# Compute the eigenvalues and eigenvectors of this Hamiltonian.
48+
# Plot them, and check whether they agree with theory.
49+
50+
# ## Diatomic chain
51+
# Now we are going to consider a diatomic chain `A B A B ...`, where the coupling
52+
# `A<->B` ($t_1$) is different from the coupling `B<->A` ($t_2$). We will use a new
53+
# index $\alpha$ to denote the `A` and `B` sites, so that wavefunctions are now
54+
# sequences $(\psi_{\alpha n})_{\alpha \in \{1, 2\}, n \in \mathbb Z}$.
55+
#
56+
# !!! tip "Exercise 4"
57+
# Show that eigenstates of this system can be looked for in the form
58+
# ```math
59+
# \psi_{\alpha n} = u_{\alpha} e^{ikn}
60+
# ```
61+
#
62+
# !!! tip "Exercise 5"
63+
# Show that, if $\psi$ is of the form above
64+
# ```math
65+
# (H \psi)_{\alpha n} = (H_k u)_\alpha e^{ikn},
66+
# ```
67+
# where
68+
# ```
69+
# H_k = \left(\begin{array}{cc}
70+
# 0 & t_1 + t_2 e^{-ik}\\
71+
# t_1 + t_2 e^{ik} & 0
72+
# \end{array}\right)
73+
# ```
74+
#
75+
# Let's now check all this numerically:
76+
77+
function build_diatomic_hamiltonian(N::Integer, t1, t2)
78+
## Build diatomic Hamiltonian with the two couplings
79+
## ... <-t2-> A <-t1-> B <-t2-> A <-t1-> B <-t2-> ...
80+
## We introduce unit cells as such:
81+
## ... <-t2-> | A <-t1-> B <-t2-> | A <-t1-> B <-t2-> | ...
82+
## Thus within a cell the A<->B coupling is t1 and across cell boundaries t2
83+
84+
H = zeros(2, N, 2, N)
85+
A, B = 1, 2
86+
for n = 1:N
87+
H[A, n, B, n] = H[B, n, A, n] = t1 # Coupling within cell
88+
end
89+
for n = 1:N-1
90+
H[B, n, A, n+1] = H[A, n+1, B, n] = t2 # Coupling across cells
91+
end
92+
H[A, 1, B, N] = H[B, N, A, 1] = t2 # Periodic BCs (A in cell1 with B in cell N)
93+
reshape(H, 2N, 2N)
94+
end
95+
96+
function build_diatomic_Hk(k::Integer, t1, t2)
97+
## Returns Hk such that H (u e^ikn) = (Hk u) e^ikn
98+
##
99+
## intra-cell AB hopping of t1, plus inter-cell hopping t2 between
100+
## site B (no phase shift) and site A (phase shift e^ik)
101+
[0 t1 + t2*exp(-im*k);
102+
t1 + t2*exp(im*k) 0 ]
103+
end
104+
105+
using Plots
106+
function plot_wavefunction(ψ)
107+
p = plot(real(ψ[1:2:end]), label="Re A")
108+
plot!(p, real(ψ[2:2:end]), label="Re B")
109+
end
110+
111+
# !!! tip "Exercise 6"
112+
# Check the above assertions. Use a $k$ of the form
113+
# $2 π \frac{l}{N}$ in order to have a $\psi$ that has the periodicity
114+
# of the supercell ($N$).
115+
116+
# !!! tip "Exercise 7"
117+
# Plot the band structure, i.e. the eigenvalues of $H_k$ as a function of $k$
118+
# Use the function `build_diatomic_Hk` to build the Hamiltonians.
119+
# Compare with the eigenvalues of the ("supercell") Hamiltonian from
120+
# `build_diatomic_hamiltonian`. In the case $t_1 = t_2$, how do the bands follow
121+
# from the previous study of the monoatomic chain?
122+
123+
# !!! tip "Exercise 8"
124+
# Repeat the above analysis in the case of a finite-difference
125+
# discretization of a continuous Hamiltonian $H = - \frac 1 2 \Delta + V(x)$
126+
# where $V$ is periodic
127+
# *Hint:* It is advisable to work through [Comparing discretization techniques](@ref)
128+
# before tackling this question.
129+
130+
# ## Solutions
131+
#
132+
# ### Exercise 1
133+
# !!! note "TODO"
134+
# This solution has not yet been written. Any help with a PR is appreciated.
135+
#
136+
# ### Exercise 2
137+
# !!! note "TODO"
138+
# This solution has not yet been written. Any help with a PR is appreciated.
139+
#
140+
# ### Exercise 3
141+
# !!! note "TODO"
142+
# This solution has not yet been written. Any help with a PR is appreciated.
143+
#
144+
# ### Exercise 4
145+
# !!! note "TODO"
146+
# This solution has not yet been written. Any help with a PR is appreciated.
147+
#
148+
# ### Exercise 5
149+
# !!! note "TODO"
150+
# This solution has not yet been written. Any help with a PR is appreciated.
151+
#
152+
# ### Exercise 6
153+
# !!! note "TODO"
154+
# This solution has not yet been written. Any help with a PR is appreciated.
155+
#
156+
# ### Exercise 7
157+
# !!! note "TODO"
158+
# This solution has not yet been written. Any help with a PR is appreciated.
159+
#
160+
# ### Exercise 8
161+
# !!! note "TODO"
162+
# This solution has not yet been written. Any help with a PR is appreciated.
163+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Introduction to density-functional theory
2+
3+
!!! note "More details"
4+
This chapter only gives a very rough overview for now. Further details
5+
can be found in the [summary of DFT theory](https://michael-herbst.com/teaching/2022-mit-workshop-dftk/2022-mit-workshop-dftk/DFT_Theory.pdf)
6+
or in the [Introductory Resources](@ref introductory-resources).
7+
8+
Density-functional theory is a simplification of the full electronic
9+
Schrödinger equation leading to an effective single-particle model.
10+
Mathematically this can be cast as an energy minimisation problem
11+
in the electronic density $\rho$. In the Kohn-Sham variant
12+
of density-functional theory the corresponding first-order stationarity
13+
conditions can be written as the non-linear eigenproblem
14+
```math
15+
\begin{aligned}
16+
&\left( -\frac12 \Delta + V\left(\rho\right) \right) \psi_i = \varepsilon_i \psi_i, \\
17+
V(\rho) = &\, V_\text{nuc} + v_C \rho + V_\text{XC}(\rho), \\
18+
\rho = &\sum_{i=1}^N f(\varepsilon_i) \abs{\psi_i}^2, \\
19+
\end{aligned}
20+
```
21+
where $\{\psi_1,\ldots, \psi_N\}$ are $N$ orthonormal orbitals,
22+
the one-particle eigenfunctions and $f$ is the occupation function
23+
(e.g. [`DFTK.Smearing.FermiDirac`](@ref), [`DFTK.Smearing.Gaussian`](@ref)
24+
or [`DFTK.Smearing.MarzariVanderbilt`](@ref))
25+
chosen such that the integral of the density is equal to the number of electrons in the system.
26+
Further the potential terms that make up $V(\rho)$ are
27+
- the nuclear attraction potential $V_\text{nuc}$ (interaction of electrons and nuclei)
28+
- the exchange-correlation potential $V_\text{xc}$,
29+
depending on $\rho$ and potentially its derivatives.
30+
- The Hartree potential $v_C \rho$, which is obtained by solving the Poisson equation
31+
```math
32+
-\Delta \left(v_C \rho\right) = 4\pi \rho
33+
```
34+
The non-linearity is such due to the fact that the DFT Hamiltonian
35+
```math
36+
H = -\frac12 \Delta + V\left(\rho\right)
37+
```
38+
depends on the density $\rho$, which is built from its own eigenfunctions.
39+
Often $H$ is also called the Kohn-Sham matrix or Fock matrix.
40+
41+
Introducing the *potential-to-density map*
42+
```math
43+
D(V) = \sum_{i=1}^N f(\varepsilon_i) \abs{\psi_i}^2
44+
\qquad \text{where} \qquad \left(-\frac12 \Delta + V\right) \psi_i = \varepsilon_i \psi_i
45+
```
46+
allows to write the DFT problem in the short-hand form
47+
```math
48+
\rho = D(V(\rho)),
49+
```
50+
which is a fixed-point problem in $\rho$, also known as the
51+
**self-consistent field problem** (SCF problem).
52+
Notice that computing $D(V)$ requires the diagonalisation of the operator
53+
$-\frac12 \Delta + V$, which is usually the most
54+
expensive step when solving the SCF problem.
55+
56+
To solve the above SCF problem $ \rho = D(V(\rho)) $
57+
one usually follows an iterative procedure.
58+
That is to say that starting from an initial guess $\rho_0$ one then
59+
computes $D(V(\rho_n))$ for a sequence of iterates $\rho_n$ until input and output
60+
are close enough. That is until the residual
61+
```math
62+
R(\rho_n) = D(V(\rho_n)) - \rho_n
63+
```
64+
is small. Details on such SCF algorithms will be discussed in [Self-consistent field methods](@ref).

0 commit comments

Comments
 (0)