---
title: "Solid-state lab: phonons and bands by computer"
heading: Dynamical matrices, plane waves and tight binding
eyebrow: "B12 · Lesson 51 · Solid-state lab"
xp: 60
---

::: hook
Every band structure and phonon dispersion in this course came from a small matrix whose eigenvalues, computed for each wavevector, trace out the curves. In this lab you'll build those matrices yourself. A two-atom chain's **dynamical matrix** gives its acoustic and optical phonons. A **plane-wave** Hamiltonian, the free-electron basis plus a periodic potential, gives the nearly-free-electron bands with their gaps to any accuracy you want. And graphene's two-site **tight-binding** matrix gives its Dirac cones and Fermi velocity. Each is a few lines of NumPy, checked against the closed forms of lessons 8, 12 and 13.
:::

::: predict
## A plane-wave calculation for a 1D crystal uses 21 reciprocal lattice vectors. How big is the matrix to diagonalize at each k?

- [ ] 2 × 2
- [x] 21 × 21
- [ ] 441 × 441
- [ ] Infinite

::: reveal
One row and column per plane wave $e^{i(k + G)x}$, so 21 × 21. The diagonal holds the free energies $\frac{\hbar^2(k + G)^2}{2m}$ and the off-diagonal entries the potential's Fourier components $U_{G - G'}$. Its lowest few eigenvalues converge quickly with the number of plane waves when the potential is smooth: 21 is plenty for a cosine.
:::
:::

::: nameit
## What you'll write

1. `diatomic(K, m1, m2, q)`: for an array q of wavevectors (q = ka/π), return the acoustic and optical frequencies in THz from the eigenvalues of the dynamical matrix
$$D = \begin{pmatrix}2K/M_1 & -\frac{K(1 + e^{-iq\pi})}{\sqrt{M_1M_2}}\\ -\frac{K(1 + e^{iq\pi})}{\sqrt{M_1M_2}} & 2K/M_2\end{pmatrix}$$
(masses in u, converted to kg; ω = √eigenvalue; f = ω/2π). Use `np.linalg.eigvalsh`, which sorts ascending.
2. `pw_bands(V0, a, k, nb=3, nG=21)`: the lowest nb energies (eV) at wavevector k (nm⁻¹) for $V(x) = -V_0\cos(2\pi x/a)$, using nG plane waves with $G = \frac{2\pi}{a}m$, m = −10…10. Diagonal: $c(k + G)^2$ with c = 0.0381 eV·nm²; neighbors in G coupled by $-V_0/2$.
3. `graphene(kx, ky, t=2.8, D=0.0)`: the two energies at $(k_x, k_y)$ (nm⁻¹) from $\begin{pmatrix}D & -tf\\ -tf^* & -D\end{pmatrix}$, $f = \sum_je^{i\mathbf k\cdot\boldsymbol\delta_j}$ over the neighbor vectors $(a, 0)$, $(-\frac a2, \frac{\sqrt3}{2}a)$, $(-\frac a2, -\frac{\sqrt3}{2}a)$ with a = 0.142 nm.

## Checks

- Chain: optical $\sqrt{2K(1/M_1 + 1/M_2)}$ at q = 0; $\sqrt{2K/M}$ at the zone edge.
- Plane waves: V₀ = 0 gives the free energies $c(k + G)^2$; the first gap at the zone edge is V₀ for a weak cosine.
- Graphene: zero energy at the K point $\left(\frac{2\pi}{3a}, \frac{2\pi}{3\sqrt3a}\right)$, slope $\frac{3ta}{2\hbar}$, gap 2D.
:::

::: example
## Why does a cosine potential open a first gap of exactly V₀?

::: solution
1. **Fourier component.** Write the cosine as two exponentials:
   $$-V_0\cos(2\pi x/a) = -\frac{V_0}{2}e^{iGx} - \frac{V_0}{2}e^{-iGx}$$
   so $U_G = -V_0/2$.
2. **The gap.** Lesson 15's two-wave result gives a gap of $2\lvert U_G\rvert$ = V₀.
3. **The other waves.** The plane-wave calculation includes every other wave too, which shifts the gap only at second order: for V₀ = 0.2 eV in a 0.5 nm lattice, by less than 0.01%.

**Answer:** the cosine's Fourier component is $U_G = -V_0/2$, so the two-wave gap $2\lvert U_G\rvert$ is exactly V₀, and the other waves change it by less than 0.01%.
:::
:::

::: example
## How do you find graphene's Fermi velocity numerically?

::: solution
1. **Finite difference.** Evaluate the upper band a small distance q from the K point and divide:
   $$v_F = \frac{E(K + q) - E(K)}{\hbar q}$$
2. **Choose the step.** With q = 10⁻³ nm⁻¹ the cone is straight to six digits and the result is 9.06 × 10⁵ m/s.
3. **Check.** That matches $\frac{3ta}{2\hbar}$ for t = 2.8 eV.
4. **In real codes.** A finite difference on the computed band is how real band-structure codes report effective masses and velocities too.

