.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/4-colors.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_4-colors.py: Atom property coloring ====================== This example demonstrates how to color atoms based on scalar properties. Note that the same parameters can be used with `chemiscope.show` to visualize an interactive widget in a Jupyter notebook. .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. code-block:: Python import ase.io import numpy as np import chemiscope .. GENERATED FROM PYTHON SOURCE LINES 20-21 Load a dataset of structures containing polarizability and dipole data .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python frames = ase.io.read("data/alpha-mu.xyz", ":") .. GENERATED FROM PYTHON SOURCE LINES 26-27 Compute some scalar quantities to display as atom coloring .. GENERATED FROM PYTHON SOURCE LINES 28-54 .. code-block:: Python polarizability = [] alpha_eigenvalues = [] anisotropy = [] for frame in frames: # center molecule in the box frame.positions += frame.cell.diagonal() * 0.5 for axx, ayy, azz, axy, axz, ayz in zip( frame.arrays["axx"], frame.arrays["ayy"], frame.arrays["azz"], frame.arrays["axy"], frame.arrays["axz"], frame.arrays["ayz"], ): polarizability.append((axx + ayy + azz) / 3) # one possible measure of anisotropy... eigenvalues = np.linalg.eigvalsh( [[axx, axy, axz], [axy, ayy, ayz], [axz, ayz, azz]] ) alpha_eigenvalues.append(eigenvalues) anisotropy.append(eigenvalues[2] - eigenvalues[0]) .. GENERATED FROM PYTHON SOURCE LINES 55-56 Create a visualization and save it as a file that can be viewed at chemiscope.org .. GENERATED FROM PYTHON SOURCE LINES 57-87 .. code-block:: Python chemiscope.write_input( "colors-example.json.gz", frames=frames, # properties can also be extracted from the ASE.Atoms frames properties={ "polarizability": np.vstack(polarizability), "anisotropy": np.vstack(anisotropy), "alpha_eigenvalues": np.vstack(alpha_eigenvalues), }, # it is also possible to define the default visualization settings settings={ "map": { "x": {"property": "alpha_eigenvalues[1]"}, "y": {"property": "alpha_eigenvalues[2]"}, "z": {"property": "alpha_eigenvalues[3]"}, "color": {"property": "anisotropy"}, }, "structure": [ { "color": {"property": "anisotropy"}, } ], }, # the properties we want to visualise are atomic properties - in order to view them # in map panel we must indicate the list of environments (all atoms in this case) environments=chemiscope.all_atomic_environments(frames), ) .. GENERATED FROM PYTHON SOURCE LINES 88-90 The file can also be viewed in a notebook. Use `chemiscope.show` above to bypass the creation of a JSON file and directly create a viewer. .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. code-block:: Python chemiscope.show_input("colors-example.json.gz") .. chemiscope:: _datasets/fig_4-colors_005.json.gz :mode: default .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.008 seconds) .. _sphx_glr_download_examples_4-colors.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 4-colors.ipynb <4-colors.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 4-colors.py <4-colors.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 4-colors.zip <4-colors.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_