From 42497c41bd16953672bd302dbbcf51a4e4bb78d5 Mon Sep 17 00:00:00 2001
From: Anton Akhmerov <anton.akhmerov@gmail.com>
Date: Fri, 30 Mar 2018 15:25:11 +0200
Subject: [PATCH] add 2d tight-binding

---
 .gitlab-ci.yml   |   2 +-
 code/bands_2d.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++
 code/nfem.py     |  78 -----------------------------
 lecture_6.md     |   9 +++-
 4 files changed, 132 insertions(+), 81 deletions(-)
 create mode 100644 code/bands_2d.py
 delete mode 100644 code/nfem.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4d970c55..c8edeff9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -25,7 +25,7 @@ build and upload the contents:
   script:
     # Compile lectures
     - python code/band_structures.py
-    - python code/nfem.py
+    - python code/bands_2d.py
     - gitbook install
     - gitbook build
     - "rsync -rv _book/* solidstate@tnw-tn1.tudelft.net:"
diff --git a/code/bands_2d.py b/code/bands_2d.py
new file mode 100644
index 00000000..10dc64dd
--- /dev/null
+++ b/code/bands_2d.py
@@ -0,0 +1,124 @@
+import numpy as np
+import plotly.offline as py
+import plotly.graph_objs as go
+
+
+pi = np.pi
+
+def E(k_x, k_y):
+    delta = np.array([-2*pi, 0, 2*pi])
+    H = np.diag(
+        ((k_x + delta)[:, np.newaxis]**2
+        + (k_y + delta)[np.newaxis]**2).flatten()
+    )
+    return tuple(np.linalg.eigvalsh(H + 5)[:3])
+
+E = np.vectorize(E, otypes=(float, float, float))
+
+
+figure_html = """
+<head>
+<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
+</head>
+<body>{figure}
+</body>
+""".format
+
+
+def plot_nfem():
+    momenta = np.linspace(-2*pi, 2*pi, 100)
+    kx, ky = momenta[:, np.newaxis], momenta[np.newaxis, :]
+    bands = E(kx, ky)
+
+    # Extended Brillouin zone scheme
+    pad = .3
+    first_BZ = ((abs(kx) < pi + pad) & (abs(ky) < pi + pad))
+    second_BZ = (
+        ((abs(kx) > pi - pad) | (abs(ky) > pi - pad))
+        & ((abs(kx + ky) < 2*pi + pad) & (abs(kx - ky) < 2*pi + pad))
+    )
+    third_BZ = (
+        (abs(kx + ky) > 2*pi - pad) | (abs(kx - ky) > 2*pi - pad)
+    )
+
+    bands[0][~first_BZ] = np.nan
+    bands[1][~second_BZ] = np.nan
+    #bands[2][~third_BZ] = np.nan
+
+    # Actually plotting
+
+    fig = go.Figure(
+        data = [
+            go.Surface(
+                z=band / 5,
+                colorscale=color,
+                opacity=opacity,
+                showscale=False,
+                hoverinfo=False,
+                x=momenta,
+                y=momenta,
+            )
+            for band, color, opacity 
+            in zip(bands[:2], 
+                   ['#cf483d', '#3d88cf'], 
+                   (1, 0.9))
+        ],
+        layout = go.Layout(
+            title='Nearly free electrons in 2D',
+            autosize=True,
+            width=500,
+            height=500,
+            hovermode=False,
+            scene=dict(
+                yaxis={"title": "k_y"},
+                xaxis={"title": "k_x"},
+                zaxis={"title": "E"},
+            )
+        )
+    )
+    with open('figures/nfem_2d.html', 'w') as f:
+        f.write(figure_html(figure=
+            py.plot(fig, show_link=False, 
+                    output_type='div', include_plotlyjs=False)
+        ))
+
+
+def plot_tb():
+    momenta = np.linspace(-pi, pi, 100)
+    kx, ky = momenta[:, np.newaxis], momenta[np.newaxis, :]
+    energies = -np.cos(kx) - np.cos(ky)
+    fig = go.Figure(
+        data = [
+            go.Surface(
+                z=energies,
+                colorscale='#3d88cf',
+                opacity=1,
+                showscale=False,
+                hoverinfo=False,
+                x=momenta,
+                y=momenta,
+            )
+        ],
+        layout = go.Layout(
+            title='Tight-binding in 2D',
+            autosize=True,
+            width=500,
+            height=500,
+            hovermode=False,
+            scene=dict(
+                yaxis={"title": "k_y"},
+                xaxis={"title": "k_x"},
+                zaxis={"title": "E"},
+            )
+        )
+    )
+    with open('figures/tb_2d.html', 'w') as f:
+        f.write(figure_html(figure=
+            py.plot(fig, show_link=False, 
+                    output_type='div', include_plotlyjs=False)
+        ))
+    
+
+if __name__ == '__main__':
+    plot_nfem()
+    plot_tb()
diff --git a/code/nfem.py b/code/nfem.py
deleted file mode 100644
index ef406847..00000000
--- a/code/nfem.py
+++ /dev/null
@@ -1,78 +0,0 @@
-import numpy as np
-import plotly.offline as py
-import plotly.graph_objs as go
-
-
-pi = np.pi
-
-def E(k_x, k_y):
-    delta = np.array([-2*pi, 0, 2*pi])
-    H = np.diag(
-        ((k_x + delta)[:, np.newaxis]**2
-        + (k_y + delta)[np.newaxis]**2).flatten()
-    )
-    return tuple(np.linalg.eigvalsh(H + 5)[:3])
-
-E = np.vectorize(E, otypes=(float, float, float))
-
-momenta = np.linspace(-2*pi, 2*pi, 100)
-kx, ky = momenta[:, np.newaxis], momenta[np.newaxis, :]
-
-bands = E(kx, ky)
-
-# Extended Brillouin zone scheme
-pad = .3
-first_BZ = ((abs(kx) < pi + pad) & (abs(ky) < pi + pad))
-second_BZ = (
-    ((abs(kx) > pi - pad) | (abs(ky) > pi - pad))
-    & ((abs(kx + ky) < 2*pi + pad) & (abs(kx - ky) < 2*pi + pad))
-)
-third_BZ = (
-    (abs(kx + ky) > 2*pi - pad) | (abs(kx - ky) > 2*pi - pad)
-)
-
-bands[0][~first_BZ] = np.nan
-bands[1][~second_BZ] = np.nan
-#bands[2][~third_BZ] = np.nan
-
-# Actually plotting
-
-fig = go.Figure(
-    data = [
-        go.Surface(
-            z=band / 5,
-            colorscale=color,
-            opacity=opacity,
-            showscale=False,
-            hoverinfo=False,
-            x=momenta,
-            y=momenta,
-        )
-        for band, color, opacity 
-        in zip(bands[:2], 
-               ['#cf483d', '#3d88cf'], 
-               (1, 0.9))
-    ],
-    layout = go.Layout(
-        title='Nearly free electrons in 2D',
-        autosize=True,
-        width=500,
-        height=500,
-        hovermode=False,
-        scene=dict(
-            yaxis={"title": "k_y"},
-            xaxis={"title": "k_x"},
-            zaxis={"title": "E"},
-        )
-    )
-)
-
-out = rf"""
-<head>
-<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
-</head>
-<body>{py.plot(fig, show_link=False, output_type='div', include_plotlyjs=False)}
-</body>
-"""
-with open('figures/nfem_2d.html', 'w') as f:
-    f.write(out)
\ No newline at end of file
diff --git a/lecture_6.md b/lecture_6.md
index 2f249468..b7c5d25e 100644
--- a/lecture_6.md
+++ b/lecture_6.md
@@ -82,7 +82,7 @@ Here the coupling strength $W = \langle \psi_+ | V(x) | \psi_- \rangle$ is the m
 We need to diagonalize a 2x2 matrix Hamiltonian. The answer is
 $$ E(\delta k) = E_0 \pm \sqrt{v^2\hbar^2\delta k^2 + |W|^2}$$
 
-In one of the exercises you will encounter the details of this calculation.
+Check out section 15.1.1 of the book for the details of this calculation.
 
 #### Physical meaning of $W$
 
@@ -176,7 +176,12 @@ The resulting band structure looks like this (in the extended Brillouin zone sch
 
 Observe that the top of the first band is above the bottom of the lowest band. Therefore if $V$ is sufficiently weak, the material can be conducting even with 2 electrons per unit cell!
 
-A larger $V$ makes the Fermi surface more square-like and eventually makes the material insulating.
+A larger $V$ makes the Fermi surface more distorted and eventually makes the material insulating.
+Let's compare the almost parabolic dispersion of the nearly free electron model with a tight-binding model in 2D.
+
+We now have a dispersion relation $E = E_0 + 2t(\cos k_x a + \cos k_y a)$, which looks like this:
+
+<iframe width="600", height="600" src="figures/tb_2d.html" frameBorder="0" align="center" style="border:0;">Your browser still doesn't support iframes??</iframe>
 
 ### Light adsorption
 
-- 
GitLab