weas-widget


Nameweas-widget JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA widget to visualize and interact with atomistic structures in Jupyter Notebook.
upload_time2024-04-05 05:35:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License Copyright (c) 2024 Xing Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords atomistic edit visualize
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Welcome to WEAS Widget!
[![PyPI version](https://badge.fury.io/py/weas-widget.svg)](https://badge.fury.io/py/weas-widget)
[![Docs status](https://readthedocs.org/projects/weas-widget/badge)](http://weas-widget.readthedocs.io/)
[![Unit test](https://github.com/superstar54/weas-widget/actions/workflows/ci.yml/badge.svg)](https://github.com/superstar54/weas-widget/actions/workflows/ci.yml)

A widget to visualize and edit atomic structures in Jupyter Notebooks. It uses [WEAS](https://github.com/superstar54/weas) (Web Environment For Atomistic Structure) in the backend.


<img src="docs/source/_static/images/example-adsorption.gif"  width="100%"/>


Features:

- Model: space-filling, ball-stick, polyhedral.
- Supports importing data from ASE and Pymatgen.
- Edit structure: move, rotate, delete and replace atoms.
- Supports periodic boundary conditions
- Animations
- Isosurfaces
- Vector fields, e.g., magnetic moments, phonons, ...


## Installation

With `pip`:

```console
pip install weas-widget
```

To install the latest version from source, first clone the repository and then install using `pip`:

```console
git clone https://github.com/superstar54/weas-widget
cd weas-widget
npm install
npm run build
pip install -e .
```

## How to use

```python
from ase.build import molecule
from weas_widget import WeasWidget
atoms = molecule("C2H6SO")
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer
```

<img src="docs/source/_static/images/example-c2h6so.png"  width="300px"/>


Full documentation at: https://weas-widget.readthedocs.io/en/latest/index.html


## Reporting issues
If you encounter any problems, please first update the widget to the latest version.

```console
    pip install weas-widget  --upgrade
```

If the problem persists, please open a [GitHub issue](https://github.com/superstar54/weas-widget/issues)


## Features


### Select Atoms
- Pick Selection: Click directly on an atom to select it.
- Range Selection: Hold the `Shift` key and drag the right mouse button to select a group of atoms.

### Move, Rotate selected atoms

Press the keyboard shortcut, and move your mouse.

|Operation | Shortcut|
|----------|---------|
| Move     | `g`   |
| Rotate   | `r`   |
| Duplicate| `d`   |


### Delete selected atoms
Press the ``Delete`` key


### Export
- Export the modified atomic structure to ASE or Pymatgen
```python
atoms = viewer.to_ase()
```
- Save image to a path by:
```python
viewer.save_image("/home/xing/filename.png")
```
- Download image by:
```python
viewer.download_image("filename.png")
```

### Visualizing crystal structures
For a nice visualization of a crystal, show
- unit cell
- bonded atoms outside the cell
- polyhedra

```python
from weas_widget import WeasWidget
viewer1 = WeasWidget()
viewer1.load_example("tio2.cif")
viewer1.avr.model_style = 2
viewer1.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.avr.show_bonded_atoms = True
viewer1.avr.color_type = "VESTA"
viewer1
```

<img src="docs/source/_static/images/example-tio2.png"  width="300px"/>


### Isosurfaces

```python
from ase.build import molecule
from weas_widget import WeasWidget
from ase.io.cube import read_cube_data
volume, atoms = read_cube_data("h2o-homo.cube")
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.avr.iso.volumetric_data = {"values": volume}
viewer.avr.iso.settings = [{"isovalue": 0.0001, "mode": 0}]
viewer
```
<img src="docs/source/_static/images/example-isosurface.png"  width="300px"/>


### Magnetic moments
Show the magnetic moments as a vector field.

```python
from ase.build import bulk
from weas_widget import WeasWidget
import numpy as np
atoms = bulk("Fe", cubic=True)
atoms*=[2, 2, 1]
atoms.set_array("moment", np.ones(len(atoms)))
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.avr.model_style = 1
viewer
```
<img src="docs/source/_static/images/example-magnetic-moment.png"  width="300px"/>


### Phonons
Animate vibrational (phonon) modes (computed with external software).

```python
import numpy as np
from ase.build import bulk
from weas_widget import WeasWidget
from weas_widget.utils import generate_phonon_trajectory

atoms = bulk("Fe", cubic=True)
eigenvector = np.array([[0, -0.0, 0.5], [0, 0.0, -0.5]])
trajectory = generate_phonon_trajectory(atoms, eigenvector, repeat=[4, 4, 1])
viewer = WeasWidget()
viewer.from_ase(trajectory)
# set a vector field to show the arrow
viewer.avr.vf.settings = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer.avr.vf.show = True
viewer
```

<img src="docs/source/_static/images/example-phonon.gif"  width="300px"/>



## Test

### Unit test

```console
pytest
```

### End-to-end test

The e2e test is similar to [ipywidgets](https://ipywidgets.readthedocs.io/en/latest/dev_testing.html).

For the first time, one needs to install the dependence.

```
cd tests/notebooks/
yarn install
```

Then run in a terminal:

```
yarn start
```

In another terminal:

```
yarn test
```

If the snapshots need to be updated:

```
yarn test:update
```

## Contact
* Xing Wang  <xingwang1991@gmail.com>

## License
[MIT](http://opensource.org/licenses/MIT)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "weas-widget",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "atomistic, edit, visualize",
    "author": null,
    "author_email": "Xing Wang <xingwang1991@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/23/60/4954e085b47e116f6785944a0cf70da3fe11b2b3eee8e23c9ac47b2986fa/weas_widget-0.1.0.tar.gz",
    "platform": null,
    "description": "\n# Welcome to WEAS Widget!\n[![PyPI version](https://badge.fury.io/py/weas-widget.svg)](https://badge.fury.io/py/weas-widget)\n[![Docs status](https://readthedocs.org/projects/weas-widget/badge)](http://weas-widget.readthedocs.io/)\n[![Unit test](https://github.com/superstar54/weas-widget/actions/workflows/ci.yml/badge.svg)](https://github.com/superstar54/weas-widget/actions/workflows/ci.yml)\n\nA widget to visualize and edit atomic structures in Jupyter Notebooks. It uses [WEAS](https://github.com/superstar54/weas) (Web Environment For Atomistic Structure) in the backend.\n\n\n<img src=\"docs/source/_static/images/example-adsorption.gif\"  width=\"100%\"/>\n\n\nFeatures:\n\n- Model: space-filling, ball-stick, polyhedral.\n- Supports importing data from ASE and Pymatgen.\n- Edit structure: move, rotate, delete and replace atoms.\n- Supports periodic boundary conditions\n- Animations\n- Isosurfaces\n- Vector fields, e.g., magnetic moments, phonons, ...\n\n\n## Installation\n\nWith `pip`:\n\n```console\npip install weas-widget\n```\n\nTo install the latest version from source, first clone the repository and then install using `pip`:\n\n```console\ngit clone https://github.com/superstar54/weas-widget\ncd weas-widget\nnpm install\nnpm run build\npip install -e .\n```\n\n## How to use\n\n```python\nfrom ase.build import molecule\nfrom weas_widget import WeasWidget\natoms = molecule(\"C2H6SO\")\nviewer = WeasWidget()\nviewer.from_ase(atoms)\nviewer\n```\n\n<img src=\"docs/source/_static/images/example-c2h6so.png\"  width=\"300px\"/>\n\n\nFull documentation at: https://weas-widget.readthedocs.io/en/latest/index.html\n\n\n## Reporting issues\nIf you encounter any problems, please first update the widget to the latest version.\n\n```console\n    pip install weas-widget  --upgrade\n```\n\nIf the problem persists, please open a [GitHub issue](https://github.com/superstar54/weas-widget/issues)\n\n\n## Features\n\n\n### Select Atoms\n- Pick Selection: Click directly on an atom to select it.\n- Range Selection: Hold the `Shift` key and drag the right mouse button to select a group of atoms.\n\n### Move, Rotate selected atoms\n\nPress the keyboard shortcut, and move your mouse.\n\n|Operation | Shortcut|\n|----------|---------|\n| Move     | `g`   |\n| Rotate   | `r`   |\n| Duplicate| `d`   |\n\n\n### Delete selected atoms\nPress the ``Delete`` key\n\n\n### Export\n- Export the modified atomic structure to ASE or Pymatgen\n```python\natoms = viewer.to_ase()\n```\n- Save image to a path by:\n```python\nviewer.save_image(\"/home/xing/filename.png\")\n```\n- Download image by:\n```python\nviewer.download_image(\"filename.png\")\n```\n\n### Visualizing crystal structures\nFor a nice visualization of a crystal, show\n- unit cell\n- bonded atoms outside the cell\n- polyhedra\n\n```python\nfrom weas_widget import WeasWidget\nviewer1 = WeasWidget()\nviewer1.load_example(\"tio2.cif\")\nviewer1.avr.model_style = 2\nviewer1.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]\nviewer1.avr.show_bonded_atoms = True\nviewer1.avr.color_type = \"VESTA\"\nviewer1\n```\n\n<img src=\"docs/source/_static/images/example-tio2.png\"  width=\"300px\"/>\n\n\n### Isosurfaces\n\n```python\nfrom ase.build import molecule\nfrom weas_widget import WeasWidget\nfrom ase.io.cube import read_cube_data\nvolume, atoms = read_cube_data(\"h2o-homo.cube\")\nviewer = WeasWidget()\nviewer.from_ase(atoms)\nviewer.avr.iso.volumetric_data = {\"values\": volume}\nviewer.avr.iso.settings = [{\"isovalue\": 0.0001, \"mode\": 0}]\nviewer\n```\n<img src=\"docs/source/_static/images/example-isosurface.png\"  width=\"300px\"/>\n\n\n### Magnetic moments\nShow the magnetic moments as a vector field.\n\n```python\nfrom ase.build import bulk\nfrom weas_widget import WeasWidget\nimport numpy as np\natoms = bulk(\"Fe\", cubic=True)\natoms*=[2, 2, 1]\natoms.set_array(\"moment\", np.ones(len(atoms)))\nviewer = WeasWidget()\nviewer.from_ase(atoms)\nviewer.avr.model_style = 1\nviewer\n```\n<img src=\"docs/source/_static/images/example-magnetic-moment.png\"  width=\"300px\"/>\n\n\n### Phonons\nAnimate vibrational (phonon) modes (computed with external software).\n\n```python\nimport numpy as np\nfrom ase.build import bulk\nfrom weas_widget import WeasWidget\nfrom weas_widget.utils import generate_phonon_trajectory\n\natoms = bulk(\"Fe\", cubic=True)\neigenvector = np.array([[0, -0.0, 0.5], [0, 0.0, -0.5]])\ntrajectory = generate_phonon_trajectory(atoms, eigenvector, repeat=[4, 4, 1])\nviewer = WeasWidget()\nviewer.from_ase(trajectory)\n# set a vector field to show the arrow\nviewer.avr.vf.settings = [{\"origins\": \"positions\", \"vectors\": \"movement\", \"radius\": 0.1}]\nviewer.avr.vf.show = True\nviewer\n```\n\n<img src=\"docs/source/_static/images/example-phonon.gif\"  width=\"300px\"/>\n\n\n\n## Test\n\n### Unit test\n\n```console\npytest\n```\n\n### End-to-end test\n\nThe e2e test is similar to [ipywidgets](https://ipywidgets.readthedocs.io/en/latest/dev_testing.html).\n\nFor the first time, one needs to install the dependence.\n\n```\ncd tests/notebooks/\nyarn install\n```\n\nThen run in a terminal:\n\n```\nyarn start\n```\n\nIn another terminal:\n\n```\nyarn test\n```\n\nIf the snapshots need to be updated:\n\n```\nyarn test:update\n```\n\n## Contact\n* Xing Wang  <xingwang1991@gmail.com>\n\n## License\n[MIT](http://opensource.org/licenses/MIT)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Xing Wang  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A widget to visualize and interact with atomistic structures in Jupyter Notebook.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://weas-widget.readthedocs.io",
        "Source": "https://github.com/superstart54/weas-widget"
    },
    "split_keywords": [
        "atomistic",
        " edit",
        " visualize"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0dc416f37e6e27224f232ceeee294942d85b9bdd25b034bb4d82333767bc193",
                "md5": "b71c2b5442ed2bf5a36a2076ab05c58b",
                "sha256": "aeef791fd932b5e3d45ba73f24e5d8f15b961ff694f456b9431ab58f94a4d1b8"
            },
            "downloads": -1,
            "filename": "weas_widget-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b71c2b5442ed2bf5a36a2076ab05c58b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 196474,
            "upload_time": "2024-04-05T05:35:50",
            "upload_time_iso_8601": "2024-04-05T05:35:50.638905Z",
            "url": "https://files.pythonhosted.org/packages/b0/dc/416f37e6e27224f232ceeee294942d85b9bdd25b034bb4d82333767bc193/weas_widget-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23604954e085b47e116f6785944a0cf70da3fe11b2b3eee8e23c9ac47b2986fa",
                "md5": "8b8ee2f224952a943451d710ed10f858",
                "sha256": "bbd821269c4f9113f480f63c8e503b20f4b7dde6045f19bed9fe9e5a70652daf"
            },
            "downloads": -1,
            "filename": "weas_widget-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8b8ee2f224952a943451d710ed10f858",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 193070,
            "upload_time": "2024-04-05T05:35:54",
            "upload_time_iso_8601": "2024-04-05T05:35:54.534843Z",
            "url": "https://files.pythonhosted.org/packages/23/60/4954e085b47e116f6785944a0cf70da3fe11b2b3eee8e23c9ac47b2986fa/weas_widget-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-05 05:35:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "superstart54",
    "github_project": "weas-widget",
    "github_not_found": true,
    "lcname": "weas-widget"
}
        
Elapsed time: 0.21996s