Skip to content

Commit

Permalink
FHI-aims IO Parsers (#3435)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
tpurcell90 and janosh authored Nov 8, 2023
1 parent 52d6b8c commit d4e253d
Show file tree
Hide file tree
Showing 29 changed files with 3,100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ repos:
# MD041: first line in a file should be a top-level heading
# MD025: single title
args: [--disable, MD013, MD024, MD025, MD033, MD041, "--"]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]
161 changes: 161 additions & 0 deletions examples/aims_io/FHI-aims-example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "8e09cccf-4335-4c59-bfa7-d3e3caeef404",
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.io.aims.inputs import AimsGeometryIn, AimsCube, AimsControlIn\n",
"from pymatgen.io.aims.outputs import AimsOutput\n",
"\n",
"from pymatgen.core import Structure, Lattice\n",
"\n",
"import numpy as np\n",
"\n",
"from pathlib import Path\n",
"from subprocess import check_call\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "536af143-f892-4549-86d7-ff426ba265ed",
"metadata": {},
"outputs": [],
"source": [
"# AIMS_CMD should be modified to match your system\n",
"AIMS_CMD = \"aims.x\"\n",
"AIMS_OUTPUT = \"aims.out\"\n",
"AIMS_SD = \"species_dir\"\n",
"AIMS_TEST_DIR = \"../../tests/io/aims/species_directory/light/\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d8d9fda-af37-45eb-971c-56fed59f3a27",
"metadata": {},
"outputs": [],
"source": [
"# Create test structure\n",
"structure = Structure(\n",
" lattice=Lattice(\n",
" np.array([[0, 2.715, 2.715],[2.715, 0, 2.715], [2.715, 2.715, 0]])\n",
" ),\n",
" species=[\"Si\", \"Si\"],\n",
" coords=np.array([np.zeros(3), np.ones(3) * 0.25])\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e67e134-84f8-4c35-afe4-87cd66e2e781",
"metadata": {},
"outputs": [],
"source": [
"# Create the geometry file from the structure\n",
"geo_in = AimsGeometryIn.from_structure(structure)\n",
"\n",
"# Create the control.in file\n",
"cont_in = AimsControlIn(\n",
" {\n",
" \"xc\": \"pw-lda\",\n",
" \"relax_geometry\": \"trm 0.01\",\n",
" \"relax_unit_cell\": \"full\",\n",
" \"species_dir\": AIMS_SD,\n",
" }\n",
")\n",
"\n",
"# Add new parameters as if AimsControl\n",
"cont_in[\"k_grid\"] = [1, 1, 1]\n",
"\n",
"# Output options to control in automatically append the list\n",
"cont_in[\"output\"] = \"hirshfeld\"\n",
"cont_in[\"output\"] = [\"eigenvectors\"]\n",
"\n",
"# Cube file output controlled by the AimsCube class\n",
"cont_in[\"cubes\"] = [\n",
" AimsCube(\"total_density\", origin=[0,0,0], points=[11, 11, 11]),\n",
" AimsCube(\"eigenstate_density 1\", origin=[0, 0, 0], points=[11, 11, 11]),\n",
"]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "096337d6-871a-48dc-b4b3-a3c7c6fd812e",
"metadata": {},
"outputs": [],
"source": [
"# Write the input files\n",
"workdir = Path.cwd() / \"workdir/\"\n",
"workdir.mkdir(exist_ok=True)\n",
"\n",
"geo_in.write_file(workdir, overwrite=True)\n",
"cont_in.write_file(structure, workdir, overwrite=True)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9994cd2-5e45-4071-ab87-b6b3e3af1174",
"metadata": {},
"outputs": [],
"source": [
"# Run the calculation\n",
"with open(f\"{workdir}/{AIMS_OUTPUT}\", \"w\") as outfile:\n",
" aims_run = check_call([AIMS_CMD], cwd=workdir, stdout=outfile)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c42a6c6-bb45-472f-a2cb-190cdd922047",
"metadata": {},
"outputs": [],
"source": [
"# Read the aims output file and the final relaxed geometry\n",
"outputs = AimsOutput.from_outfile(f\"{workdir}/{AIMS_OUTPUT}\")\n",
"relaxed_structure = AimsGeometryIn.from_file(f\"{workdir}/geometry.in.next_step\")\n",
"\n",
"# Check the results\n",
"assert outputs.get_results_for_image(-1).lattice == relaxed_structure.structure.lattice\n",
"assert np.all(outputs.get_results_for_image(-1).frac_coords == relaxed_structure.structure.frac_coords)\n",
"\n",
"assert np.allclose(\n",
" outputs.get_results_for_image(-1).properties[\"stress\"],\n",
" outputs.stress\n",
")\n",
"\n",
"assert np.allclose(\n",
" outputs.get_results_for_image(-1).site_properties[\"force\"],\n",
" outputs.forces\n",
")\n"
]
}
],
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions pymatgen/io/aims/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""IO interface for FHI-aims."""
Loading

0 comments on commit d4e253d

Please sign in to comment.