{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Using OpenKIM models with ASE\n", "\n", "This example demonstrates using an OpenKIM model installed on your system for an ASE calculation, specifically a static energy calculation of FCC Aluminum using the famous 1994 Ercolessi-Adams EAM potential. The [KIM query](https://openkim.org/doc/usage/kim-query/) Python module is used to obtain the lattice constant used for the simulation." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "This is what the calculation would look like without OpenKIM. The user is required to specify the lattice constant and obtain their own parameter file:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ase.calculators.eam import EAM\n", "from ase.lattice.cubic import FaceCenteredCubic\n", "# Define the user-obtained parameter file and lattice constant\n", "model = \"potentials/v2_18_Al3Sm_2016.eam.fs\"\n", "calc = EAM(potential=model)\n", "a0 = 4.05\n", "# Set up fcc crystal\n", "atoms = FaceCenteredCubic(\"Al\", latticeconstant=a0)\n", "atoms.calc = calc\n", "# Compute energy and stress\n", "print(\"\\nPotential energy:\")\n", "print(atoms.get_potential_energy())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below is the same calculation using OpenKIM. The kim_query Python module is used to automatically obtain the lattice constant." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ase.calculators.kim import KIM\n", "from ase.lattice.cubic import FaceCenteredCubic\n", "from kim_query import get_lattice_constant_cubic\n", "# Define KIM model and get Al fcc lattice parameter for this potential\n", "model = \"EAM_Dynamo_SongMendelev_2021_AlSm__MO_722733117926_000\"\n", "calc = KIM(model)\n", "a0 = get_lattice_constant_cubic([model], [\"fcc\"], [\"Al\"], [\"angstrom\"])[0]\n", "# Set up fcc crystal\n", "atoms = FaceCenteredCubic(\"Al\", latticeconstant=a0)\n", "atoms.calc = calc\n", "# Compute energy and stress\n", "print(\"\\nPotential energy:\")\n", "print(atoms.get_potential_energy())" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The energy is nearly identical, but slightly lower due to the lattice constant being the perfect equilibrium value. See the [KIM calculator in ASE documentation](https://wiki.fysik.dtu.dk/ase/ase/calculators/kim.html) for more info." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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" } }, "nbformat": 4, "nbformat_minor": 4 }