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..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] @@ -22,6 +28,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__ 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/requirements.txt b/requirements.txt index ff903f2..fe0dcef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +pip==21.0.1 voila==0.2.7 voila-osscar-template==0.2.8 -widget-bzvisualizer==0.1.0a1 +widget-bzvisualizer==0.1.0a2 +scipy 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': ''} 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