**Answer:** divide the band's rise just off the K point by ħq, which gives $9.06 \times 10^5$ m/s.
:::
:::

::: check
kind: python

## Step 1. Write `diatomic(K, m1, m2, q)` returning (acoustic, optical) in THz.

```python starter
import numpy as np
u = 1.66053906660e-27

def diatomic(K, m1, m2, q):
    q = np.atleast_1d(np.asarray(q, float))
    M1, M2 = m1 * u, m2 * u
    # for each q, build the 2x2 dynamical matrix and take eigvalsh
    return np.zeros(len(q)), np.zeros(len(q))

print(diatomic(91, 69.72, 74.92, [0, 0.5, 1]))
```

```python solution
import numpy as np
u = 1.66053906660e-27

def diatomic(K, m1, m2, q):
    q = np.atleast_1d(np.asarray(q, float))
    M1, M2 = m1 * u, m2 * u
    out = []
    for qi in q:
        ph = np.exp(-1j * np.pi * qi)
        D = np.array([[2 * K / M1, -K * (1 + ph) / np.sqrt(M1 * M2)],
                      [-K * (1 + np.conj(ph)) / np.sqrt(M1 * M2), 2 * K / M2]])
        w2 = np.linalg.eigvalsh(D)
        out.append(np.sqrt(np.clip(w2, 0, None)) / (2 * np.pi) / 1e12)
    out = np.array(out)
    return out[:, 0], out[:, 1]

print(diatomic(91, 69.72, 74.92, [0, 0.5, 1]))
```

```python tests
import numpy as np
for K, m1, m2 in ((91, 69.72, 74.92), (50, 12, 40)):
    ac, op = diatomic(K, m1, m2, [0, 1])
    M1, M2 = m1 * u, m2 * u
    want0 = np.sqrt(2 * K * (1 / M1 + 1 / M2)) / (2 * np.pi) / 1e12
    assert abs(ac[0]) < 1e-6, "The acoustic branch starts at zero frequency."
    assert abs(op[0] / want0 - 1) < 1e-9, f"Optical at q = 0 should be {want0:.4f} THz; got {op[0]:.4f}."
    lo, hi = sorted([np.sqrt(2 * K / M1), np.sqrt(2 * K / M2)])
    assert abs(ac[1] / (lo / (2 * np.pi) / 1e12) - 1) < 1e-9 and abs(op[1] / (hi / (2 * np.pi) / 1e12) - 1) < 1e-9, "At the zone edge the branches are sqrt(2K/M) for each mass."
```

::: right
Right. A 2×2 eigenvalue problem per wavevector reproduces both branches exactly, and the same code handles any masses and springs.
:::
:::

::: check
kind: python

## Step 2. Write `pw_bands(V0, a, k, nb=3, nG=21)`.

```python starter
import numpy as np
C = 0.0381

def pw_bands(V0, a, k, nb=3, nG=21):
    G = 2 * np.pi / a * np.arange(-(nG // 2), nG // 2 + 1)
    H = np.diag(C * (k + G) ** 2)
    # couple neighboring plane waves by -V0/2, then eigvalsh
    return np.zeros(nb)

print(pw_bands(0.2, 0.5, np.pi / 0.5))
```

```python solution
import numpy as np
C = 0.0381

def pw_bands(V0, a, k, nb=3, nG=21):
    G = 2 * np.pi / a * np.arange(-(nG // 2), nG // 2 + 1)
    H = np.diag(C * (k + G) ** 2)
    for i in range(nG - 1):
        H[i, i + 1] = H[i + 1, i] = -V0 / 2
    return np.linalg.eigvalsh(H)[:nb]

print(pw_bands(0.2, 0.5, np.pi / 0.5))
```

```python tests
import numpy as np
k = 0.3 * np.pi / 0.5
free = sorted(C * (k + 2 * np.pi / 0.5 * n) ** 2 for n in range(-3, 4))[:3]
got = pw_bands(0, 0.5, k)
assert np.allclose(got, free, atol=1e-12), f"With V0 = 0 the bands are the folded free-electron energies {np.round(free, 6)}; got {np.round(got, 6)}."
for V0 in (0.05, 0.2):
    e = pw_bands(V0, 0.5, np.pi / 0.5)
    assert abs((e[1] - e[0]) / V0 - 1) < 1e-3, f"A weak cosine of strength {V0} eV opens a first gap of about {V0} eV; got {e[1] - e[0]:.5f}."
e21 = pw_bands(0.2, 0.5, 1.0)
e41 = pw_bands(0.2, 0.5, 1.0, 3, 41)
assert np.allclose(e21, e41, atol=1e-9), "21 plane waves should already be converged for a cosine potential."
```

::: right
Right. The plane-wave method gives the nearly-free-electron gap of lesson 15 and converges with a modest basis; real band-structure codes are the same idea in three dimensions with pseudopotentials.
:::
:::

::: check
kind: python

## Step 3. Write `graphene(kx, ky, t=2.8, D=0.0)`.

