Skip to content
Snippets Groups Projects
Commit 2ef5f643 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

use inline code execution

parent a9ea54e8
No related branches found
No related tags found
No related merge requests found
Showing
with 69 additions and 502 deletions
......@@ -24,11 +24,8 @@ build and upload the contents:
script:
# Compile lectures
- python code/band_structures.py
- python code/bands_2d.py
- python code/misc.py
- python code/semiconductors.py
- python code/heat_capacity.py
- python execute.py
- mkdocs build
- "rsync -rv site/* solidstate@tnw-tn1.tudelft.net:"
only:
......
import os
import numpy as np
import matplotlib
import mpl_toolkits
matplotlib.use('agg')
from matplotlib import pyplot
import common
from common import draw_classic_axes
pi = np.pi
def fermi_dirac():
fig = pyplot.figure()
ax = fig.add_subplot(1,1,1)
xvals = np.linspace(0, 2, 200)
mu = .75
beta = 20
ax.plot(xvals, xvals < mu, ls='dashed', label='$T=0$')
ax.plot(xvals, 1/(np.exp(beta * (xvals-mu)) + 1),
ls='solid', label='$T>0$')
ax.set_xlabel(r'$\varepsilon$')
ax.set_ylabel(r'$f(\varepsilon, T)$')
ax.set_yticks([0, 1])
ax.set_yticklabels(['$0$', '$1$'])
ax.set_xticks([mu])
ax.set_xticklabels([r'$\mu$'])
ax.set_ylim(-.1, 1.1)
ax.legend()
draw_classic_axes(ax)
pyplot.tight_layout()
fig.savefig('fermi_dirac.svg')
def phonons_1d():
k = np.linspace(-2*pi, 6*pi, 500)
fig, ax = pyplot.subplots()
pyplot.plot(k, np.abs(np.sin(k/2)))
ax.set_ylim(bottom=0, top=1.2)
ax.set_xlabel('$ka$')
ax.set_ylabel(r'$\omega$')
pyplot.xticks(list(2*pi*np.arange(-1, 4)) + [-pi, pi],
[r'$-2\pi$', '$0$', r'$2\pi$', r'$4\pi$', r'$6\pi$',
r'$-\pi$', r'$\pi$'])
pyplot.yticks([1], [r'$2\sqrt{\frac{\kappa}{m}}$'])
pyplot.vlines([-pi, pi], 0, 1.1, linestyles='dashed')
pyplot.hlines([1], .1*pi, 1.3*pi, linestyles='dashed')
draw_classic_axes(ax)
ax.annotate(s='', xy=(-pi, -.15), xytext=(pi, -.15),
arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
ax.text(0, -.25, '1st Brillouin zone', ha='center')
ax.set_ylim(bottom=-.7)
pyplot.savefig('phonons3.svg')
def aliasing():
x = np.linspace(-.2, 2.8, 500)
fig, ax = pyplot.subplots()
ax.plot(x, np.cos(pi*(x - .3)), label=r'$k=\pi/a$')
ax.plot(x, np.cos(3*pi*(x - .3)), label=r'$k=3\pi/a$')
ax.plot(x, np.cos(5*pi*(x - .3)), label=r'$k=5\pi/a$')
sites = np.arange(3) + .3
ax.scatter(sites, np.cos(pi*(sites - .3)), c='k', s=64, zorder=5)
ax.set_xlabel('$x$')
ax.set_ylabel('$u_n$')
ax.set_xlim((-.1, 3.2))
ax.set_ylim((-1.3, 1.3))
ax.legend(loc='lower right')
draw_classic_axes(ax)
ax.annotate(s='', xy=(.3, -1.1), xytext=(1.3, -1.1),
arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
ax.text(.3 + .5, -1.25, '$a$', ha='center')
pyplot.savefig('phonons4.svg')
def tight_binding_1d():
pyplot.figure()
k = np.linspace(-pi, pi, 300)
pyplot.plot(k, -np.cos(k))
pyplot.xlabel('$ka$'); pyplot.ylabel('$E$')
pyplot.xticks([-pi, 0, pi], [r'$-\pi$', 0, r'$\pi$'])
pyplot.yticks([-1, 0, 1], ['$E_0+2t$', '$E_0$', '$E_0-2t$'])
pyplot.savefig('tight_binding_1d.svg')
def meff_1d_tb():
pyplot.figure(figsize=(8, 5))
k = np.linspace(-pi, pi, 300)
meff = 1/np.cos(k)
color = list(matplotlib.rcParams['axes.prop_cycle'])[0]['color']
pyplot.plot(k[meff > 0], meff[meff > 0], c=color)
pyplot.plot(k[meff < 0], meff[meff < 0], c=color)
pyplot.ylim(-5, 5)
pyplot.xlabel('$ka$'); pyplot.ylabel('$m_{eff}$')
pyplot.xticks([-pi, 0, pi], [r'$-\pi$', 0, r'$\pi$']);
pyplot.savefig('meff_1d_tb.svg')
def dispersion_2m(k, kappa=1, M=1.4, m=1, acoustic=True):
Mm = M*m
m_harm = (M + m) / Mm
root = kappa * np.sqrt(m_harm**2 - 4*np.sin(k/2)**2 / Mm)
if acoustic:
root *= -1
return np.sqrt(kappa*m_harm + root)
def phonons_1d_2masses():
# TODO: Add panels with eigenvectors
k = np.linspace(-2*pi, 6*pi, 300)
fig, ax = pyplot.subplots()
ax.plot(k, dispersion_2m(k, acoustic=False), label='optical')
ax.plot(k, dispersion_2m(k), label='acoustic')
ax.set_xlabel('$ka$')
ax.set_ylabel(r'$\omega$')
pyplot.xticks([-pi, 0, pi], [r'$-\pi$', '$0$', r'$\pi$'])
pyplot.yticks([], [])
pyplot.vlines([-pi, pi], 0, 2.2, linestyles='dashed')
pyplot.legend()
pyplot.xlim(-1.75*pi, 3.5*pi)
pyplot.ylim(bottom=0)
draw_classic_axes(ax, xlabeloffset=.2)
pyplot.savefig('phonons6.svg')
def DOS_2masses():
matplotlib.rcParams['font.size'] = 24
k = np.linspace(-.25*pi, 1.5*pi, 300)
k_dos = np.linspace(0, pi, 20)
fig, (ax, ax2) = pyplot.subplots(ncols=2, sharey=True, figsize=(10, 5))
ax.plot(k, dispersion_2m(k, acoustic=False), label='optical')
ax.plot(k, dispersion_2m(k), label='acoustic')
ax.vlines(k_dos, 0, dispersion_2m(k_dos, acoustic=False),
colors=(0.5, 0.5, 0.5, 0.5))
ax.hlines(
np.hstack((dispersion_2m(k_dos, acoustic=False), dispersion_2m(k_dos))),
np.hstack((k_dos, k_dos)),
1.8*pi,
colors=(0.5, 0.5, 0.5, 0.5)
)
ax.set_xlabel('$ka$')
ax.set_ylabel(r'$\omega$')
ax.set_xticks([0, pi])
ax.set_xticklabels(['$0$', r'$\pi$'])
ax.set_yticks([], [])
ax.set_xlim(-pi/4, 2*pi)
ax.set_ylim((0, dispersion_2m(0, acoustic=False) + .2))
draw_classic_axes(ax, xlabeloffset=.2)
k = np.linspace(0, pi, 1000)
omegas = np.hstack((
dispersion_2m(k, acoustic=False), dispersion_2m(k)
))
ax2.hist(omegas, orientation='horizontal', bins=75)
ax2.set_xlabel(r'$g(\omega)$')
ax2.set_ylabel(r'$\omega$')
# Truncate the singularity in the DOS
max_x = ax2.get_xlim()[1]
ax2.set_xlim((0, max_x/2))
draw_classic_axes(ax2, xlabeloffset=.1)
matplotlib.rcParams['font.size'] = 16
pyplot.savefig('phonons8.svg')
def consistency_1_2_masses():
k = np.linspace(0, 2*pi, 300)
k_dos = np.linspace(0, pi, 20)
fig, ax = pyplot.subplots()
ax.plot(k, dispersion_2m(k, acoustic=False), label='optical')
ax.plot(k, dispersion_2m(k), label='acoustic')
omega_max = dispersion_2m(0, acoustic=False)
ax.plot(k, omega_max * np.sin(k/4), label='equal masses')
ax.set_xlabel('$ka$')
ax.set_ylabel(r'$\omega$')
ax.set_xticks([0, pi, 2*pi])
ax.set_xticklabels(['$0$', r'$\pi/2a$', r'$\pi/a$'])
ax.set_yticks([], [])
ax.set_xlim(-pi/8, 2*pi+.4)
ax.set_ylim((0, dispersion_2m(0, acoustic=False) + .2))
ax.legend(loc='lower right')
pyplot.vlines([pi, 2*pi], 0, 2.2, linestyles='dashed')
draw_classic_axes(ax, xlabeloffset=.2)
pyplot.savefig('phonons7.svg')
def DOS_finite_phonon_chain(n, output_name):
rhs = 2 * np.eye(n) - np.eye(n, k=1) - np.eye(n, k=-1)
rhs[0, 0] -= 1
rhs[-1, -1] -= 1
pyplot.figure()
pyplot.hist(np.sqrt(np.abs(np.linalg.eigvalsh(rhs))), bins=30)
pyplot.xlabel("$\omega$")
pyplot.ylabel("Number of levels")
pyplot.savefig(output_name)
def DOS_finite_electron_chain(n, output_name):
rhs = - np.eye(n, k=1) - np.eye(n, k=-1)
pyplot.figure()
pyplot.hist(np.linalg.eigvalsh(rhs), bins=30)
pyplot.xlabel("$E$")
pyplot.ylabel("Number of levels")
pyplot.savefig(output_name)
def main():
os.chdir('docs/figures')
fermi_dirac()
phonons_1d()
phonons_1d_2masses()
consistency_1_2_masses()
DOS_2masses()
aliasing()
meff_1d_tb()
tight_binding_1d()
DOS_finite_phonon_chain(3, '3_phonons.svg')
DOS_finite_phonon_chain(300, '300_phonons.svg')
DOS_finite_electron_chain(3, '3_electrons.svg')
DOS_finite_electron_chain(300, '300_electrons.svg')
if __name__ == "__main__":
main()
import os
import numpy as np
from IPython import get_ipython
import matplotlib
import mpl_toolkits
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['figure.figsize'] = (8, 5)
matplotlib.rcParams['font.size'] = 16
matplotlib.rcParams['savefig.transparent'] = True
def configure_plotting():
# Configure matplotlib
ip = get_ipython()
ip.config['InlineBackend']['figure_format'] = 'svg'
# Fix for https://stackoverflow.com/a/36021869/2217463
ip.config['InlineBackend']['rc'] = {}
ip.enable_matplotlib(gui='inline')
matplotlib.rcParams['text.usetex'] = False
matplotlib.rcParams['figure.figsize'] = (10, 7)
matplotlib.rcParams['font.size'] = 16
def draw_classic_axes(ax, x=0, y=0, xlabeloffset=.1, ylabeloffset=.07):
ax.set_axis_off()
x0, x1 = ax.get_xlim()
y0, y1 = ax.get_ylim()
ax.annotate(ax.get_xlabel(), xytext=(x1, y), xy=(x0, y),
arrowprops=dict(arrowstyle="<-"), va='center')
ax.annotate(ax.get_ylabel(), xytext=(x, y1), xy=(x, y0),
arrowprops=dict(arrowstyle="<-"), ha='center')
ax.annotate(
ax.get_xlabel(), xytext=(x1, y), xy=(x0, y),
arrowprops=dict(arrowstyle="<-"), va='center'
)
ax.annotate(
ax.get_ylabel(), xytext=(x, y1), xy=(x, y0),
arrowprops=dict(arrowstyle="<-"), ha='center'
)
for pos, label in zip(ax.get_xticks(), ax.get_xticklabels()):
ax.text(pos, y - xlabeloffset, label.get_text(),
ha='center', va='bottom')
......
import os
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot
import numpy as np
from scipy.optimize import curve_fit
from scipy.integrate import quad
import common
from common import draw_classic_axes
# Data from Einstein's paper
T = [222.4, 262.4, 283.7, 306.4, 331.3, 358.5, 413.0, 479.2, 520.0, 879.7, 1079.7, 1258.0],
c = [0.384, 0.578, 0.683, 0.798, 0.928, 1.069, 1.343, 1.656, 1.833, 2.671, 2.720, 2.781]
def plot_n_e():
fig, (ax, ax2) = pyplot.subplots(ncols=2, figsize=(10, 5))
omega = np.linspace(0.1, 2)
ax.plot(omega, 1/(np.exp(omega) - 1))
ax.set_ylim(0, top=3)
ax.set_xlim(left=0)
ax.set_xlabel(r'$\hbar \omega$')
ax.set_xticks([0, 1])
ax.set_xticklabels(['$0$', '$k_B T$'])
ax.set_ylabel('$n$')
ax.set_yticks([1, 2])
ax.set_yticklabels(['$1$', '$2$'])
draw_classic_axes(ax, xlabeloffset=.2)
T = np.linspace(0.01, 2)
ax2.plot(T, 1/2 + 1/(np.exp(1/T)-1))
ax2.set_ylim(bottom=0)
ax2.set_xlabel('$k_B T$')
ax2.set_xticks([0, 1])
ax2.set_xticklabels(['$0$', r'$\hbar \omega$'])
ax2.set_ylabel(r"$\bar\varepsilon$")
ax2.set_yticks([1/2])
ax2.set_yticklabels([r'$\hbar\omega/2$'])
draw_classic_axes(ax2, xlabeloffset=.15)
fig.savefig('bose_einstein.svg')
def c_einstein(T, T_E=1):
x = T_E / T
return 3 * x**2 * np.exp(x) / (np.exp(x) - 1)**2
def integrand(y):
return y**4 * np.exp(y) / (np.exp(y) - 1)**2
@np.vectorize
def c_debye(T, T_D=1):
x = T / T_D
return 9 * x**3 * quad(integrand, 0, 1/x)[0]
def plot_einstein():
T = np.linspace(0.01, 1.5, 500)
fig, ax = pyplot.subplots()
ax.plot(T, c_einstein(T)/3)
ax.fill_between(T, c_einstein(T)/3, 1, alpha=0.5)
ax.set_ylim(bottom=0, top=1.2)
ax.set_xlabel('$T$')
ax.set_ylabel(r'$\omega$')
ax.set_xticks([1])
ax.set_xticklabels([r'$\hbar \omega/k_B$'])
ax.set_yticks([1])
ax.set_yticklabels(['$k_B$'])
pyplot.hlines([1], 0, 1.5, linestyles='dashed')
draw_classic_axes(ax)
pyplot.savefig('zeropoint.svg')
def plot_debye():
T = np.linspace(0.01, 1.5, 500)
fig, ax = pyplot.subplots()
ax.plot(T, c_einstein(T), label="Einstein model")
ax.plot(T, c_debye(T), label="Debye model")
ax.set_ylim(bottom=0, top=3.4)
ax.set_xlabel('$T$')
ax.set_ylabel(r'$\omega$')
ax.set_xticks([1])
ax.set_xticklabels([r'$\Theta_D$'])
ax.set_yticks([3])
ax.set_yticklabels(['$3Nk_B$'])
ax.legend(loc='lower right')
pyplot.hlines([3], 0, 1.5, linestyles='dashed')
draw_classic_axes(ax, xlabeloffset=0.3)
pyplot.savefig('debye.svg')
def main():
os.chdir('docs/figures')
plot_n_e()
plot_einstein()
plot_debye()
if __name__ == "__main__":
main()
import os
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot
import numpy as np
from scipy.optimize import curve_fit
from scipy.integrate import quad
import common
from common import draw_classic_axes
def plot_curie():
B = np.linspace(-2, 2, 1000)
fig, ax = pyplot.subplots()
sqrt_plus = lambda x: np.sqrt(x * (x >= 0))
ax.plot(B, np.tanh(B * 3), label="low $T$")
ax.plot(B, np.tanh(B), label="high $T$")
ax.legend()
ax.set_ylabel("$M$")
ax.set_xlabel("$B$")
draw_classic_axes(ax, xlabeloffset=.2)
fig.savefig('curie.svg')
def plot_free_electron_DOS():
E = np.linspace(0, 2, 500)
fig, ax = pyplot.subplots()
ax.plot(E, np.sqrt(E))
ax.set_ylabel(r"$g(\varepsilon)$")
ax.set_xlabel(r"$\varepsilon$")
draw_classic_axes(ax, xlabeloffset=.2)
fig.savefig('sqrt.svg')
def plot_finite_T_FEM():
E = np.linspace(0, 2, 500)
fig, ax = pyplot.subplots()
ax.plot(E, np.sqrt(E), linestyle='dashed')
ax.text(1.7, 1.4, r'$g(\varepsilon)\propto \sqrt{\varepsilon}$', ha='center')
ax.fill_between(E, np.sqrt(E) * (E < 1), alpha=.3)
n = np.sqrt(E) / (1 + np.exp(20*(E-1)))
ax.plot(E, n)
ax.fill_between(E, n, alpha=.5)
w = .17
ax.annotate(s='', xy=(1, 1), xytext=(1-w, 1),
arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
ax.text(1-w/2, 1.1, r'$\sim k_BT$', ha='center')
ax.plot([1-w, 1+w], [1, 0], c='k', linestyle='dashed')
ax.annotate(s='', xy=(1, 0), xytext=(1, 1),
arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
ax.text(1.2, .7, r'$g(\varepsilon_F)$', ha='center')
ax.set_xticks([1])
ax.set_xticklabels([r'$\varepsilon_F$'])
ax.set_ylabel(r"$g(\varepsilon)$")
ax.set_xlabel(r"$\varepsilon$")
draw_classic_axes(ax, xlabeloffset=.2)
fig.savefig('FD_DOS.svg')
def main():
os.chdir('docs/figures')
plot_curie()
plot_free_electron_DOS()
plot_finite_T_FEM()
if __name__ == "__main__":
main()
import os
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot
import numpy as np
from scipy.optimize import curve_fit
from scipy.integrate import quad
import common
from common import draw_classic_axes
E_V, E_C, E_F = -1.2, 1.8, .4
E_D, E_A = E_C - .7, E_V + .5
m_h, m_e = 1, .5
sqrt_plus = lambda x: np.sqrt(x * (x >= 0))
def plot_dos():
E = np.linspace(-3, 3, 1000)
fig, ax = pyplot.subplots()
n_F = 1/(np.exp(2*(E - E_F)) + 1)
g_e = m_e * sqrt_plus(E - E_C)
g_h = m_h * sqrt_plus(E_V - E)
ax.plot(E, g_h, label="$g_e$")
ax.plot(E, g_e, label="$g_h$")
ax.plot(E, 10 * g_h * (1-n_F), label="$n_h$")
ax.plot(E, 10 * g_e * n_F, label="$n_e$")
ax.plot(E, n_F, label="$n_F$", linestyle='dashed')
ax.set_ylim(top=1.5)
ax.set_xlabel('$E$')
ax.set_ylabel('$g$')
ax.set_xticks([E_V, E_C, E_F])
ax.set_xticklabels(['$E_V$', '$E_C$', '$E_F$'])
ax.legend()
draw_classic_axes(ax, xlabeloffset=.2)
fig.savefig('intrinsic_DOS.svg')
def plot_doping():
E = np.linspace(-3, 3, 1000)
fig, ax = pyplot.subplots()
n_F = 1/(np.exp(2*(E - E_F)) + 1)
g_e = m_e * sqrt_plus(E - E_C)
g_h = m_h * sqrt_plus(E_V - E)
ax.plot(E, g_h, label="$g_e$")
ax.plot(E, g_e, label="$g_h$")
sigma = 0.01
g_D = np.exp(-(E_D - E)**2 / sigma**2)
g_A = .7 * np.exp(-(E_A - E)**2 / sigma**2)
ax.plot(E, g_D, label='$g_D$')
ax.plot(E, g_A, label='$g_A$')
ax.legend()
ax.set_xticks([E_V, E_C, E_A, E_D])
ax.set_xticklabels(['$E_V$', '$E_C$', '$E_A$', '$E_D$'])
draw_classic_axes(ax, xlabeloffset=.2)
fig.savefig('doping.svg')
def main():
os.chdir('docs/figures')
plot_dos()
plot_doping()
if __name__ == "__main__":
main()
MathJax.Hub.Config({
config: ["MMLorHTML.js"],
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
extensions: ["MathMenu.js", "MathZoom.js"]
});
from pathlib import Path
import shutil
import nbconvert
import notedown
from traitlets.config import Config
reader = notedown.MarkdownReader()
src = Path('src')
target = Path('docs')
shutil.rmtree(target, ignore_errors=True)
target.mkdir(exist_ok=True)
shutil.copytree(src / 'figures', target / 'figures')
exporter = nbconvert.MarkdownExporter(
config=Config(dict(
MarkdownExporter=dict(
preprocessors=[
nbconvert.preprocessors.ExecutePreprocessor,
nbconvert.preprocessors.ExtractOutputPreprocessor,
],
exclude_input=True
)
))
)
writer = nbconvert.writers.FilesWriter(build_directory=str(target))
for source_file in src.glob('*.md'):
fname = source_file.name[:-len('.md')]
notebook = reader.reads(source_file.read_text())
output, resources = exporter.from_notebook_node(
notebook,
resources={
'unique_key': fname,
'output_files_dir': 'figures',
'metadata': {'path': str(Path('.') / 'code')}
}
)
writer.write(output, resources, fname)
......@@ -13,7 +13,8 @@ pages:
- Crystal structure and diffraction: 'lecture_5.md'
- Tight binding and nearly free electrons: 'lecture_6.md'
- Semiconductors: 'lecture_7.md'
- Magnetism: 'lecture_8.md'
- Attic:
- Magnetism: 'lecture_8.md'
theme:
name: material
......@@ -22,7 +23,6 @@ theme:
primary: 'white'
accent: 'indigo'
markdown_extensions:
- mdx_math:
enable_dollar_delimiter: True
......@@ -33,6 +33,5 @@ markdown_extensions:
extra_javascript:
- 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-AMS_HTML'
- 'mathjaxhelper.js'
copyright: "Copyright © 2017-2018 Delft University of Technology, CC-BY-SA-NC 4.0."
File moved
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment