Skip to content

Commit

Permalink
Made default selected k-point in 2d phonon notebook more illuminating…
Browse files Browse the repository at this point in the history
…, added arrows by default, added background theory sections to all notebooks, fixed links.
  • Loading branch information
Taylor-96 committed May 14, 2024
1 parent dbb464f commit 247dc43
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 58 deletions.
4 changes: 2 additions & 2 deletions notebook/lattice-vibration/Molecule_Vibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"<i class=\"fa fa-home fa-2x\"></i><a href=\"../index.ipynb\" style=\"font-size: 20px\"> Go back to index</a>\n",
"\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/blob/develop/notebook/lattice-vibration/Molecule_Vibration.ipynb\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/blob/master/notebook/lattice-vibration/Molecule_Vibration.ipynb\n",
"\n",
"\n",
"With this notebook, the concept of molecular vibration is explored and visualized in an interactive fashion.\n",
Expand Down Expand Up @@ -338,7 +338,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
41 changes: 34 additions & 7 deletions notebook/lattice-vibration/NGLTrajectoryClass2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,16 @@ def __init__(self, trajectory):
self.kx_array = np.linspace(-1.5 * np.pi, 1.5 * np.pi, 61)
self.ky_array = np.linspace(-1.5 * np.pi, 1.5 * np.pi, 61)
self.KX, self.KY = np.meshgrid(self.kx_array, self.ky_array)
# Center of Brillouin zone
self.idx_x = 30
self.idx_y = 30

# Initialize to nontrivial k-point
self.x=np.pi/2
self.y=np.pi/2
self.idx_x = (np.abs(self.kx_array - self.x)).argmin()
self.idx_y = (np.abs(self.ky_array - self.y)).argmin()

kx = self.kx_array[self.idx_x]
ky = self.ky_array[self.idx_y]


# kx,ky bounds are 1.5*BZ edge
self.kx_array_honey = np.linspace(-1.5 * 2 * np.pi / 3, 1.5 * 2 * np.pi / 3, 61)
Expand All @@ -176,8 +182,8 @@ def __init__(self, trajectory):
self.KX_honey, self.KY_honey = np.meshgrid(
self.kx_array_honey, self.ky_array_honey
)
self.idx_x_honey = 30
self.idx_y_honey = 30
self.idx_x_honey = 50
self.idx_y_honey = 50

# View settings
self.init_delay = 20
Expand Down Expand Up @@ -498,7 +504,15 @@ def initialize_2D_band_plot(self):
self.ax.set_yticks(np.linspace(-np.pi, np.pi, 5))
self.ax.set_yticklabels(["$-\pi/a$", "", "0", "", "$\pi/a$"])

(self.point,) = self.ax.plot([0], [0], ".", c="crimson", markersize=10)

self.x=np.pi/2
self.y=np.pi/2
self.idx_x = (np.abs(self.kx_array - self.x)).argmin()
self.idx_y = (np.abs(self.ky_array - self.y)).argmin()

kx = self.kx_array[self.idx_x]
ky = self.ky_array[self.idx_y]
(self.point,) = self.ax.plot([kx], [ky], ".", c="crimson", markersize=10) # TODO CHANGE INITIAL MARKER POS

self.fig.canvas.mpl_connect("button_press_event", self.onclick)
plt.ion()
Expand Down Expand Up @@ -544,7 +558,20 @@ def initialize_paths_bands(self):
self.ax_.plot([20, 20], [0, 10000], "k--")
self.ax_.plot([40, 40], [0, 10000], "k--")

(self.point_,) = self.ax_.plot([], [], "r.", markersize=10)

self.x=np.pi/2
self.y=np.pi/2
self.idx_x = (np.abs(self.kx_array - self.x)).argmin()
self.idx_y = (np.abs(self.ky_array - self.y)).argmin()

kx = self.kx_array[self.idx_x]
ky = self.ky_array[self.idx_y]

# default chosen to be on gamma-M
idx = np.where(np.all([kx, ky] == np.c_[self.kx_GM, self.ky_GM], axis=1))[
0
][0]
(self.point_,) = self.ax_.plot([idx], [self.w_long[self.idx_x][self.idx_y]], "r.", markersize=10)

