From 6c1f11fdbb2216b9ad8ed17447ab867206cb633e Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 18:33:26 +0100 Subject: [PATCH 1/8] update the workflows --- .github/workflows/{heroku_deploy.yml => heroku-deploy.yml} | 0 .github/workflows/python-publish.yml | 1 + 2 files changed, 1 insertion(+) rename .github/workflows/{heroku_deploy.yml => heroku-deploy.yml} (100%) diff --git a/.github/workflows/heroku_deploy.yml b/.github/workflows/heroku-deploy.yml similarity index 100% rename from .github/workflows/heroku_deploy.yml rename to .github/workflows/heroku-deploy.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 6a636af..e148f37 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -22,6 +22,7 @@ jobs: run: | python -m pip install --upgrade pip pip install setuptools wheel twine + pip install jupyterlab - name: Build and publish env: TWINE_USERNAME: __token__ From d7e1a3e22c054cb9f1d029ad4c437144ebaf8947 Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 18:36:35 +0100 Subject: [PATCH 2/8] update the workflows --- .github/workflows/python-publish.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index e148f37..d59445b 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -4,6 +4,12 @@ name: Upload Python Package on: + workflow_dispatch: + inputs: + name: + description: 'Publish on PyPi' + required: true + default: 'Publish on PyPi' release: types: [created] From 26c7fcbbee1093dd752441e6325f02cc7fdacec7 Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 18:40:54 +0100 Subject: [PATCH 3/8] update requirements.txt file --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ff903f2..af70302 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ voila==0.2.7 voila-osscar-template==0.2.8 -widget-bzvisualizer==0.1.0a1 +widget-bzvisualizer==0.1.0a2 From 284567a91da44f10e169636f97e5efc13f3bcf78 Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 18:48:35 +0100 Subject: [PATCH 4/8] add the scipy --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index af70302..e8acfba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +scipy==1.6.1 voila==0.2.7 voila-osscar-template==0.2.8 widget-bzvisualizer==0.1.0a2 From 177c1fc32e181453cc0dbff3d4dfec8ac1569ccb Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 18:53:07 +0100 Subject: [PATCH 5/8] update the pip version --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e8acfba..856bd9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +pip==21.0.1 scipy==1.6.1 voila==0.2.7 voila-osscar-template==0.2.8 From c93369479377c39d83af73be3f2e92f22ac5f485 Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 19:00:29 +0100 Subject: [PATCH 6/8] test again --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 856bd9c..fe0dcef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pip==21.0.1 -scipy==1.6.1 voila==0.2.7 voila-osscar-template==0.2.8 widget-bzvisualizer==0.1.0a2 +scipy From 4400aeabf7d09d8f4f1737f3752d900f5c58b51a Mon Sep 17 00:00:00 2001 From: Dou Date: Wed, 24 Mar 2021 23:27:09 +0100 Subject: [PATCH 7/8] make it possible to update the structure --- example/bzvisualizer-example.ipynb | 10 +++--- js/lib/BZVisualizer.js | 4 +-- js/lib/example.js | 9 +++++ widget_bzvisualizer/example.py | 57 ++++++++++++++++++++++++++++-- 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/example/bzvisualizer-example.ipynb b/example/bzvisualizer-example.ipynb index c8c4a40..ff9789f 100644 --- a/example/bzvisualizer-example.ipynb +++ b/example/bzvisualizer-example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "hindu-movement", + "id": "agreed-accreditation", "metadata": {}, "source": [ "## **A Jupyter widget to visualize the 1st Brillouin zone**\n", @@ -13,7 +13,7 @@ { "cell_type": "code", "execution_count": null, - "id": "particular-companion", + "id": "valued-worry", "metadata": {}, "outputs": [], "source": [ @@ -24,7 +24,7 @@ { "cell_type": "code", "execution_count": null, - "id": "great-number", + "id": "fluid-heavy", "metadata": {}, "outputs": [], "source": [ @@ -34,7 +34,7 @@ { "cell_type": "code", "execution_count": null, - "id": "constant-techno", + "id": "figured-palestinian", "metadata": {}, "outputs": [], "source": [ @@ -45,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "north-moisture", + "id": "powered-gardening", "metadata": {}, "outputs": [], "source": [] diff --git a/js/lib/BZVisualizer.js b/js/lib/BZVisualizer.js index 55ea367..9ddac73 100644 --- a/js/lib/BZVisualizer.js +++ b/js/lib/BZVisualizer.js @@ -739,8 +739,8 @@ var BZVisualizer = function (showAxes, showBVectors, showPathpoints, useSVGRende } else { - var widthHalf = 0.5 * renderer.context.canvas.width / devicePixelRatio; - var heightHalf = 0.5 * renderer.context.canvas.height / devicePixelRatio; + var widthHalf = 0.5 * renderer.getContext().canvas.width / devicePixelRatio; + var heightHalf = 0.5 * renderer.getContext().canvas.height / devicePixelRatio; vector2D.x = (vector2D.x * widthHalf) + widthHalf; vector2D.y = - (vector2D.y * heightHalf) + heightHalf; } diff --git a/js/lib/example.js b/js/lib/example.js index d73078b..e96eaa9 100644 --- a/js/lib/example.js +++ b/js/lib/example.js @@ -56,6 +56,7 @@ var BrillouinZoneView = widgets.DOMWidgetView.extend({ this.model.on('change:kpts', this.kpts_changed, this); this.model.on('change:face_color', this.faceColor_changed, this); this.model.on('change:path_vectors', this.vectors_changed, this); + this.model.on('change:update_structure', this.reloadBZ, this); this.el.innerHTML = '
' + '
'; @@ -70,6 +71,14 @@ var BrillouinZoneView = widgets.DOMWidgetView.extend({ }); }, + reloadBZ: function () { + var jsondata = this.model.get('jsondata'); + var faceColor = this.model.get('face_color'); + + this.BZVisualizer.loadBZ(canvasID = this.canvasID, infoID = this.infoID, jsondata = jsondata); + this.BZVisualizer.set_visibility(faceColor); + }, + toggle_faceColor: function () { const faceColor = this.model.get('face_color'); this.model.set('face_color', !faceColor); diff --git a/widget_bzvisualizer/example.py b/widget_bzvisualizer/example.py index 18a582d..ce46548 100644 --- a/widget_bzvisualizer/example.py +++ b/widget_bzvisualizer/example.py @@ -1,5 +1,5 @@ import ipywidgets as widgets -from traitlets import Unicode, Dict, List, Bool +from traitlets import Unicode, Dict, List, Bool, Int, observe import seekpath from seekpath.brillouinzone.brillouinzone import get_BZ import numpy as np @@ -49,6 +49,9 @@ class BZVisualizer(widgets.DOMWidget): # The path vectors path_vectors = List().tag(sync=True) + # Singal to update the structure + update_structure = Int().tag(sync=True) + def __init__(self, cell, positions, numbers, face_color=True): if type(cell) == np.ndarray: cell = cell.tolist() @@ -107,4 +110,54 @@ def __init__(self, cell, positions, numbers, face_color=True): self.jsondata = response self.kpts = self.jsondata['explicit_kpoints_abs'] - self.path_vectors = self.jsondata['path'] \ No newline at end of file + self.path_vectors = self.jsondata['path'] + self.update_structure = 0 + + @observe('cell') + def _cell_change(self, change): + system = (np.array(change['new']), np.array(self.positions), np.array(self.numbers)) + res = seekpath.getpaths.get_path(system, with_time_reversal=False) + + real_lattice = res["primitive_lattice"] + rec_lattice = np.array(seekpath.hpkot.tools.get_reciprocal_cell_rows(real_lattice)) + b1, b2, b3 = rec_lattice + + faces_data = get_BZ(b1=b1, b2=b2, b3=b3) + + response = {} + response["faces_data"] = faces_data + response["b1"] = b1.tolist() + response["b2"] = b2.tolist() + response["b3"] = b3.tolist() + ## Convert to absolute + response["kpoints"] = { + k: (v[0] * b1 + v[1] * b2 + v[2] * b3).tolist() + for k, v in res["point_coords"].items() + } + response["kpoints_rel"] = { + k: [v[0], v[1], v[2]] for k, v in res["point_coords"].items() + } + response["path"] = res["path"] + + # It should use the same logic, so give the same cell as above + res_explicit = seekpath.get_explicit_k_path(system, with_time_reversal=False) + for k in res_explicit: + if k == "segments" or k.startswith("explicit_"): + if isinstance(res_explicit[k], np.ndarray): + response[k] = res_explicit[k].tolist() + else: + response[k] = res_explicit[k] + + if ( + np.sum( + np.abs( + np.array(res_explicit["reciprocal_primitive_lattice"]) + - np.array(res["reciprocal_primitive_lattice"]) + ) + ) + > 1.0e-7 + ): + raise AssertionError("Got different reciprocal cells...") + + self.jsondata = response + self.update_structure += 1 \ No newline at end of file From 925d3dadd86f3fa35d7fc0df3e5e824129907488 Mon Sep 17 00:00:00 2001 From: Dou Date: Thu, 25 Mar 2021 19:38:30 +0100 Subject: [PATCH 8/8] version 0.1.0a3 --- widget_bzvisualizer/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget_bzvisualizer/_version.py b/widget_bzvisualizer/_version.py index 879a7f5..36cdc75 100644 --- a/widget_bzvisualizer/_version.py +++ b/widget_bzvisualizer/_version.py @@ -1,5 +1,5 @@ # Module version -version_info = (0, 1, 0, 'alpha', 2) +version_info = (0, 1, 0, 'alpha', 3) # Module version stage suffix map _specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}