Skip to content

Commit

Permalink
Merge pull request #2 from osscar-org/develop
Browse files Browse the repository at this point in the history
Prepare for version 0.1.0a3
  • Loading branch information
dou-du authored Mar 25, 2021
2 parents 200d465 + 925d3da commit 9731e81
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 11 deletions.
File renamed without changes.
7 changes: 7 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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__
Expand Down
10 changes: 5 additions & 5 deletions example/bzvisualizer-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "particular-companion",
"id": "valued-worry",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -24,7 +24,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "great-number",
"id": "fluid-heavy",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,7 +34,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "constant-techno",
"id": "figured-palestinian",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -45,7 +45,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "north-moisture",
"id": "powered-gardening",
"metadata": {},
"outputs": [],
"source": []
Expand Down
4 changes: 2 additions & 2 deletions js/lib/BZVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions js/lib/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="BZ-widget" id="' + this.canvasID + '"></div>'
+ '<div id="' + this.infoID + '"></div>';
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion widget_bzvisualizer/_version.py
Original file line number Diff line number Diff line change
@@ -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': ''}
Expand Down
57 changes: 55 additions & 2 deletions widget_bzvisualizer/example.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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']
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

0 comments on commit 9731e81

Please sign in to comment.