# Position of the high symmetry points
self.ax_.set_xticks([0, 20, 40, 60])
Expand Down
2 changes: 1 addition & 1 deletion notebook/lattice-vibration/NGLUtilsClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, trajectory) -> None:
r"Arrow amplitude", layout=self.layout_description
)
self.slider_amp_arrow = widgets.FloatSlider(
value=0.5,
value=2.0,
min=0.1,
max=5.01,
step=0.1,
Expand Down
82 changes: 70 additions & 12 deletions notebook/lattice-vibration/Phonon_2D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"<i class=\"fa fa-home fa-2x\"></i><a href=\"../index.ipynb\" style=\"font-size: 20px\"> Go back to index</a>\n",
"\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/blob/develop/notebook/lattice-vibration/Phonon_2D.ipynb\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/blob/master/notebook/lattice-vibration/Phonon_2D.ipynb\n",
"\n",
"This notebook extends the notion of phonons to the 2D case. In this notebook, the link between the reciprocal space and the band dispersion plot along certain path is made explicit. The wave can now be transversal as opposed to longitudinal only in the 1D phonon case. A simple example, the square lattice, and a more complex one, the honeycomb lattice, are presented.\n",
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
Expand All @@ -27,6 +27,14 @@
"* Discover the importance of highly symmetrical points."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **Background theory** \n",
"[More on the background theory.](./theory/theory_phonon_2d.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -100,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -122,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -135,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -149,7 +157,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -186,10 +194,14 @@
"for widget in widgets:\n",
" handler.widgetList.append(widget)\n",
"\n",
"handler.tick_box_arrows.value = False\n",
"handler.slider_atom_radius.value=0.1\n",
"handler.slider_arrow_radius.value=0.05\n",
"handler.tick_box_arrows.value=True\n",
"handler.addArrows() # add arrows by default\n",
"\n",
"handler.tick_box_arrows.value = True\n",
"handler.set_view_parameters(clipDist=1, quality=\"low\")\n",
"# handler.slider_atom_radius.value = 0.1\n",
"handler.slider_arrow_radius.value = 0.1\n",
"handler.set_player_parameters(delay=handler.init_delay)\n",
"handler.set_view_dimensions()\n",
"handler.button_lattice.observe(on_lattice_change,\"value\")\n",
Expand Down Expand Up @@ -335,9 +347,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
".box_style{\n",
" border : 2px solid red;\n",
"}\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"<style>\n",
Expand All @@ -349,9 +378,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "392bd39bbb0845409a9b73607dd2b574",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Tab(children=(VBox(children=(GridBox(children=(VBox(children=(Output(),), layout=Layout(grid_ar…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b58c1354d9a443aebd43315215a2ec1e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(NGLWidget(max_frame=60),), layout=Layout(align_items='center', display='flex', flex_flow='colum…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(actions, HBox([handler.view], layout=layout).add_class(\"box_style\"))"
]
Expand Down Expand Up @@ -425,7 +483,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"metadata": {},
"source": [
"# **Background theory**: Introduction to molecular vibrations\n",
"\n",
"<i class=\"fa fa-book fa-2x\"></i><a href=\"../Molecule_Vibration.ipynb\" style=\"font-size: 20px\"> Go back to the interactive notebook</a>\n",
"\n",
"**Source code:** https://github.com/osscar-org/quantum-mechanics/tree/develop/notebook/lattice-vibration/theory/theory_molecular_vibration.ipynb\n",
Expand All @@ -19,7 +20,11 @@
"outputs": [
{
"data": {
"application/javascript": "MathJax.Hub.Config({\n TeX: { equationNumbers: { autoNumber: \"AMS\" } }\n});\n",
"application/javascript": [
"MathJax.Hub.Config({\n",
" TeX: { equationNumbers: { autoNumber: \"AMS\" } }\n",
"});\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
Expand Down Expand Up @@ -158,9 +163,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
35 changes: 11 additions & 24 deletions notebook/lattice-vibration/theory/theory_phonon_1d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,14 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"MathJax.Hub.Config({\n",
" TeX: { equationNumbers: { autoNumber: \"AMS\" } }\n",
"});\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%%javascript\n",
"MathJax.Hub.Config({\n",
" TeX: { equationNumbers: { autoNumber: \"AMS\" } }\n",
"});"
"# %%javascript\n",
"# MathJax.Hub.Config({\n",
"# TeX: { equationNumbers: { autoNumber: \"AMS\" } }\n",
"# });"
]
},
{
Expand All @@ -54,6 +39,8 @@
"source": [
"## **1D monoatomic chain**\n",
"$$\\require{cancel}$$\n",
"$$\\require{MathJax}$$\n",
"\n",
"Let's now consider the case of a 1D monoatomic chain in which only the first neighbours interactions are considered. Let $R_n=na$ be the position of atom $n$, $R_{n+1}=(n+1)a$ the position of atom $n+1$, etc., as shown in Fig. 1. The classical equation of motion of the $n$-th atom of mass $M$ in position $R_n+u_n(t)$ under the force $F_n$ is:\n",
"\\begin{equation}\n",
" M\\ddot u_n = -C_1(u_{n-1}-u_{n})-C_1(u_{n+1}-u_n)=-C_1(2u_n-u_{n-1}-u_{n+1})\n",
Expand All @@ -66,7 +53,7 @@
" \\label{eq:u_1d}\n",
"\\end{equation}\n",
"where $A$ is the amplitude of the displacement, $k$ is the phonon wave vector and $\\omega$ its frequency.<br>\n",
"Plugging Eq.\\eqref{eq:u_1d} into Eq.\\eqref{eq:1d_eq} results in\n",
"Plugging Eq.\\ref{eq:u_1d} into Eq.\\eqref{eq:1d_eq} results in\n",
"$$\n",
"\\begin{align}\n",
" -M \\omega^2 \\cancel{e^{ikn}}\\cancel{e^{-i\\omega t}} & =-C_1(2\\cancel{e^{ikn}}\\cancel{e^{-i\\omega t}}-\\cancel{e^{ikn}}\\cancel{e^{-i\\omega t}}e^{-ika}-\\cancel{e^{ikn}}\\cancel{e^{-i\\omega t}}e^{ika})\\nonumber \\\\\n",
Expand All @@ -79,13 +66,13 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"images/theory_phonon_1d_schematic.png\" style=\"margin:auto; width:40%\"/>\n",
"<img src=\"images/theory_phonon_1d_schematic.png\" style=\"margin:auto; width:50%\"/>\n",
"<p style=\"text-align: center\">\n",
" Figure 1: Schematic of the 1D monoatomic chain.\n",
"</p>\n"
Expand Down
Loading

0 comments on commit 247dc43

Please sign in to comment.