|
7 | 7 | "metadata": {},
|
8 | 8 | "outputs": [],
|
9 | 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", |
| 10 | + "from pathlib import Path\n", |
| 11 | + "from subprocess import check_call\n", |
14 | 12 | "\n",
|
15 | 13 | "import numpy as np\n",
|
| 14 | + "from numpy.testing import assert_allclose\n", |
16 | 15 | "\n",
|
17 |
| - "from pathlib import Path\n", |
18 |
| - "from subprocess import check_call\n" |
| 16 | + "from pymatgen.core import Lattice, Structure\n", |
| 17 | + "from pymatgen.io.aims.inputs import AimsControlIn, AimsCube, AimsGeometryIn\n", |
| 18 | + "from pymatgen.io.aims.outputs import AimsOutput" |
19 | 19 | ]
|
20 | 20 | },
|
21 | 21 | {
|
|
29 | 29 | "AIMS_CMD = \"aims.x\"\n",
|
30 | 30 | "AIMS_OUTPUT = \"aims.out\"\n",
|
31 | 31 | "AIMS_SD = \"species_dir\"\n",
|
32 |
| - "AIMS_TEST_DIR = \"../../tests/io/aims/species_directory/light/\"\n" |
| 32 | + "AIMS_TEST_DIR = \"../../tests/io/aims/species_directory/light/\"" |
33 | 33 | ]
|
34 | 34 | },
|
35 | 35 | {
|
|
41 | 41 | "source": [
|
42 | 42 | "# Create test structure\n",
|
43 | 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", |
| 44 | + " lattice=Lattice(np.array([[0, 2.715, 2.715], [2.715, 0, 2.715], [2.715, 2.715, 0]])),\n", |
47 | 45 | " species=[\"Si\", \"Si\"],\n",
|
48 |
| - " coords=np.array([np.zeros(3), np.ones(3) * 0.25])\n", |
49 |
| - ")\n" |
| 46 | + " coords=np.array([np.zeros(3), np.ones(3) * 0.25]),\n", |
| 47 | + ")" |
50 | 48 | ]
|
51 | 49 | },
|
52 | 50 | {
|
|
78 | 76 | "\n",
|
79 | 77 | "# Cube file output controlled by the AimsCube class\n",
|
80 | 78 | "cont_in[\"cubes\"] = [\n",
|
81 |
| - " AimsCube(\"total_density\", origin=[0,0,0], points=[11, 11, 11]),\n", |
| 79 | + " AimsCube(\"total_density\", origin=[0, 0, 0], points=[11, 11, 11]),\n", |
82 | 80 | " AimsCube(\"eigenstate_density 1\", origin=[0, 0, 0], points=[11, 11, 11]),\n",
|
83 |
| - "]\n" |
| 81 | + "]" |
84 | 82 | ]
|
85 | 83 | },
|
86 | 84 | {
|
|
91 | 89 | "outputs": [],
|
92 | 90 | "source": [
|
93 | 91 | "# Write the input files\n",
|
94 |
| - "workdir = Path.cwd() / \"workdir/\"\n", |
95 |
| - "workdir.mkdir(exist_ok=True)\n", |
| 92 | + "work_dir = Path.cwd() / \"workdir/\"\n", |
| 93 | + "work_dir.mkdir(exist_ok=True)\n", |
96 | 94 | "\n",
|
97 |
| - "geo_in.write_file(workdir, overwrite=True)\n", |
98 |
| - "cont_in.write_file(structure, workdir, overwrite=True)\n" |
| 95 | + "geo_in.write_file(work_dir, overwrite=True)\n", |
| 96 | + "cont_in.write_file(structure, work_dir, overwrite=True)" |
99 | 97 | ]
|
100 | 98 | },
|
101 | 99 | {
|
|
106 | 104 | "outputs": [],
|
107 | 105 | "source": [
|
108 | 106 | "# 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" |
| 107 | + "with open(f\"{work_dir}/{AIMS_OUTPUT}\", \"w\") as outfile:\n", |
| 108 | + " aims_run = check_call([AIMS_CMD], cwd=work_dir, stdout=outfile)" |
111 | 109 | ]
|
112 | 110 | },
|
113 | 111 | {
|
|
118 | 116 | "outputs": [],
|
119 | 117 | "source": [
|
120 | 118 | "# 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", |
| 119 | + "outputs = AimsOutput.from_outfile(f\"{work_dir}/{AIMS_OUTPUT}\")\n", |
| 120 | + "relaxed_structure = AimsGeometryIn.from_file(f\"{work_dir}/geometry.in.next_step\")\n", |
123 | 121 | "\n",
|
124 | 122 | "# Check the results\n",
|
125 | 123 | "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" |
| 124 | + "assert_allclose(outputs.get_results_for_image(-1).frac_coords, relaxed_structure.structure.frac_coords)\n", |
| 125 | + "assert_allclose(outputs.get_results_for_image(-1).properties[\"stress\"], outputs.stress)\n", |
| 126 | + "assert_allclose(outputs.get_results_for_image(-1).site_properties[\"force\"], outputs.forces)" |
137 | 127 | ]
|
138 | 128 | }
|
139 | 129 | ],
|
|
153 | 143 | "name": "python",
|
154 | 144 | "nbconvert_exporter": "python",
|
155 | 145 | "pygments_lexer": "ipython3",
|
156 |
| - "version": "3.9.16" |
| 146 | + "version": "3.11.7" |
157 | 147 | }
|
158 | 148 | },
|
159 | 149 | "nbformat": 4,
|
|
0 commit comments