From 10180efe0668592139850bf56bdfbfcd1e51a395 Mon Sep 17 00:00:00 2001 From: Kristjan Eimre Date: Mon, 25 Mar 2024 23:24:16 +0200 Subject: [PATCH] fix dependencies; update example --- README.md | 4 +- example/example.ipynb | 160 ++++++++++++++++++++++-------------------- js/widget.js | 4 +- package-lock.json | 8 +-- package.json | 2 +- pyproject.toml | 14 +++- 6 files changed, 106 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index e6cadd6..e7acc72 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,14 @@ The primary input is a crystal structure, which is parsed by [seekpath](https:// This repo is bootstrapped with `npm create anywidget@latest`. -## Installation +## Installation & usage ```sh pip install widget-bzvisualizer ``` +For usage examples, see `example/example.ipynb`. + ## Development Install the python code: diff --git a/example/example.ipynb b/example/example.ipynb index 708ccb5..7d72f4a 100644 --- a/example/example.ipynb +++ b/example/example.ipynb @@ -1,78 +1,86 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n", - "%env ANYWIDGET_HMR=1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from widget_bzvisualizer import BZVisualizer\n", - "import ase.io\n", - "\n", - "def load_cif_cell_info(cif):\n", - " \"\"\"Loads cell, relative positions and atom numbers from a CIF file\"\"\"\n", - " struct = ase.io.read(cif)\n", - " return struct.cell, struct.get_scaled_positions(), struct.numbers" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cell, rel_coords, atom_numbers = load_cif_cell_info(\"./mc3d-10.cif\")\n", - "bz = BZVisualizer(cell, rel_coords, atom_numbers)\n", - "bz" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cell, rel_coords, atom_numbers = load_cif_cell_info(\"./mc3d-10016.cif\")\n", - "bz = BZVisualizer(cell, rel_coords, atom_numbers, width=\"300px\", height=\"300px\")\n", - "bz" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "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.10.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# This cell is only needed for development!\n", + "%load_ext autoreload\n", + "%autoreload 2\n", + "%env ANYWIDGET_HMR=1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from widget_bzvisualizer import BZVisualizer\n", + "\n", + "cell = [\n", + " [5.0, 0.0, 0.0],\n", + " [0.0, 5.0, 0.0],\n", + " [0.0, 0.0, 5.0],\n", + "]\n", + "# atomic coordinates in terms of unit vectors\n", + "rel_coords = [[0.0, 0.0, 0.0]]\n", + "# element numbers of atoms\n", + "atom_numbers = [6]\n", + "\n", + "bz = BZVisualizer(cell, rel_coords, atom_numbers, width=\"100%\", height=\"400px\")\n", + "display(bz)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Load info with ASE\n", + "# NOTE: (ASE is not included as a direct dependency, needs to be installed separately)\n", + "import ase.io\n", + "\n", + "def load_cell_info_ase(file):\n", + " \"\"\"Loads cell, relative positions and atom numbers from a CIF file\"\"\"\n", + " struct = ase.io.read(file)\n", + " return struct.cell, struct.get_scaled_positions(), struct.numbers\n", + "\n", + "cell, rel_coords, atom_numbers = load_cell_info_ase(\"./mc3d-10016.cif\")\n", + "bz2 = BZVisualizer(cell, rel_coords, atom_numbers)\n", + "display(bz2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/js/widget.js b/js/widget.js index 042863e..a3330f3 100644 --- a/js/widget.js +++ b/js/widget.js @@ -8,13 +8,13 @@ function render({ model, el }) { container.style.height = model.get("height"); container.style.margin = "0 auto"; - el.appendChild(container); - let mainBZVisualizer = createBZVisualizer(container, getSeekpathData()); model.on("change:seekpath_data", () => { mainBZVisualizer.loadBZ(getSeekpathData()); }); + + el.appendChild(container); } export default { render }; diff --git a/package-lock.json b/package-lock.json index 8040d61..2e17b35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "brillouinzone-visualizer": "^0.3.1" + "brillouinzone-visualizer": "^0.3.2" }, "devDependencies": { "esbuild": "^0.20.0" @@ -380,9 +380,9 @@ } }, "node_modules/brillouinzone-visualizer": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/brillouinzone-visualizer/-/brillouinzone-visualizer-0.3.1.tgz", - "integrity": "sha512-nScMfiEoyCm+pq+hGhQmnnulO/dBefEjBANn5v2V5yRTHJmRt5JzgA9ta70GJAo9zCVopCLlyOyStHxl76Wmrw==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/brillouinzone-visualizer/-/brillouinzone-visualizer-0.3.2.tgz", + "integrity": "sha512-DyS4ukP4jpxg02x8/TFHH8MFa/inxPcivDQRN4XUud+hixAcj9Q9oxPe80Xcru0HgbQDlbT9urF9aKx4y/WGFw==", "dependencies": { "three": "~0.162.0" } diff --git a/package.json b/package.json index 25106d5..f0c0d51 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,6 @@ "esbuild": "^0.20.0" }, "dependencies": { - "brillouinzone-visualizer": "^0.3.1" + "brillouinzone-visualizer": "^0.3.2" } } diff --git a/pyproject.toml b/pyproject.toml index 0a65cc3..28831ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,11 +5,21 @@ build-backend = "hatchling.build" [project] name = "widget-bzvisualizer" version = "0.2.1" -dependencies = ["anywidget"] +dependencies = [ + "anywidget~=0.9.3", + "numpy~=1.21", + "scipy~=1.10", + "seekpath~=2.1", +] readme = "README.md" [project.optional-dependencies] -dev = ["watchfiles", "jupyterlab", "ase", "bumpver==2023.1129"] +dev = [ + "watchfiles", + "jupyterlab", + "ase", + "bumpver==2023.1129", +] # automatically add the dev feature to the default env (e.g., hatch shell) [tool.hatch.envs.default]