```python starter
import numpy as np
acc = 0.142

def graphene(kx, ky, t=2.8, D=0.0):
    d = np.array([[acc, 0], [-acc / 2, acc * np.sqrt(3) / 2], [-acc / 2, -acc * np.sqrt(3) / 2]])
    # f = sum over neighbors of exp(i k . delta); 2x2 Hamiltonian; eigvalsh
    return np.zeros(2)

K = (2 * np.pi / (3 * acc), 2 * np.pi / (3 * np.sqrt(3) * acc))
print(graphene(*K))
```

```python solution
import numpy as np
acc = 0.142

def graphene(kx, ky, t=2.8, D=0.0):
    d = np.array([[acc, 0], [-acc / 2, acc * np.sqrt(3) / 2], [-acc / 2, -acc * np.sqrt(3) / 2]])
    f = sum(np.exp(1j * (kx * dx + ky * dy)) for dx, dy in d)
    H = np.array([[D, -t * f], [-t * np.conj(f), -D]])
    return np.linalg.eigvalsh(H)

K = (2 * np.pi / (3 * acc), 2 * np.pi / (3 * np.sqrt(3) * acc))
print(graphene(*K))
```

```python tests
import numpy as np
K = (2 * np.pi / (3 * acc), 2 * np.pi / (3 * np.sqrt(3) * acc))
e = graphene(*K)
assert np.max(np.abs(e)) < 1e-9, f"At the K point both bands meet at zero; got {e}."
G0 = graphene(0, 0)
assert abs(G0[1] - 3 * 2.8) < 1e-9, "At Γ the upper band is at 3t = 8.4 eV."
q = 1e-3
vF = graphene(K[0] + q, K[1])[1] / q * 1e-9 / 6.582119569e-16
want = 3 * 2.8 * acc * 1e-9 / (2 * 6.582119569e-16)
assert abs(vF / want - 1) < 1e-4, f"The Fermi velocity should be 3ta/2ħ = {want:.4g} m/s; got {vF:.4g}."
eD = graphene(*K, D=0.5)
assert abs(eD[1] - eD[0] - 1.0) < 1e-9, "A sublattice energy of ±0.5 eV opens a 1.0 eV gap at K."
```

::: right
Right. Two lines of physics, the neighbor vectors and a 2×2 matrix, give graphene's Dirac cones, its 0.9 × 10⁶ m/s Fermi velocity and the gap that hBN-like asymmetry opens.
:::
:::

::: check
given: n = 11 | 21 | 41
answer: n^2
tolerance: 0

## How many matrix elements does a {n}-plane-wave Hamiltonian have?

::: right
Right. {n} × {n} = {answer}.
:::

::: misses
- [n] That's the number of rows.
- [any] Not yet. Square the basis size.
:::
:::

::: check
given: V = 0.05 | 0.2 | 0.8
answer: V
unit: eV
tolerance: 0.5%

## A crystal's potential is $-V_0\cos(2\pi x/a)$ with V₀ = {V} eV. To first order, how wide is its first gap?

::: right
Right. $2\lvert U_G\rvert$ with $U_G = -V_0/2$: {answer} eV.
:::

::: misses
- [2*V] The Fourier component is V₀/2, so the gap is V₀.
- [V/2] That's $\lvert U_G\rvert$; the gap is twice it.
:::
:::

::: check
given: t = 2.5 | 2.8 | 3
answer: 3*t
unit: eV
tolerance: 0.1%

## In nearest-neighbor tight binding for graphene with t = {t} eV, how high is the upper band at Γ?

::: right
Right. At Γ, f = 3, so E = 3t = {answer} eV.
:::

::: misses
- [t] All three neighbors add in phase at k = 0: f = 3.
- [any] Not yet. Evaluate f at k = 0.
:::
:::

::: explain
## Why does every band structure in this course reduce to finding eigenvalues of a small matrix at each wavevector?

::: model
Bloch's theorem says the crystal's eigenstates can be labeled by a wavevector k, and states with different k don't mix because the crystal's translation symmetry keeps them separate. So instead of one enormous problem for the whole crystal, there's one small problem for each k, involving only the few basis functions that share that k: the two atoms of a cell in a dynamical matrix, the two sublattices in graphene, or the set of plane waves k + G in the plane-wave method. Diagonalizing that small matrix gives every band at that k, and sweeping k across the Brillouin zone traces the full band structure.
:::
:::

::: practice

::: check
given: n = 5 | 15 | 21 | 41 | 81 | 101
answer: n^2
tolerance: 0

## Matrix elements for {n} plane waves?

::: misses
- [any] $n^2$.
:::
:::

::: check
given: V = 0.1 | 0.3 | 0.5 | 1 | 1.5 | 2
answer: V
unit: eV
tolerance: 0.5%

## First gap for $-V_0\cos(2\pi x/a)$, V₀ = {V} eV?

::: misses
- [any] V₀.
:::
:::

::: check
given: t = 2.5 | 2.6 | 2.7 | 2.8 | 2.9 | 3.1
answer: 3*t
unit: eV
tolerance: 0.1%

## Graphene's upper band at Γ for t = {t} eV?

::: misses
- [any] 3t.
:::
:::
:::
