{ "cells": [ { "cell_type": "markdown", "id": "31ff2524", "metadata": {}, "source": [ "# Highlight atoms\n", "\n", "\n", "One can highlight the atoms using the following shapes:\n", "\n", "- sphere\n", "- box\n", "- cross\n", "\n", "One can see the highlight setting:\n", "\n", "```python\n", "viewer.avr.highlight.settings\n", "```\n", "\n", "The default settings has `selection` and `fixed` items, which are used to highlight the selected atoms and fixed atoms, respectively.\n", "\n", "Add highlight item\n", "-------------------\n", "One can add one highlight item with the following code:\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "87afd915", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "82bc7e6162a648f2a469ed85ba5d730d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "WeasWidget(children=(,))" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from weas_widget import WeasWidget\n", "from ase.build import fcc110\n", "\n", "slab = fcc110('Pt', size=(3, 3, 6), vacuum=10.0)\n", "viewer = WeasWidget()\n", "viewer.from_ase(slab)\n", "viewer.avr.highlight.settings['my_highlight'] = {\"indices\": [len(slab)-1],\n", " \"type\": \"sphere\",\n", " \"color\": [1.0, 0.0, 0.0],\n", " \"scale\": 1.2,\n", " \"opacity\": 0.4}\n", "viewer" ] }, { "cell_type": "markdown", "id": "f8dc7619", "metadata": {}, "source": [ "\n", "\n", "Highlight fixed atoms\n", "---------------------\n", "When loading ASE atoms, constraints are converted into an atom attribute ``fixed_xyz`` (N x 3 booleans). If any axis is fixed, ``fixed_xyz`` is stored and the widget automatically highlights those atoms using the ``fixed`` crossView entry. If no atoms are fixed, ``fixed_xyz`` is omitted.\n", "\n", "\n", "Pymatgen structures can also carry fixed-atom info via the ``selective_dynamics`` site property (True means movable). When present, it is converted into ``fixed_xyz`` and preserved on export.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "e7d6dbf1", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c47a76b447b7427e9676fcde9f1f3548", "version_major": 2, "version_minor": 0 }, "text/plain": [ "WeasWidget(children=(,))" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from weas_widget import WeasWidget\n", "from ase.build import fcc110\n", "from ase.constraints import FixAtoms\n", "\n", "slab = fcc110('Pt', size=(3, 3, 6), vacuum=10.0)\n", "c = FixAtoms(indices=[atom.index for atom in slab if atom.z < 12.0])\n", "slab.set_constraint(c)\n", "\n", "viewer = WeasWidget()\n", "viewer.from_ase(slab)\n", "viewer.camera.setting = {\"direction\": [0, -1, 0]}\n", "viewer" ] } ], "metadata": { "kernelspec": { "display_name": "aiida", "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }