Skip to content

Commit d4e253d

Browse files
tpurcell90janosh
andauthored
FHI-aims IO Parsers (#3435)
* Move FHI-aims io from atomate2 into pymatgen 1) parsers and AimsOuput ojbects moved over 2) All ASE Atoms objects removed in favor of pymatgen structures 3) TO DO: Check name schemes 4) Create an AimsInputs object in the future * Initial aims input files 1) remove aims_outputs naming convention 2) Add AimsGeometryIn and AimsControlIn classes * Add test for the aims parsers Adjusted from ASE parser tests * Add tests for AimsOutputs 1) How to handle stress in properties? * Add aims output refrence files For aims outputs checks * Add tests for AimsGeometryIn inputs Test for both Si and H2O * Add tests for AimsCube Make sure that the AimsCubes are properly formatted * Add tests for aims_control_in Add test for aims control.in file generators * gzip all output files as requested all output files are gzipped * Gzip all refrence files 1) Species blocks can now read from gzipped file 2) geometry.in can now read a gzip file * Remove json dict comparision Error in the Actions from rounding errors, do more explicit test for as_dict * Add full type hinting for inputs.py and convert docstrings 1) Docstrings are googledoc format 2) All type hinting is done * Convert all AimsOutput docstrings to google doc Everything is also type hintted now * Add type hining and google doc strings to parsers * Fix tests Forgot pip install in the last commit * Requested changes to tests 1) Moved lines objects to seperate files 2) inline k_point_weights 3) Remove trailing comma 4) tmpdir -> tmp_path * Update pymatgen/io/aims/inputs.py use numpy eye instead of a full list Co-authored-by: Janosh Riebesell <[email protected]> Signed-off-by: Thomas Purcell <[email protected]> * pre-commit auto-fixes * Make more changes requested * Rename io.aims.output to io.aims.outputs Keep it consistent with inputs naming scheme * Add example for FHI-aims io * Make corrections suggested by @janosh 1) Remove copy of species file in examples 2) Typo corrections in docstrings 3) d -> dct for `from_dict` methods 4) error mesages for AimsCube 5) Shortened default checks in Inputs 6) Removal of chdir in tests * add nbstripout to pre-commit hooks apply to FHI-aims-example.ipynb * class AimsCube snake_case spin_state * fix doc str * refactor AimsCube.from_dict * fix typo * fix tests * mv tests/io/aims/(aims_->'')input_files tests/io/aims/(aims_->'')output_files tests/io/aims/(aims_->'')parser_checks * Correct refrence json files for aims_outputs aims.output -> aims.outputs module name --------- Signed-off-by: Thomas Purcell <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 52d6b8c commit d4e253d

29 files changed

+3100
-0
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ repos:
5656
# MD041: first line in a file should be a top-level heading
5757
# MD025: single title
5858
args: [--disable, MD013, MD024, MD025, MD033, MD041, "--"]
59+
60+
- repo: https://github.com/kynan/nbstripout
61+
rev: 0.6.1
62+
hooks:
63+
- id: nbstripout
64+
args: [--drop-empty-cells, --keep-output]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
}

pymatgen/io/aims/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""IO interface for FHI-aims."""

0 commit comments

Comments
 (0)