{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Advanced Tutorial\n", "\n", "This tutorial shows some more advanced features of the Data types presented in the [previous tutorial](./intermidiate.ipynb).\n", "\n", "## Working with custom atomic names\n", "\n", "Many quantum codes, and AiiDA itself, allow for defining custom atomic names. This can be usefull when defining some extra features, such as magnetic ordering or on-site Hubbard values. Nevertheless, `Phonopy` is not handling such cases, and this could be a bottleneck for the usage of the package in AiiDA. In `aiida-phonopy`, we manage to overcome this problem! Let's see how does it work!\n", "\n", "### A structure with kinds\n", "\n", "Let's define a very simple structure that contains two atoms of the same species. Let's take cubic silicon!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from local_module import load_temp_profile\n", "from aiida.plugins import DataFactory\n", "# If you download this file, you can run it with your own profile.\n", "# Put these lines instead:\n", "# from aiida import load_profile\n", "# load_profile()\n", "load_temp_profile(name=\"advanced-tutorial\")\n", "\n", "StructureData = DataFactory(\"core.structure\")\n", "\n", "a = 2.716\n", "cell = [[0,a,a],[a,0,a],[a,a,0]]\n", "\n", "structure = StructureData(cell=cell)\n", "structure.append_atom(position=(a,a,a), symbols=\"Si\", name=\"Si1\")\n", "structure.append_atom(position=(1.5*a,1.5*a,1.5*a), symbols=\"Si\", name=\"Si2\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Now we can pass load it in the {py:class}`aiida_phonopy.data.preprocess.PreProcessData` with a supercell matrix of (2,2,2). Let's see if the supercell has the correct kinds." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PreProcessData = DataFactory(\"phonopy.preprocess\")\n", "\n", "preprocess_data = PreProcessData(structure=structure, supercell_matrix=[2,2,2])\n", "\n", "supercell = preprocess_data.get_supercell()\n", "supercell.sites" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Great! The supercell structure has the correct _kind names_.\n", "\n", "If we have a look at the number of structure with displacements, we will notice they will be higher than the silicon structure with only chemical symbols." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of displacements: 2\n" ] } ], "source": [ "supercells = preprocess_data.get_supercells_with_displacements()\n", "print(f\"Number of displacements: {len(supercells)}\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "This may or may not be a wanted behaviour. If you want `Phonopy` to not distinguish atoms on their _name_, you can initialize the `PreProcessData` with the flag `distinguish_kinds = False`, as follows:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now the number of displacements are: 1\n" ] } ], "source": [ "preprocess_data = PreProcessData(structure, supercell_matrix=[2,2,2], distinguish_kinds=False)\n", "supercells = preprocess_data.get_supercells_with_displacements()\n", "print(f\"Now the number of displacements are: {len(supercells)}\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "```{admonition} Exercise\n", ":class: tip\n", "Verify that the supercell still have the same _kind names_.\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.8.10" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d4d1e4263499bec80672ea0156c357c1ee493ec2b1c70f0acce89fc37c4a6abe" } } }, "nbformat": 4, "nbformat_minor": 2 }