A widget to visualize and edit atomic structures in Jupyter Notebook
MIT License
A widget to visualize and edit atomic structures in Jupyter Notebooks. It uses WEAS (Web Environment For Atomistic Structure) in the backend.
Features:
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 .
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
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
Shift
key and drag the right mouse button to select a group of atoms.Press the keyboard shortcut, and move your mouse.
Operation | Shortcut |
---|---|
Move | g |
Rotate | r |
Duplicate | d |
Press the Delete
key
atoms = viewer.to_ase()
viewer.save_image("/home/xing/filename.png")
viewer.download_image("filename.png")
For a nice visualization of a crystal, show
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
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
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.avr.model_style = 1
viewer
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.avr.vf.settings = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer.avr.vf.show = True
viewer
Draw a plane that is defined by the miller indices and distance from the origin or by selecting the atoms.
viewer.avr.lp.add_plane_from_indices(name = "111",
indices = [1, 1, 1],
distance = 4,
scale = 1.0,
color = [0, 1, 1, 0.5])
viewer.avr.lp.build_plane()
pytest
The e2e test is similar to ipywidgets.
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