.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/2-structure_map.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_2-structure_map.py: Structure-property maps ======================= This example demonstrates the visualization of structures (or environments) using data-driven descriptors of their geometry, to cluster together similar motifs. Here the geometric descriptors have been computed by PCA starting from SOAP representations, but are provided as text files to avoid external dependencies for the example. The same parameters can be used with `chemiscope.show` to visualize an interactive widget in a Jupyter notebook. .. GENERATED FROM PYTHON SOURCE LINES 16-22 .. code-block:: Python import ase.io import numpy as np import chemiscope .. GENERATED FROM PYTHON SOURCE LINES 23-24 Load structures .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python frames = ase.io.read("data/trajectory.xyz", ":") .. GENERATED FROM PYTHON SOURCE LINES 28-31 Load the SOAP-PCA descriptors. chemiscope does not provide analysis routines, but you can look up for instance scikit-matter as a package to do dimensionality reduction analyses. .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python pca_atom = np.loadtxt("data/trajectory-pca_atom.dat") pca_structure = np.loadtxt("data/trajectory-pca_structure.dat") .. GENERATED FROM PYTHON SOURCE LINES 37-44 When both environments and structure property are present, a toggle allows you to switch between both modes. .. note:: if there are properties stored in the ASE frames, you can extract them with chemiscope.extract_properties(frames) .. GENERATED FROM PYTHON SOURCE LINES 45-60 .. code-block:: Python properties = { # concise definition of a property, with just an array and the type # inferred by the size "structure PCA": pca_structure, "atom PCA": pca_atom, # an example of the verbose definition "energy": { "target": "structure", "values": [frame.info["energy"] for frame in frames], "units": "eV", "description": "potential energy, computed with DFTB+", }, } .. GENERATED FROM PYTHON SOURCE LINES 61-62 Environment descriptors have only been computed for C and O atoms. .. GENERATED FROM PYTHON SOURCE LINES 63-71 .. code-block:: Python environments = [] cutoff = 4.0 for frame_i, frame in enumerate(frames): for atom_i, atom in enumerate(frame.numbers): if atom == 6 or atom == 8: environments.append((frame_i, atom_i, cutoff)) .. GENERATED FROM PYTHON SOURCE LINES 72-73 Create a visualization and save it as a file that can be viewed at chemiscope.org .. GENERATED FROM PYTHON SOURCE LINES 74-102 .. code-block:: Python chemiscope.write_input( "trajectory-pca.json.gz", # dataset metadata can also be included, to provide a self-contained description # of the data, authors and references meta={ "name": "Allyl alcohol PCA map", "description": ( "This dataset contains a PCA map of the C and O environments " "from a few frames out of a MD simulation of allyl alcohol, C3H5OH." ), "authors": ["The chemiscope developers"], "references": [ ( "G. Fraux, R. Cersonsky, and M. Ceriotti, " '"Chemiscope: interactive structure-property explorer for materials ' 'and molecules," JOSS 5(51), 2117 (2020).' ) ], }, frames=frames, properties=properties, environments=environments, settings={ # these are reasonable settings for trajectory visualization "structure": [{"keepOrientation": True, "playbackDelay": 100}] }, ) .. GENERATED FROM PYTHON SOURCE LINES 103-105 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 106-108 .. code-block:: Python chemiscope.show_input("trajectory-pca.json.gz") .. chemiscope:: _datasets/fig_2-structure_map_003.json.gz :mode: default .. raw:: html


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