Skip to main content

A widget to visualize and interact with atomistic structures in Jupyter Notebook.

Project description

Welcome to WEAS Widget!

PyPI version Docs status Unit test

A widget to visualize and edit atomic structures in Jupyter Notebooks. It uses WEAS (Web Environment For Atomistic Structure) in the backend.

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:

pip install weas-widget

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

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

How to use

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

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.

    pip install weas-widget  --upgrade

If the problem persists, please open a GitHub issue

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
atoms = viewer.to_ase()
  • Save image to a path by:
viewer.save_image("/home/xing/filename.png")
  • Download image by:
viewer.download_image("filename.png")

Visualizing crystal structures

For a nice visualization of a crystal, show

  • unit cell
  • bonded atoms outside the cell
  • polyhedra
from weas_widget import WeasWidget
viewer1 = WeasWidget()
viewer1.load_example("tio2.cif")
viewer1.modelStyle = 2
viewer1.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.showBondedAtoms = True
viewer1.colorType = "VESTA"
viewer1

Isosurfaces

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.volumetricData = {"values": volume}
viewer.isoSettings = [{"isovalue": 0.0001, "mode": 0}]
viewer

Magnetic moments

Show the magnetic moments as a vector field.

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.modelStyle = 1
viewer

Phonons

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

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.vectorField = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer

Contact

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weas_widget-0.0.16.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

weas_widget-0.0.16-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file weas_widget-0.0.16.tar.gz.

File metadata

  • Download URL: weas_widget-0.0.16.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for weas_widget-0.0.16.tar.gz
Algorithm Hash digest
SHA256 5089a37044ea3b9ae22bc2db7c5f177ef9f25a19cf47a1108bc9e4f536f8e648
MD5 0faad563cd16816d16ac240afbbc58bd
BLAKE2b-256 933c5f35e8eaca40058cc6b5004e221798b42d43cb8922de0d3559bdf85f3aea

See more details on using hashes here.

File details

Details for the file weas_widget-0.0.16-py3-none-any.whl.

File metadata

File hashes

Hashes for weas_widget-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 124558c96bc87843e828d25f1db7c403951d88803ffb8029021ec41351e2ce80
MD5 e3806350039671a50df3250c7a5c65c6
BLAKE2b-256 8931ed5fd71065ee7a75ae3b2e506c930c42d7375060d985e47e93b9bc5f08f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page