{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Disorder variable\n", "\n", "In this example, [disorder variable](random link) which was introduced to measure the disorder of a system is explored. We start by importing the necessary modules. We will use :mod:`~pyscal.crystal_structures` to create the necessary crystal structures." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pyscal as pc\n", "import pyscal.crystal_structures as pcs\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First an fcc structure with a lattice constant of 4.00 is created." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "fcc_atoms, fcc_box = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The created atoms and box are assigned to a :class:`~pyscal.core.System` object." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "fcc = pc.System()\n", "fcc.box = fcc_box\n", "fcc.atoms = fcc_atoms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next step is find the neighbors, and the calculate the Steinhardt parameter based on which we could calculate the disorder variable." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "fcc.find_neighbors(method='cutoff', cutoff='adaptive')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once the neighbors are found, we can calculate the Steinhardt parameter value. In this example $q=6$ will be used." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "fcc.calculate_q(6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, disorder parameter can be calculated." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "fcc.calculate_disorder()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The calculated disorder value can be accessed for each atom using the :attr:`~pyscal.catom.disorder` variable." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "atoms = fcc.atoms" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "disorder = [atom.disorder for atom in atoms]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-1.041556887034408e-16" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.mean(disorder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, for a perfect fcc structure, we can see that the disorder is zero. The variation of disorder variable on a distorted lattice can be explored now. We will once again use the `noise` keyword along with :func:`~pyscal.crystal_structures.make_crystal` to create a distorted lattice." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "fcc_atoms_d1, fcc_box_d1 = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4], noise=0.01)\n", "fcc_d1 = pc.System()\n", "fcc_d1.box = fcc_box_d1\n", "fcc_d1.atoms = fcc_atoms_d1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once again, find neighbors and then calculate disorder" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "fcc_d1.find_neighbors(method='cutoff', cutoff='adaptive')\n", "fcc_d1.calculate_q(6)\n", "fcc_d1.calculate_disorder()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check the value of disorder" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "atoms_d1 = fcc_d1.atoms" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "disorder = [atom.disorder for atom in atoms_d1]" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.00026650465454653035" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.mean(disorder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The value of average disorder for the system has increased with noise. Finally trying with a high amount of noise." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "fcc_atoms_d2, fcc_box_d2 = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4], noise=0.1)\n", "fcc_d2 = pc.System()\n", "fcc_d2.box = fcc_box_d2\n", "fcc_d2.atoms = fcc_atoms_d2" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "fcc_d2.find_neighbors(method='cutoff', cutoff='adaptive')\n", "fcc_d2.calculate_q(6)\n", "fcc_d2.calculate_disorder()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "atoms_d2 = fcc_d2.atoms" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.030475287944847596" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "disorder = [atom.disorder for atom in atoms_d2]\n", "np.mean(disorder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The value of disorder parameter shows an increase with the amount of lattice distortion. An averaged version of disorder parameter, averaged over the neighbors for each atom can also be calculated as shown below." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "fcc_d2.calculate_disorder(averaged=True)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.030373641570262584" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "atoms_d2 = fcc_d2.atoms\n", "disorder = [atom.avg_disorder for atom in atoms_d2]\n", "np.mean(disorder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The disorder parameter can also be calculated for values of Steinhardt parameter other than 6. For example," ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "fcc_d2.find_neighbors(method='cutoff', cutoff='adaptive')\n", "fcc_d2.calculate_q([4, 6])\n", "fcc_d2.calculate_disorder(q=4, averaged=True)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.11909705997413539" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "atoms_d2 = fcc_d2.atoms\n", "disorder = [atom.disorder for atom in atoms_d2]\n", "np.mean(disorder)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$q=4$, for example, can be useful when measuring disorder in bcc crystals" ] } ], "metadata": { "kernelspec": { "display_name": "pyscal-test", "language": "python", "name": "pyscal-test" }, "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.9.7" } }, "nbformat": 4, "nbformat_minor": 4 }