Skip to content

Commit

Permalink
Made animation play and loop by default. Set default k-point to somet…
Browse files Browse the repository at this point in the history
…hing nontrivial and initialized everything.
  • Loading branch information
Taylor-96 committed Oct 8, 2023
1 parent 4f2c566 commit ed566f5
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 17 deletions.
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
94 changes: 84 additions & 10 deletions notebook/lattice-vibration/Phonon_2D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5ae458bbda7148e89af095238743499d",
"version_major": 2,
"version_minor": 0
},
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib widget\n",
Expand All @@ -122,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -135,7 +148,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -149,7 +162,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -170,6 +183,21 @@
"\"\"\")\n",
"\n",
"\n",
"# Cause animation to play and loop by default.\n",
"stop = False\n",
"def loop(view):\n",
" import time\n",
" def do():\n",
" while True and not stop:\n",
" if view.frame == view.max_frame:\n",
" view.frame = 0\n",
" view.frame = view.frame + 1\n",
" time.sleep(0.2)\n",
" view._run_on_another_thread(do)\n",
" \n",
"view = handler.view \n",
"view.on_displayed(loop)\n",
"\n",
"widgets = [\n",
" handler.slider_amplitude,\n",
" handler.slider_C1,\n",
Expand Down Expand Up @@ -335,9 +363,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"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 +394,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "13aa0f33623840e2bd0e918cd5f74856",
"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": "0c00951c9c6f484eb058ff72a2d4b4c9",
"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 +499,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ed566f5

Please sign in to comment.