{ "cells": [ { "cell_type": "markdown", "id": "8b00fbd5", "metadata": {}, "source": [ "# Auxiliary Modules\n", "\n", "You can download source files to follow this tutorial from this [link](https://drive.google.com/file/d/1_gMT74f_1PqxQ8Um1-y_i11Y2tKg7-3f/view?usp=drivesdk) (26 GB).\n", "\n", "```{note}\n", "This is the same example set used in the **Hopping Parameter Extraction** or **Mean Square Displacement** section in `CLI Tutorial` documentation, or the **Hopping Parameter Extraction** section in `API Tutorial` documentation. If you have already completed that tutorial, you do not need to download the files again.\n", "```\n", "\n", "----\n", "\n", "This tutorial provides a brief overview of `VacHopPy`'s auxiliary modules. For more detailed information on each module and its parameters, please consult the `API Reference` documentation.\n", "\n", "First, navigate to the `Example3` directory you downloaded. For this tutorial, we will only use the `TRAJ_TiO2` directory and the `POSCAR_TiO2` file; other files in the directory can be ignored." ] }, { "cell_type": "code", "execution_count": 3, "id": "e030d1e4", "metadata": {}, "outputs": [], "source": [ "import os\n", "from vachoppy.core import Site\n", "\n", "path_traj = 'TRAJ_TiO2'\n", "path_structure = 'POSCAR_TiO2'\n", "if not os.path.exists(path_traj): print(f\"{path_traj} not found.\")\n", "if not os.path.exists(path_structure): print(f\"{path_structure} not found.\")" ] }, { "cell_type": "markdown", "id": "ae5ffffa", "metadata": {}, "source": [ "First, we'll create an instance of the `Site` class. This object will analyze the perfect structure to define the lattice framework for our analysis." ] }, { "cell_type": "code", "execution_count": 4, "id": "77f0fe8e", "metadata": {}, "outputs": [], "source": [ "site = Site(path_structure, 'O')" ] }, { "cell_type": "markdown", "id": "9b4cb238", "metadata": {}, "source": [ "---\n", "## The `Vibration` Module\n", "\n", "The `Vibration` module is dedicated to calculating the **atomic vibration frequency ($\\nu^*$)** from trajectory data. Unlike the `Calculator` function, this module is designed to operate on a **single HDF5 trajectory file**.\n", "\n", "Let's instantiate the `Vibration` class, providing it with the path to a single trajectory file and our pre-defined `site` object." ] }, { "cell_type": "code", "execution_count": 7, "id": "c6d37edb", "metadata": {}, "outputs": [], "source": [ "from vachoppy.vibration import Vibration\n", "\n", "path_traj_single = os.path.join(path_traj, 'TRAJ_2100K', 'TRAJ_O_01.h5')\n", "vib = Vibration(path_traj_single, site)" ] }, { "cell_type": "markdown", "id": "2dbcfbf9", "metadata": {}, "source": [ "To run the analysis, simply call the `.calculate()` method. This will perform the frequency calculation and print a summary of the results directly to the console." ] }, { "cell_type": "code", "execution_count": 11, "id": "3a2b8e9a", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6f2065981548428b9b1ec245db0c139c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Compute Displacement: 0%| | 0/47 [00:00\n", "\n", " \"Image\"\n", "\n" ] }, { "cell_type": "markdown", "id": "e201c681", "metadata": {}, "source": [ "---\n", "\n", "## The `Einstein` Module\n", "\n", "The `Einstein` module is used to calculate the **atomic diffusivity** by analyzing the **mean squared displacement (MSD)** of atoms and applying the **Einstein relation**.\n", "\n", "While the `Calculator()` focuses on the discrete hopping events of vacancies, the `Einstein` module tracks the continuous, long-range movement of the **atoms** themselves. A key distinction is that the diffusivity calculated here inherently includes correlation effects. Consequently, the activation energy derived from this analysis represents the **effective diffusion barrier**, not the **effective hopping barrier**.\n", "\n", "Similar to the `Calculator()`, the `Einstein` class can accept either a path to a single HDF5 file or a directory containing a bundle of files." ] }, { "cell_type": "code", "execution_count": 22, "id": "5a7bf42a", "metadata": {}, "outputs": [], "source": [ "from vachoppy.einstein import Einstein\n", "\n", "# For a bundle of trajectories\n", "einstein_bundle = Einstein(path_traj, 'O')\n", "\n", "# For a single trajectory file\n", "einstein_single = Einstein(path_traj_single, 'O')" ] }, { "cell_type": "markdown", "id": "53c4490d", "metadata": {}, "source": [ "The analysis is performed by calling the `.calculate()` method. \n", "\n", "When provided with a single HDF5 file, the module calculates the MSD and determines the diffusivity for that specific temperature. You can view these results using the `.summary()` method." ] }, { "cell_type": "code", "execution_count": 23, "id": "9a2419d7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "============================================================\n", " MSD Analysis Summary (Single)\n", "============================================================\n", "\n", "-- Input Parameters --\n", " - Trajectory File : TRAJ_O_01.h5\n", " - Target Symbol : O\n", " - Temperature : 2100.0 K\n", " - Skip Time : 0.00 ps\n", " - Segment Length : Full\n", "\n", "-- Fitting Range --\n", " - Start Time : 1.00 ps\n", " - End Time : 151.00 ps\n", "\n", "-- Results --\n", " - Diffusivity (D) : 2.070e-11 m^2/s\n", "============================================================\n", "\n" ] } ], "source": [ "einstein_single.calculate()\n", "einstein_single.summary()" ] }, { "cell_type": "markdown", "id": "4e09dda5", "metadata": {}, "source": [ "To visualize the underlying data, you can generate a plot of MSD vs. time using the `.plot_msd()` method." ] }, { "cell_type": "code", "execution_count": null, "id": "1584bdeb", "metadata": {}, "outputs": [], "source": [ "einstein_single.plot_msd()" ] }, { "cell_type": "markdown", "id": "272f8bb1", "metadata": {}, "source": [ "Example output:\n", "\n", "
\n", "\n", " \"Image\"\n", "
\n" ] }, { "cell_type": "markdown", "id": "334a29b5", "metadata": {}, "source": [ "When provided with a **bundle of HDF5 files from different temperatures**, the `Einstein` module automatically performs an Arrhenius fit to calculate the **pre-exponential factor** and the **diffusion barrier**.Let's run the calculation on the `einstein_bundle` object we created earlier and inspect the summary." ] }, { "cell_type": "code", "execution_count": 25, "id": "ebcb8595", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4b1c2fe8dfbe4ca2ac06c17838bee90c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Compute MSD: 0%| | 0/100 [00:00\n", "\n", " \"Image\"\n", "\n" ] }, { "cell_type": "markdown", "id": "4786426e", "metadata": {}, "source": [ "Similarly, the `.plot_msd()` method can be used to plot the MSD vs. time curves for all trajectories, grouped by temperature." ] }, { "cell_type": "code", "execution_count": null, "id": "e9f15a11", "metadata": {}, "outputs": [], "source": [ "einstein_bundle.plot_msd()" ] }, { "cell_type": "markdown", "id": "bd200ed8", "metadata": {}, "source": [ "Example output:\n", "\n", "
\n", "\n", " \"Image\"\n", "
\n" ] } ], "metadata": { "kernelspec": { "display_name": "vhp_ver3", "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.10.18" } }, "nbformat": 4, "nbformat_minor": 5 }