Skip to content

Commit

Permalink
fix dependencies; update example
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Mar 25, 2024
1 parent 6f30a2d commit 10180ef
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 86 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
160 changes: 84 additions & 76 deletions example/example.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"esbuild": "^0.20.0"
},
"dependencies": {
"brillouinzone-visualizer": "^0.3.1"
"brillouinzone-visualizer": "^0.3.2"
}
}
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 10180ef

Please sign in to comment.