{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Phonopy and ASE Tutorial\n", "\n", "In this tutorial you will learn how to run an automated calculation of phonons by calculating the forces using ASE.\n", "\n", "We will use the `aiida_phonopy.workflows.ase.PhonopyAseWorkChain`, which is based on `aiida_pythonjob`.\n", "This workflow takes care of: \n", "\n", "* Pre-processing: generating the (supercell) structures with displacements on top of which computing forces (for frozen phonons)\n", "* Gather all information in `PhonopyData`, ready to be post-processed \n", "* (optional) Post-process: calculate phonon-related properties, such as phonon band structure and (P)DOS, thermal properties, and so on by using `PhonopyCalculation`.\n", "\n", "In this tutorial we will make use of the silicon structure to give you an overall understanding of the usage.\n", "\n", "Let's get started!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from local_module import load_temp_profile\n", "from aiida.plugins import DataFactory, WorkflowFactory\n", "\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(\n", " name=\"ase-tutorial\",\n", " add_computer=True,\n", " add_phonopy_code=True,\n", ")\n", "\n", "StructureData = DataFactory(\"core.structure\")\n", "PhonopyAseWorkChain = WorkflowFactory(\"phonopy.ase\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Let's define the alumin structure using the ASE module" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ase.build import bulk\n", "\n", "atoms = bulk(\"Al\", a=1.5456658) # Note: this is NOT the experimental lattice constant, but the good value for the force field used in the tutorial\n", "structure = StructureData(ase=atoms)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{code-block} python\n", ":caption: |\n", ": If you have your own structure, e.g., \n", ": in .cif or .xyz format, you can simply use the followig snippet\n", "\n", "from ase.io import read\n", "\n", "atoms = read(\"/path/to/file.cif\") # here, any format supported by ASE\n", "structure = StructureData(ase=atoms)\n", "```\n", "\n", "## Automated calculation via `PhonopyAseWorkChain`\n", "\n", "We now want to choose an ASE `calculator` that we want to give to the workchain, so that it will compute with it all the forces on all the displaced structures. The calculation will be performed automatically by the `PhonopyAseWorkChain`, which will give us a `PhonopyData` as output that stores all the displacements and forces needed to compute phonons-related properties.\n", "\n", "The calculator can be:\n", "- a simple empirical forces field, like a Lenard-Jones potential (presented in this example)\n", "- a DFT calculator (e.g., Quantum ESPRESSO, VASP, Abinit, and so on, interfaced by ASE)\n", "- a pre-trained machine-learning potential (e.g., NequIP, Allegro, MACE, MatterSim, GAP, FLARE, and so on, interfaced with ASE)\n", "\n", "These should be installed and able to run on your machine or on a remote cluster." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ase.calculators.lj import LennardJones\n", "from aiida.orm import Dict, load_code\n", "from aiida.engine import run_get_node\n", "\n", "inputs = PhonopyAseWorkChain.get_populated_builder(\n", " structure=structure,\n", " calculator=LennardJones(),\n", " max_number_of_atoms=200,\n", " pythonjob_inputs={\"computer\": \"local_direct\"},\n", " phonopy_inputs={\n", " \"code\": load_code(\"phonopy@local_direct\"),\n", " \"parameters\": Dict({\"band\":\"auto\"})\n", " },\n", ")\n", "\n", "results, node = run_get_node(PhonopyAseWorkChain, **inputs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results['output_phonopy']['phonon_bands'].show_mpl()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Manual post-processing\n", "\n", "You can still of course use the output `PhonopyData` to get a `Phonopy` instance, allowing you to directly post-process the data locally." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ph = node.outputs.phonopy_data.get_phonopy_instance()\n", "ph.produce_force_constants()\n", "ph.auto_band_structure(plot=True)" ] } ], "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.10.18" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d4d1e4263499bec80672ea0156c357c1ee493ec2b1c70f0acce89fc37c4a6abe" } } }, "nbformat": 4, "nbformat_minor": 2 }