From ba8bbf6360f64a0e7cdf18a648ec09aa557029b7 Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Wed, 17 Jul 2024 12:28:56 -0700 Subject: [PATCH 1/9] Fix d2k function Need to use the transpose of the inverse matrix for recipmatrix --- src/pymatgen/io/aims/sets/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pymatgen/io/aims/sets/base.py b/src/pymatgen/io/aims/sets/base.py index c15385d9a2e..2bdf28f6395 100644 --- a/src/pymatgen/io/aims/sets/base.py +++ b/src/pymatgen/io/aims/sets/base.py @@ -382,7 +382,7 @@ def d2k( Returns: dict: Monkhorst-Pack grid size in all directions """ - recipcell = structure.lattice.inv_matrix + recipcell = structure.lattice.inv_matrix.transpose() return self.d2k_recipcell(recipcell, structure.lattice.pbc, kptdensity, even) def k2d(self, structure: Structure, k_grid: np.ndarray[int]): @@ -397,7 +397,7 @@ def k2d(self, structure: Structure, k_grid: np.ndarray[int]): Returns: dict: Density of kpoints in each direction. result.mean() computes average density """ - recipcell = structure.lattice.inv_matrix + recipcell = structure.lattice.inv_matrix.transpose() densities = k_grid / (2 * np.pi * np.sqrt((recipcell**2).sum(axis=1))) return np.array(densities) @@ -433,6 +433,7 @@ def d2k_recipcell( kpts.append(int(np.ceil(k))) else: kpts.append(1) + print(f"kpoiint: {i} {kpts[i]} {np.sqrt((recipcell[i] ** 2).sum())} {kptdensity[i]}") return kpts From e2e22b1ac73521ecff5ff519f70b79e2493849a9 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 5 Aug 2024 08:56:21 -0400 Subject: [PATCH 2/9] breaking: snake_case method args kpt_density and recip_cell (better to do early while user base small) --- src/pymatgen/io/aims/sets/base.py | 61 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/pymatgen/io/aims/sets/base.py b/src/pymatgen/io/aims/sets/base.py index 2bdf28f6395..35f99106e89 100644 --- a/src/pymatgen/io/aims/sets/base.py +++ b/src/pymatgen/io/aims/sets/base.py @@ -12,6 +12,7 @@ import numpy as np from monty.json import MontyDecoder, MontyEncoder + from pymatgen.core import Molecule, Structure from pymatgen.io.aims.inputs import AimsControlIn, AimsGeometryIn from pymatgen.io.aims.parsers import AimsParseError, read_aims_output @@ -233,7 +234,7 @@ def _read_previous( prev_dir (str or Path): The previous directory for the calculation """ prev_structure: Structure | Molecule | None = None - prev_parameters = {} + prev_params = {} prev_results: dict[str, Any] = {} if prev_dir: @@ -242,7 +243,7 @@ def _read_previous( # jobflow_remote) split_prev_dir = str(prev_dir).split(":")[-1] with open(f"{split_prev_dir}/parameters.json") as param_file: - prev_parameters = json.load(param_file, cls=MontyDecoder) + prev_params = json.load(param_file, cls=MontyDecoder) try: aims_output: Sequence[Structure | Molecule] = read_aims_output( @@ -255,7 +256,7 @@ def _read_previous( except (IndexError, AimsParseError): pass - return prev_structure, prev_parameters, prev_results + return prev_structure, prev_params, prev_results @staticmethod def _get_properties( @@ -307,12 +308,9 @@ def _get_input_parameters( Returns: dict: The input object """ - # Get the default configuration - # FHI-aims recommends using their defaults so bare-bones default parameters - parameters: dict[str, Any] = { - "xc": "pbe", - "relativistic": "atomic_zora scalar", - } + # Get the default config + # FHI-aims recommends using their defaults so bare-bones default params + params: dict[str, Any] = {"xc": "pbe", "relativistic": "atomic_zora scalar"} # Override default parameters with previous parameters prev_parameters = {} if prev_parameters is None else copy.deepcopy(prev_parameters) @@ -326,25 +324,25 @@ def _get_input_parameters( kpt_settings["density"] = density parameter_updates = self.get_parameter_updates(structure, prev_parameters) - parameters = recursive_update(parameters, parameter_updates) + params = recursive_update(params, parameter_updates) # Override default parameters with user_params - parameters = recursive_update(parameters, self.user_params) - if ("k_grid" in parameters) and ("density" in kpt_settings): + params = recursive_update(params, self.user_params) + if ("k_grid" in params) and ("density" in kpt_settings): warn( "WARNING: the k_grid is set in user_params and in the kpt_settings," " using the one passed in user_params.", stacklevel=1, ) - elif isinstance(structure, Structure) and ("k_grid" not in parameters): + elif isinstance(structure, Structure) and ("k_grid" not in params): density = kpt_settings.get("density", 5.0) even = kpt_settings.get("even", True) - parameters["k_grid"] = self.d2k(structure, density, even) - elif isinstance(structure, Molecule) and "k_grid" in parameters: + params["k_grid"] = self.d2k(structure, density, even) + elif isinstance(structure, Molecule) and "k_grid" in params: warn("WARNING: removing unnecessary k_grid information", stacklevel=1) - del parameters["k_grid"] + del params["k_grid"] - return parameters + return params def get_parameter_updates( self, @@ -365,7 +363,7 @@ def get_parameter_updates( def d2k( self, structure: Structure, - kptdensity: float | list[float] = 5.0, + kpt_density: float | list[float] = 5.0, even: bool = True, ) -> Iterable[float]: """Convert k-point density to Monkhorst-Pack grid size. @@ -375,15 +373,15 @@ def d2k( Args: structure (Structure): Contains unit cell and information about boundary conditions. - kptdensity (float | list[float]): Required k-point + kpt_density (float | list[float]): Required k-point density. Default value is 5.0 point per Ang^-1. even (bool): Round up to even numbers. Returns: dict: Monkhorst-Pack grid size in all directions """ - recipcell = structure.lattice.inv_matrix.transpose() - return self.d2k_recipcell(recipcell, structure.lattice.pbc, kptdensity, even) + recip_cell = structure.lattice.inv_matrix.transpose() + return self.d2k_recip_cell(recip_cell, structure.lattice.pbc, kpt_density, even) def k2d(self, structure: Structure, k_grid: np.ndarray[int]): """Generate the kpoint density in each direction from given k_grid. @@ -397,43 +395,42 @@ def k2d(self, structure: Structure, k_grid: np.ndarray[int]): Returns: dict: Density of kpoints in each direction. result.mean() computes average density """ - recipcell = structure.lattice.inv_matrix.transpose() - densities = k_grid / (2 * np.pi * np.sqrt((recipcell**2).sum(axis=1))) + recip_cell = structure.lattice.inv_matrix.transpose() + densities = k_grid / (2 * np.pi * np.sqrt((recip_cell**2).sum(axis=1))) return np.array(densities) @staticmethod - def d2k_recipcell( - recipcell: np.ndarray, + def d2k_recip_cell( + recip_cell: np.ndarray, pbc: Sequence[bool], - kptdensity: float | Sequence[float] = 5.0, + kpt_density: float | Sequence[float] = 5.0, even: bool = True, ) -> Sequence[int]: """Convert k-point density to Monkhorst-Pack grid size. Args: - recipcell (Cell): The reciprocal cell + recip_cell (Cell): The reciprocal cell pbc (Sequence[bool]): If element of pbc is True then system is periodic in that direction - kptdensity (float or list[floats]): Required k-point + kpt_density (float or list[floats]): Required k-point density. Default value is 3.5 point per Ang^-1. even(bool): Round up to even numbers. Returns: dict: Monkhorst-Pack grid size in all directions """ - if not isinstance(kptdensity, Iterable): - kptdensity = 3 * [float(kptdensity)] + if not isinstance(kpt_density, Iterable): + kpt_density = 3 * [float(kpt_density)] kpts: list[int] = [] for i in range(3): if pbc[i]: - k = 2 * np.pi * np.sqrt((recipcell[i] ** 2).sum()) * float(kptdensity[i]) + k = 2 * np.pi * np.sqrt((recip_cell[i] ** 2).sum()) * float(kpt_density[i]) if even: kpts.append(2 * int(np.ceil(k / 2))) else: kpts.append(int(np.ceil(k))) else: kpts.append(1) - print(f"kpoiint: {i} {kpts[i]} {np.sqrt((recipcell[i] ** 2).sum())} {kptdensity[i]}") return kpts From e947a881e064086bcb55287d4e56a3f034b06878 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 5 Aug 2024 08:57:26 -0400 Subject: [PATCH 3/9] d2k_recip_cell fix kpt_density type anno and doc str --- src/pymatgen/io/aims/sets/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pymatgen/io/aims/sets/base.py b/src/pymatgen/io/aims/sets/base.py index 35f99106e89..83a4761529d 100644 --- a/src/pymatgen/io/aims/sets/base.py +++ b/src/pymatgen/io/aims/sets/base.py @@ -403,7 +403,7 @@ def k2d(self, structure: Structure, k_grid: np.ndarray[int]): def d2k_recip_cell( recip_cell: np.ndarray, pbc: Sequence[bool], - kpt_density: float | Sequence[float] = 5.0, + kpt_density: float | tuple[float, float, float] = 5.0, even: bool = True, ) -> Sequence[int]: """Convert k-point density to Monkhorst-Pack grid size. @@ -413,7 +413,7 @@ def d2k_recip_cell( pbc (Sequence[bool]): If element of pbc is True then system is periodic in that direction kpt_density (float or list[floats]): Required k-point - density. Default value is 3.5 point per Ang^-1. + density. Default value is 5 points per Ang^-1. even(bool): Round up to even numbers. Returns: From fce89301415f6f97862488c220bca63e02c363e2 Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Mon, 5 Aug 2024 08:27:36 -0700 Subject: [PATCH 4/9] Add test for aims density conversions --- src/pymatgen/util/testing/aims.py | 13 +++++++++++-- .../static-no-kgrid-si/control.in.gz | Bin 1244 -> 1162 bytes .../static-no-kgrid-si/geometry.in.gz | Bin 216 -> 188 bytes .../static-no-kgrid-si/parameters.json | 4 ++-- .../aims/test_sets/test_static_generator.py | 5 ++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pymatgen/util/testing/aims.py b/src/pymatgen/util/testing/aims.py index 057df663083..ab31b9d667f 100644 --- a/src/pymatgen/util/testing/aims.py +++ b/src/pymatgen/util/testing/aims.py @@ -84,6 +84,7 @@ def comp_system( generator_cls: type, properties: list[str] | None = None, prev_dir: str | None | Path = None, + user_kpt_settings: dict[str, Any] | None = None, ) -> None: """Compare files generated by tests with ones in reference directories. @@ -96,16 +97,24 @@ def comp_system( generator_cls (type): The class of the generator properties (list[str] | None): The list of properties to calculate prev_dir (str | Path | None): The previous directory to pull outputs from + user_kpt_settings (dict[str, Any] | None): settings for k-point density in FHI-aims Raises: AssertionError: If the input files are not the same """ + if user_kpt_settings is None: + user_kpt_settings = {} + k_point_density = user_params.pop("k_point_density", 20) try: - generator = generator_cls(user_params=user_params, k_point_density=k_point_density) + generator = generator_cls( + user_params=user_params, + k_point_density=k_point_density, + user_kpoints_settings=user_kpt_settings, + ) except TypeError: - generator = generator_cls(user_params=user_params) + generator = generator_cls(user_params=user_params, user_kpoints_settings=user_kpt_settings) input_set = generator.get_input_set(structure, prev_dir, properties) input_set.write_input(work_dir / test_name) diff --git a/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/control.in.gz b/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/control.in.gz index 9b912b2ffe2d5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_ref/static-no-kgrid-si/geometry.in.gz index c2e720a036642f8b6363fb1f551ee7ed40bb9911..413cb3eb22ac036ee72ce497d1484cbb709f79f0 100644 GIT binary patch literal 188 zcmV;t07L&DiwFqC?yzP617~G#ZDn+Fc`j*g0F{wJ3WP8WMfaYf`+<;ZW1Vx%0Ysz= zK@p_P`DYeG8PgDBmY>hd&(AvLyv%8Qr#bJ3a|rl1>4E563(?c1)~pOg5IT;M@U^c( z4d4S$AZazenex8LdyU#_`7vxY=nSb7V^3-h>`LYHKv~lM6V_jc@G$7c&CvA>QX=mnQ-Q z7fBGVc8n^BWQq3?OEMOKNBpC3!#RM6vN-*#{h*d&et0jGA3m5Lu)Nn(yUG_Mj*>J> Szx|$?V>|&0*)$P=0ssK=4qhk# diff --git a/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/parameters.json b/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/parameters.json index 28242f36fa7..a6c81a5f1e6 100644 --- a/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/parameters.json +++ b/tests/io/aims/aims_input_generator_ref/static-no-kgrid-si/parameters.json @@ -4,7 +4,7 @@ "species_dir": "/home/tpurcell/git/atomate2/tests/aims/species_dir/light", "k_grid": [ 12, - 12, - 12 + 6, + 4 ] } diff --git a/tests/io/aims/test_sets/test_static_generator.py b/tests/io/aims/test_sets/test_static_generator.py index 39415758b1e..62a82964bb3 100644 --- a/tests/io/aims/test_sets/test_static_generator.py +++ b/tests/io/aims/test_sets/test_static_generator.py @@ -2,6 +2,8 @@ from pathlib import Path +import numpy as np + from pymatgen.io.aims.sets.core import StaticSetGenerator from pymatgen.util.testing.aims import O2, Si, comp_system @@ -19,7 +21,8 @@ def test_static_si(tmp_path): def test_static_si_no_kgrid(tmp_path): parameters = {"species_dir": "light"} - comp_system(Si, parameters, "static-no-kgrid-si", tmp_path, ref_path, StaticSetGenerator) + Si_supercell = Si.make_supercell(np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]), in_place=False) + comp_system(Si_supercell, parameters, "static-no-kgrid-si", tmp_path, ref_path, StaticSetGenerator) def test_static_o2(tmp_path): From ae530c922c8523760bee8db7d30e7eb930247cb6 Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Mon, 5 Aug 2024 09:14:22 -0700 Subject: [PATCH 5/9] Fix mypy errors --- src/pymatgen/io/aims/sets/base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pymatgen/io/aims/sets/base.py b/src/pymatgen/io/aims/sets/base.py index 83a4761529d..5f266a21a0c 100644 --- a/src/pymatgen/io/aims/sets/base.py +++ b/src/pymatgen/io/aims/sets/base.py @@ -5,7 +5,6 @@ import copy import json import logging -from collections.abc import Iterable from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any from warnings import warn @@ -19,7 +18,7 @@ from pymatgen.io.core import InputFile, InputGenerator, InputSet if TYPE_CHECKING: - from collections.abc import Sequence + from collections.abc import Iterable, Sequence from pymatgen.util.typing import PathLike @@ -363,7 +362,7 @@ def get_parameter_updates( def d2k( self, structure: Structure, - kpt_density: float | list[float] = 5.0, + kpt_density: float | tuple[float, float, float] = 5.0, even: bool = True, ) -> Iterable[float]: """Convert k-point density to Monkhorst-Pack grid size. @@ -419,8 +418,8 @@ def d2k_recip_cell( Returns: dict: Monkhorst-Pack grid size in all directions """ - if not isinstance(kpt_density, Iterable): - kpt_density = 3 * [float(kpt_density)] + if isinstance(kpt_density, float): + kpt_density = (kpt_density, kpt_density, kpt_density) kpts: list[int] = [] for i in range(3): if pbc[i]: From c9087db38124cfd2525c22034169ec9912555d86 Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Mon, 5 Aug 2024 09:41:59 -0700 Subject: [PATCH 6/9] Add print line to see what the actual errors look like All tests pass locally --- src/pymatgen/util/testing/aims.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pymatgen/util/testing/aims.py b/src/pymatgen/util/testing/aims.py index ab31b9d667f..d11cf1422d9 100644 --- a/src/pymatgen/util/testing/aims.py +++ b/src/pymatgen/util/testing/aims.py @@ -49,6 +49,7 @@ def compare_files(test_name: str, work_dir: Path, ref_dir: Path) -> None: ref_lines = [line.strip() for line in ref_file.readlines() if len(line.strip()) > 0 and line[0] != "#"] for test_line, ref_line in zip(test_lines, ref_lines): + print(f"\n{test_line}\n{ref_line}") if "output" in test_line and "band" in test_line: assert check_band(test_line, ref_line) else: From 6face7f113e0ff70d76c301fedd51041db7d0408 Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Mon, 5 Aug 2024 10:03:18 -0700 Subject: [PATCH 7/9] for supercell round coords should fix error in tests --- tests/io/aims/test_sets/test_static_generator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/io/aims/test_sets/test_static_generator.py b/tests/io/aims/test_sets/test_static_generator.py index 62a82964bb3..abea87ae2bb 100644 --- a/tests/io/aims/test_sets/test_static_generator.py +++ b/tests/io/aims/test_sets/test_static_generator.py @@ -4,6 +4,7 @@ import numpy as np +from pymatgen.core import Structure from pymatgen.io.aims.sets.core import StaticSetGenerator from pymatgen.util.testing.aims import O2, Si, comp_system @@ -22,6 +23,11 @@ def test_static_si(tmp_path): def test_static_si_no_kgrid(tmp_path): parameters = {"species_dir": "light"} Si_supercell = Si.make_supercell(np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]), in_place=False) + Si_supercell = Structure( + lattice=Si_supercell.lattice, + species=Si_supercell.species, + coords=np.round(Si_supercell.frac_coords, 15), + ) comp_system(Si_supercell, parameters, "static-no-kgrid-si", tmp_path, ref_path, StaticSetGenerator) From 52c4f0f4d48b9600569db0a73383bbf124f0af9b Mon Sep 17 00:00:00 2001 From: Tom Purcell Date: Mon, 5 Aug 2024 10:19:11 -0700 Subject: [PATCH 8/9] remove extra print line --- src/pymatgen/util/testing/aims.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pymatgen/util/testing/aims.py b/src/pymatgen/util/testing/aims.py index d11cf1422d9..ab31b9d667f 100644 --- a/src/pymatgen/util/testing/aims.py +++ b/src/pymatgen/util/testing/aims.py @@ -49,7 +49,6 @@ def compare_files(test_name: str, work_dir: Path, ref_dir: Path) -> None: ref_lines = [line.strip() for line in ref_file.readlines() if len(line.strip()) > 0 and line[0] != "#"] for test_line, ref_line in zip(test_lines, ref_lines): - print(f"\n{test_line}\n{ref_line}") if "output" in test_line and "band" in test_line: assert check_band(test_line, ref_line) else: From 51e27bcf4a2d0a679239a2b9960d1515bb47cf47 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Tue, 6 Aug 2024 11:52:16 -0400 Subject: [PATCH 9/9] refactor test_static_si_no_kgrid --- src/pymatgen/util/testing/aims.py | 2 +- tests/io/aims/test_sets/test_static_generator.py | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/pymatgen/util/testing/aims.py b/src/pymatgen/util/testing/aims.py index ab31b9d667f..1220974a8b5 100644 --- a/src/pymatgen/util/testing/aims.py +++ b/src/pymatgen/util/testing/aims.py @@ -126,7 +126,7 @@ def compare_single_files(ref_file: str | Path, test_file: str | Path) -> None: """Compare single files generated by tests with ones in reference directories. Args: - ref_file (str | Path): The reference file to cmpare against + ref_file (str | Path): The reference file to compare against test_file (str | Path): The file to compare against the reference Raises: diff --git a/tests/io/aims/test_sets/test_static_generator.py b/tests/io/aims/test_sets/test_static_generator.py index abea87ae2bb..a38c002897d 100644 --- a/tests/io/aims/test_sets/test_static_generator.py +++ b/tests/io/aims/test_sets/test_static_generator.py @@ -2,9 +2,6 @@ from pathlib import Path -import numpy as np - -from pymatgen.core import Structure from pymatgen.io.aims.sets.core import StaticSetGenerator from pymatgen.util.testing.aims import O2, Si, comp_system @@ -22,12 +19,10 @@ def test_static_si(tmp_path): def test_static_si_no_kgrid(tmp_path): parameters = {"species_dir": "light"} - Si_supercell = Si.make_supercell(np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]), in_place=False) - Si_supercell = Structure( - lattice=Si_supercell.lattice, - species=Si_supercell.species, - coords=np.round(Si_supercell.frac_coords, 15), - ) + Si_supercell = Si.make_supercell([1, 2, 3], in_place=False) + for site in Si_supercell: + # round site.coords to ignore floating point errors + site.coords = [round(x, 15) for x in site.coords] comp_system(Si_supercell, parameters, "static-no-kgrid-si", tmp_path, ref_path, StaticSetGenerator)