Skip to content

Commit

Permalink
Merge pull request #1 from osscar-org/develop
Browse files Browse the repository at this point in the history
Version 0.1.0a2
  • Loading branch information
dou-du authored Mar 24, 2021
2 parents 61f0b76 + 235b4e8 commit 200d465
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/heroku_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

name: Deploy on Heroku

on:
workflow_dispatch:
inputs:
name:
description: 'Deploy on Heroku'
required: true
default: 'Deploy on Heroku'
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "osscar-widget-bzvisualizer" #Must be unique in Heroku
heroku_email: "[email protected]"
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
# pytest
31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: voila --template=osscar --VoilaConfiguration.enable_nbextensions=True --VoilaConfiguration.file_whitelist="['.*']" example/bzvisualizer-example.ipynb --port=$PORT --no-browser --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120 --MappingKernelManager.cull_busy=True
75 changes: 75 additions & 0 deletions example/bzvisualizer-example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "hindu-movement",
"metadata": {},
"source": [
"## **A Jupyter widget to visualize the 1st Brillouin zone**\n",
"\n",
"<hr style=\"height:1px;border:none;color:#cccccc;background-color:#cccccc;\" />"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "particular-companion",
"metadata": {},
"outputs": [],
"source": [
"from widget_bzvisualizer import BZVisualizer\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "great-number",
"metadata": {},
"outputs": [],
"source": [
"lattice = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "constant-techno",
"metadata": {},
"outputs": [],
"source": [
"w = BZVisualizer(lattice, [[0.0, 0.0, 0.0]], [1], True)\n",
"display(w)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "north-moisture",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
49 changes: 45 additions & 4 deletions js/lib/BZVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,44 @@ var BZVisualizer = function (showAxes, showBVectors, showPathpoints, useSVGRende
new THREE.Vector3(p2[0], p2[1], p2[2]));
var line = new THREE.Line(geometry, line_material);
line.material.linewidth = 4;
line.name = "pathvectors";
scene.add(line);
});

// update the path vectors
this.update_pathVector = function (pathVector) {
var vectors = scene.getObjectByName('pathvectors');
while (vectors) {
vectors = scene.getObjectByName('pathvectors');
scene.remove(vectors);
};

pathVector.forEach(function (linespec) {
label1 = linespec[0];
label2 = linespec[1];
p1 = special_points[label1];
p2 = special_points[label2];

var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(p1[0], p1[1], p1[2]));
geometry.vertices.push(
new THREE.Vector3(p2[0], p2[1], p2[2]));
var line = new THREE.Line(geometry, line_material);
line.material.linewidth = 4;
line.name = "pathvectors";
scene.add(line);
});

render();
};


if (showPathpoints) {
kpoints_abs = jsondata['explicit_kpoints_abs'];
for (var idx in kpoints_abs) {
pos = kpoints_abs[idx];
radius = 0.01 * max_b_length;
radius = 0.008 * max_b_length;

var sphere_geometry = new THREE.SphereGeometry(
radius, 16, 16);
Expand Down Expand Up @@ -582,7 +611,7 @@ var BZVisualizer = function (showAxes, showBVectors, showPathpoints, useSVGRende

// canvas3d.addEventListener('dblclick', bz_switch_enable);

var toggle_visiblity = function (event) {
toggle_visibility = function (event) {
if (bz_material.opacity === 0.0) {
bz_material.opacity = 0.3;
bz_material.needsUpdate = true;
Expand All @@ -594,7 +623,19 @@ var BZVisualizer = function (showAxes, showBVectors, showPathpoints, useSVGRende
render();
}

canvas3d.addEventListener('dblclick', toggle_visiblity);
this.set_visibility = function (faceColor) {
if (faceColor) {
bz_material.opacity = 0.3;
bz_material.needsUpdate = true;
} else {
bz_material.opacity = 0.0;
bz_material.needsUpdate = true;
};

render();
}

// canvas3d.addEventListener('dblclick', toggle_visibility);

this.update_kpts = function (kpoints_abs) {
var kpt = scene.getObjectByName('kpts');
Expand All @@ -605,7 +646,7 @@ var BZVisualizer = function (showAxes, showBVectors, showPathpoints, useSVGRende

for (var idx in kpoints_abs) {
pos = kpoints_abs[idx];
radius = 0.01 * max_b_length;
radius = 0.008 * max_b_length;

var sphere_geometry = new THREE.SphereGeometry(
radius, 16, 16);
Expand Down
26 changes: 24 additions & 2 deletions js/lib/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,49 @@ var BrillouinZoneView = widgets.DOMWidgetView.extend({
this.BZVisualizer = new BZVisualizer(true, true, true, false);
},

events: {
'dblclick': 'toggle_faceColor',
},

// Defines how the widget gets rendered into the DOM
render: function () {
// Observe changes in the value traitlet in Python, and define
// a custom callback.
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.el.innerHTML = '<div class="BZ-widget" id="' + this.canvasID + '"></div>'
+ '<div id="' + this.infoID + '"></div>';

var jsondata = this.model.get('jsondata');
var faceColor = this.model.get('face_color');

that = this;
$(document).ready(function () {
that.BZVisualizer.loadBZ(canvasID=that.canvasID, infoID=that.infoID, jsondata=jsondata);
that.BZVisualizer.loadBZ(canvasID = that.canvasID, infoID = that.infoID, jsondata = jsondata);
that.BZVisualizer.set_visibility(faceColor);
});
},

toggle_faceColor: function () {
const faceColor = this.model.get('face_color');
this.model.set('face_color', !faceColor);
this.touch();
},

kpts_changed: function () {
console.log("This function has been triggled here***********");
const kpts = this.model.get('kpts');
this.BZVisualizer.update_kpts(kpts);
},

vectors_changed: function () {
const vectors = this.model.get('path_vectors');
this.BZVisualizer.update_pathVector(vectors);
},

faceColor_changed: function () {
this.BZVisualizer.set_visibility(this.model.get('face_color'));
}
});

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
voila==0.2.7
voila-osscar-template==0.2.8
widget-bzvisualizer==0.1.0a1
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', 1)
version_info = (0, 1, 0, 'alpha', 2)

# Module version stage suffix map
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
Expand Down
15 changes: 11 additions & 4 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
from traitlets import Unicode, Dict, List, Bool
import seekpath
from seekpath.brillouinzone.brillouinzone import get_BZ
import numpy as np
Expand Down Expand Up @@ -43,7 +43,13 @@ class BZVisualizer(widgets.DOMWidget):
# The jsondata for the Brillouin zone
jsondata = Dict().tag(sync=True)

def __init__(self, cell, positions, numbers):
# Show the BZ surface
face_color = Bool(True).tag(sync=True)

# The path vectors
path_vectors = List().tag(sync=True)

def __init__(self, cell, positions, numbers, face_color=True):
if type(cell) == np.ndarray:
cell = cell.tolist()

Expand All @@ -53,7 +59,7 @@ def __init__(self, cell, positions, numbers):
if type(numbers) == np.ndarray:
numbers = numbers.tolist()

super().__init__(cell = cell, positions=positions, numbers=numbers)
super().__init__(cell = cell, positions=positions, numbers=numbers, face_color=face_color)

system = (np.array(cell), np.array(positions), np.array(numbers))
res = seekpath.getpaths.get_path(system, with_time_reversal=False)
Expand Down Expand Up @@ -100,4 +106,5 @@ def __init__(self, cell, positions, numbers):
raise AssertionError("Got different reciprocal cells...")

self.jsondata = response
self.kpts = self.jsondata['explicit_kpoints_abs']
self.kpts = self.jsondata['explicit_kpoints_abs']
self.path_vectors = self.jsondata['path']

0 comments on commit 200d465

Please sign in to comment.