Skip to content

Commit

Permalink
Aims bug fixes (#3466)
Browse files Browse the repository at this point in the history
* Add default species dir option for inputs

Restore the use of an environment variable to set the
aims species directory

* Fix errors in parsers

1) Remove the filter for deciding if line is in a header or calc chunk
   Done since some lines appear in both
2) Remove stray call to an atoms object made from the atomate2 parsers

Modify the AimsOutput test for Si to use phonon calc file and not a relaxation
to check part 2

* Fix error to use f-strings

had an fstring but did not specify it was

* Add header information to all source files

Add myself and @ansobolev as authors

* Reduce test of default species dir

No need to retest everything, just the one functionality
  • Loading branch information
tpurcell90 authored Nov 9, 2023
1 parent 605757f commit 77a92bd
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 5 deletions.
11 changes: 9 additions & 2 deletions pymatgen/io/aims/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import gzip
import os
import time
from copy import deepcopy
from dataclasses import dataclass, field
Expand All @@ -20,6 +21,11 @@
if TYPE_CHECKING:
from collections.abc import Sequence

__author__ = "Thomas A. R. Purcell"
__version__ = "1.0"
__email__ = "[email protected]"
__date__ = "November 2023"


@dataclass
class AimsGeometryIn(MSONable):
Expand Down Expand Up @@ -566,7 +572,8 @@ def write_file(
fd.write(cube.control_block)

fd.write(lim + "\n\n")
fd.write(self.get_species_block(structure, self._parameters["species_dir"]))
species_dir = self._parameters.get("species_dir", os.environ.get("AIMS_SPECIES_DIR"))
fd.write(self.get_species_block(structure, species_dir))

def get_species_block(self, structure: Structure | Molecule, species_dir: str | Path) -> str:
"""Get the basis set information for a structure
Expand All @@ -592,7 +599,7 @@ def get_species_block(self, structure: Structure | Molecule, species_dir: str |
with gzip.open(f"{filename}.gz", "rt") as sf:
sb += "".join(sf.readlines())
else:
raise ValueError("Species file for {sp.symbol} not found.")
raise ValueError(f"Species file for {sp.symbol} not found.")

return sb

Expand Down
5 changes: 5 additions & 0 deletions pymatgen/io/aims/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

from pymatgen.core import Molecule, Structure

__author__ = "Andrey Sobolev and Thomas A. R. Purcell"
__version__ = "1.0"
__email__ = "[email protected] and [email protected]"
__date__ = "November 2023"


class AimsOutput(MSONable):
"""The main output file for FHI-aims."""
Expand Down
11 changes: 9 additions & 2 deletions pymatgen/io/aims/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

from emmet.core.math import Matrix3D, Vector3D

__author__ = "Thomas A. R. Purcell and Andrey Sobolev"
__version__ = "1.0"
__email__ = "[email protected] and [email protected]"
__date__ = "November 2023"

# TARP: Originally an object, but type hinting needs this to be an int
LINE_NOT_FOUND = -1000
EV_PER_A3_TO_KBAR = 1.60217653e-19 * 1e22
Expand Down Expand Up @@ -997,7 +1002,7 @@ def get_aims_out_chunks(content: str | TextIOWrapper, header_chunk: AimsOutHeade
Yields:
The next AimsOutChunk
"""
lines = list(filter(lambda x: x not in header_chunk.lines, get_lines(content)))
lines = get_lines(content)[len(header_chunk.lines) :]
if len(lines) == 0:
return

Expand Down Expand Up @@ -1122,7 +1127,9 @@ def read_aims_output_from_content(
check_convergence(chunks, non_convergence_ok)
# Relaxations have an additional footer chunk due to how it is split
images = (
[chunk.structure for chunk in chunks[:-1]] if header_chunk.is_relaxation else [chunk.atoms for chunk in chunks]
[chunk.structure for chunk in chunks[:-1]]
if header_chunk.is_relaxation
else [chunk.structure for chunk in chunks]
)
return images[index]

Expand Down
Binary file modified tests/io/aims/input_files/control.in.si.gz
Binary file not shown.
Binary file added tests/io/aims/input_files/control.in.si.no_sd.gz
Binary file not shown.
Binary file modified tests/io/aims/output_files/si.out.gz
Binary file not shown.
Binary file modified tests/io/aims/output_files/si_ref.json.gz
Binary file not shown.
37 changes: 36 additions & 1 deletion tests/io/aims/test_aims_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gzip
import json
import os
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -29,7 +30,6 @@ def compare_files(ref_file, test_file):
for test_line, ref_line in zip(test_lines, ref_lines):
if "species_dir" in ref_line:
continue

assert test_line.strip() == ref_line.strip()


Expand Down Expand Up @@ -228,3 +228,38 @@ def test_aims_control_in(tmp_path):

aims_control_from_dict.write_file(si, directory=tmp_path, verbose_header=True, overwrite=True)
compare_files(infile_dir / "control.in.si", f"{tmp_path}/control.in")


def test_aims_control_in_default_species_dir(tmp_path):
original_sd = os.environ.get("AIMS_SPECIES_DIR", None)
os.environ["AIMS_SPECIES_DIR"] = str(infile_dir.parent / "species_directory/light")

parameters = {
"cubes": [
AimsCube(type="eigenstate 1", points=[10, 10, 10]),
AimsCube(type="total_density", points=[10, 10, 10]),
],
"xc": "LDA",
"smearing": ["fermi-dirac", 0.01],
"vdw_correction_hirshfeld": True,
"compute_forces": True,
"relax_geometry": ["trm", "1e-3"],
"batch_size_limit": 200,
"output": ["band 0 0 0 0.5 0 0.5 10 G X", "band 0 0 0 0.5 0.5 0.5 10 G L"],
"k_grid": [1, 1, 1],
}

aims_control = AimsControlIn(parameters.copy())

for key, val in parameters.items():
assert aims_control[key] == val

si = AimsGeometryIn.from_file(infile_dir / "geometry.in.si.gz").structure

aims_control.write_file(si, directory=tmp_path, verbose_header=True, overwrite=True)
compare_files(infile_dir / "control.in.si.no_sd", f"{tmp_path}/control.in")

if original_sd is not None:
os.environ["AIMS_SPECIES_DIR"] = original_sd
else:
del os.environ["AIMS_SPECIES_DIR"]

0 comments on commit 77a92bd

Please sign in to comment.