|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "8e09cccf-4335-4c59-bfa7-d3e3caeef404", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "from pymatgen.io.aims.inputs import AimsGeometryIn, AimsCube, AimsControlIn\n", |
| 11 | + "from pymatgen.io.aims.outputs import AimsOutput\n", |
| 12 | + "\n", |
| 13 | + "from pymatgen.core import Structure, Lattice\n", |
| 14 | + "\n", |
| 15 | + "import numpy as np\n", |
| 16 | + "\n", |
| 17 | + "from pathlib import Path\n", |
| 18 | + "from subprocess import check_call\n" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": null, |
| 24 | + "id": "536af143-f892-4549-86d7-ff426ba265ed", |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "# AIMS_CMD should be modified to match your system\n", |
| 29 | + "AIMS_CMD = \"aims.x\"\n", |
| 30 | + "AIMS_OUTPUT = \"aims.out\"\n", |
| 31 | + "AIMS_SD = \"species_dir\"\n", |
| 32 | + "AIMS_TEST_DIR = \"../../tests/io/aims/species_directory/light/\"\n" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "4d8d9fda-af37-45eb-971c-56fed59f3a27", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "# Create test structure\n", |
| 43 | + "structure = Structure(\n", |
| 44 | + " lattice=Lattice(\n", |
| 45 | + " np.array([[0, 2.715, 2.715],[2.715, 0, 2.715], [2.715, 2.715, 0]])\n", |
| 46 | + " ),\n", |
| 47 | + " species=[\"Si\", \"Si\"],\n", |
| 48 | + " coords=np.array([np.zeros(3), np.ones(3) * 0.25])\n", |
| 49 | + ")\n" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "id": "8e67e134-84f8-4c35-afe4-87cd66e2e781", |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "# Create the geometry file from the structure\n", |
| 60 | + "geo_in = AimsGeometryIn.from_structure(structure)\n", |
| 61 | + "\n", |
| 62 | + "# Create the control.in file\n", |
| 63 | + "cont_in = AimsControlIn(\n", |
| 64 | + " {\n", |
| 65 | + " \"xc\": \"pw-lda\",\n", |
| 66 | + " \"relax_geometry\": \"trm 0.01\",\n", |
| 67 | + " \"relax_unit_cell\": \"full\",\n", |
| 68 | + " \"species_dir\": AIMS_SD,\n", |
| 69 | + " }\n", |
| 70 | + ")\n", |
| 71 | + "\n", |
| 72 | + "# Add new parameters as if AimsControl\n", |
| 73 | + "cont_in[\"k_grid\"] = [1, 1, 1]\n", |
| 74 | + "\n", |
| 75 | + "# Output options to control in automatically append the list\n", |
| 76 | + "cont_in[\"output\"] = \"hirshfeld\"\n", |
| 77 | + "cont_in[\"output\"] = [\"eigenvectors\"]\n", |
| 78 | + "\n", |
| 79 | + "# Cube file output controlled by the AimsCube class\n", |
| 80 | + "cont_in[\"cubes\"] = [\n", |
| 81 | + " AimsCube(\"total_density\", origin=[0,0,0], points=[11, 11, 11]),\n", |
| 82 | + " AimsCube(\"eigenstate_density 1\", origin=[0, 0, 0], points=[11, 11, 11]),\n", |
| 83 | + "]\n" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": null, |
| 89 | + "id": "096337d6-871a-48dc-b4b3-a3c7c6fd812e", |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Write the input files\n", |
| 94 | + "workdir = Path.cwd() / \"workdir/\"\n", |
| 95 | + "workdir.mkdir(exist_ok=True)\n", |
| 96 | + "\n", |
| 97 | + "geo_in.write_file(workdir, overwrite=True)\n", |
| 98 | + "cont_in.write_file(structure, workdir, overwrite=True)\n" |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + "cell_type": "code", |
| 103 | + "execution_count": null, |
| 104 | + "id": "c9994cd2-5e45-4071-ab87-b6b3e3af1174", |
| 105 | + "metadata": {}, |
| 106 | + "outputs": [], |
| 107 | + "source": [ |
| 108 | + "# Run the calculation\n", |
| 109 | + "with open(f\"{workdir}/{AIMS_OUTPUT}\", \"w\") as outfile:\n", |
| 110 | + " aims_run = check_call([AIMS_CMD], cwd=workdir, stdout=outfile)\n" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": null, |
| 116 | + "id": "0c42a6c6-bb45-472f-a2cb-190cdd922047", |
| 117 | + "metadata": {}, |
| 118 | + "outputs": [], |
| 119 | + "source": [ |
| 120 | + "# Read the aims output file and the final relaxed geometry\n", |
| 121 | + "outputs = AimsOutput.from_outfile(f\"{workdir}/{AIMS_OUTPUT}\")\n", |
| 122 | + "relaxed_structure = AimsGeometryIn.from_file(f\"{workdir}/geometry.in.next_step\")\n", |
| 123 | + "\n", |
| 124 | + "# Check the results\n", |
| 125 | + "assert outputs.get_results_for_image(-1).lattice == relaxed_structure.structure.lattice\n", |
| 126 | + "assert np.all(outputs.get_results_for_image(-1).frac_coords == relaxed_structure.structure.frac_coords)\n", |
| 127 | + "\n", |
| 128 | + "assert np.allclose(\n", |
| 129 | + " outputs.get_results_for_image(-1).properties[\"stress\"],\n", |
| 130 | + " outputs.stress\n", |
| 131 | + ")\n", |
| 132 | + "\n", |
| 133 | + "assert np.allclose(\n", |
| 134 | + " outputs.get_results_for_image(-1).site_properties[\"force\"],\n", |
| 135 | + " outputs.forces\n", |
| 136 | + ")\n" |
| 137 | + ] |
| 138 | + } |
| 139 | + ], |
| 140 | + "metadata": { |
| 141 | + "kernelspec": { |
| 142 | + "display_name": "Python 3 (ipykernel)", |
| 143 | + "language": "python", |
| 144 | + "name": "python3" |
| 145 | + }, |
| 146 | + "language_info": { |
| 147 | + "codemirror_mode": { |
| 148 | + "name": "ipython", |
| 149 | + "version": 3 |
| 150 | + }, |
| 151 | + "file_extension": ".py", |
| 152 | + "mimetype": "text/x-python", |
| 153 | + "name": "python", |
| 154 | + "nbconvert_exporter": "python", |
| 155 | + "pygments_lexer": "ipython3", |
| 156 | + "version": "3.9.16" |
| 157 | + } |
| 158 | + }, |
| 159 | + "nbformat": 4, |
| 160 | + "nbformat_minor": 5 |
| 161 | +} |
0 commit comments