{ "cells": [ { "cell_type": "markdown", "id": "cf85a76d", "metadata": {}, "source": [ "Color\n", "===============\n", "\n", "One can color the atoms using the following scheme:\n", "\n", "- Element\n", "- Random\n", "- Uniform\n", "- Index\n", "- Attribute\n", "\n", "\n", "Color by element\n", "----------------\n", "\n", "Supported style are:\n", "\n", "#. **JMOL**: http://jmol.sourceforge.net/jscolors/#color_U\n", "#. **VESTA**: https://jp-minerals.org/vesta/en/\n", "#. **CPK**: https://en.wikipedia.org/wiki/CPK_coloring\n", "\n", "\n", "Custom color for each species\n", "-----------------------------\n", "Use can set custom color for each species. The color can be in the form of hex code or color name.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a2a3a9a8", "metadata": {}, "outputs": [], "source": [ "from ase.build import molecule\n", "from weas_widget import WeasWidget\n", "\n", "atoms = molecule(\"C2H6SO\")\n", "viewer = WeasWidget()\n", "viewer.from_ase(atoms)\n", "# set the color and radius for each species\n", "viewer.avr.species.settings[\"C\"].update({\"color\": \"red\", \"radius\": 1.0})\n", "viewer.avr.species.settings[\"H\"].update({\"color\": \"green\", \"radius\": 0.5})\n", "viewer.avr.species.settings[\"O\"].update({\"color\": \"blue\", \"radius\": 0.6})\n", "viewer.avr.species.settings[\"S\"].update({\"color\": \"yellow\", \"radius\": 1.2})\n", "viewer" ] }, { "cell_type": "markdown", "id": "65780aa5", "metadata": {}, "source": [ "\n", "Color by attribute\n", "----------------------\n", "Coloring based on the attribute of the atoms. The attribute can be: charge, magmom, or any other attribute in the structure.\n", "\n", "Here we show how to color the atoms by their forces." ] }, { "cell_type": "code", "execution_count": null, "id": "bf6bb43e", "metadata": {}, "outputs": [], "source": [ "from ase.build import bulk\n", "from ase.calculators.emt import EMT\n", "import numpy as np\n", "from weas_widget import WeasWidget\n", "atoms = bulk('Au', cubic = True)\n", "atoms *= [3, 3, 3]\n", "atoms.positions += np.random.random((len(atoms), 3))\n", "atoms.calc = EMT()\n", "atoms.get_potential_energy()\n", "# set the forces as an attribute\n", "atoms.set_array(\"Force\", atoms.calc.results[\"forces\"])\n", "viewer = WeasWidget()\n", "viewer.from_ase(atoms)\n", "viewer.avr.color_by = \"Force\"\n", "viewer.avr.color_ramp = [\"red\", \"yellow\", \"blue\"]\n", "viewer.avr.model_style = 1\n", "viewer\n" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }