Skip to content

Commit 0817ede

Browse files
ansobolevjanosh
andauthored
Equation of State workflow for FHI-aims (#889)
* Added EOS FHI-aims workflow * Added tmp_path to phonon tests * Added test data for EOS workflow * Tests changed for older Pymatgen version * simplify from_parameters * Change the test reference value --------- Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
1 parent 5397132 commit 0817ede

File tree

15 files changed

+188
-2
lines changed

15 files changed

+188
-2
lines changed

src/atomate2/aims/flows/eos.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""Equation of state workflow for FHI-aims. Based on the common EOS workflow."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass, field
6+
from typing import TYPE_CHECKING, Any
7+
8+
from atomate2.aims.flows.core import DoubleRelaxMaker
9+
from atomate2.aims.jobs.core import RelaxMaker
10+
from atomate2.common.flows.eos import CommonEosMaker
11+
12+
if TYPE_CHECKING:
13+
from jobflow import Maker
14+
15+
16+
@dataclass
17+
class AimsEosMaker(CommonEosMaker):
18+
"""
19+
Generate equation of state data (based on common EOS maker).
20+
21+
First relaxes a structure using initial_relax_maker, then perform a series of
22+
deformations on the relaxed structure, and evaluate single-point energies with
23+
static_maker.
24+
25+
Parameters
26+
----------
27+
name : str
28+
Name of the flows produced by this maker.
29+
initial_relax_maker : .Maker | None
30+
Maker to relax the input structure, defaults to double relaxation.
31+
eos_relax_maker : .Maker
32+
Maker to relax deformed structures for the EOS fit.
33+
static_maker : .Maker | None
34+
Maker to generate statics after each relaxation, defaults to None.
35+
strain : tuple[float]
36+
Percentage linear strain to apply as a deformation, default = -5% to 5%.
37+
number_of_frames : int
38+
Number of strain calculations to do for EOS fit, default = 6.
39+
postprocessor : .atomate2.common.jobs.EOSPostProcessor
40+
Optional postprocessing step, defaults to
41+
`atomate2.common.jobs.PostProcessEosEnergy`.
42+
_store_transformation_information : .bool = False
43+
Whether to store the information about transformations. Unfortunately
44+
needed at present to handle issues with emmet and pydantic validation
45+
"""
46+
47+
name: str = "aims eos"
48+
initial_relax_maker: Maker | None = field(
49+
default_factory=lambda: DoubleRelaxMaker.from_parameters({})
50+
)
51+
eos_relax_maker: Maker | None = field(
52+
default_factory=lambda: RelaxMaker.fixed_cell_relaxation(
53+
user_params={"species_dir": "tight"}
54+
)
55+
)
56+
57+
@classmethod
58+
def from_parameters(cls, parameters: dict[str, Any], **kwargs) -> AimsEosMaker:
59+
"""Creation of AimsEosMaker from parameters.
60+
61+
Parameters
62+
----------
63+
parameters : dict
64+
Dictionary of common parameters for both makers. The one exception is
65+
`species_dir` which can be either a string or a dict with keys [`initial`,
66+
`eos`]. If a string is given, it will be interpreted as the `species_dir`
67+
for the `eos` Maker; the initial double relaxation will be done then with
68+
the default `light` and `tight` species' defaults.
69+
kwargs
70+
Keyword arguments passed to `CommonEosMaker`.
71+
"""
72+
species_dir = parameters.setdefault("species_dir", "tight")
73+
initial_params = parameters.copy()
74+
eos_params = parameters.copy()
75+
if isinstance(species_dir, dict):
76+
initial_params["species_dir"] = species_dir.get("initial")
77+
eos_params["species_dir"] = species_dir.get("eos", "tight")
78+
return cls(
79+
initial_relax_maker=DoubleRelaxMaker.from_parameters(initial_params),
80+
eos_relax_maker=RelaxMaker.fixed_cell_relaxation(user_params=eos_params),
81+
**kwargs,
82+
)

tests/aims/test_flows/test_eos.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""Test FHI-aims Equation of State workflow"""
2+
3+
import os
4+
5+
import pytest
6+
from jobflow import run_locally
7+
from pymatgen.core import Structure
8+
9+
from atomate2.aims.flows.eos import AimsEosMaker
10+
from atomate2.aims.jobs.core import RelaxMaker
11+
12+
cwd = os.getcwd()
13+
14+
# mapping from job name to directory containing test files
15+
ref_paths = {
16+
"Relaxation calculation 1": "double-relax-si/relax-1",
17+
"Relaxation calculation 2": "double-relax-si/relax-2",
18+
"Relaxation calculation (fixed cell) deformation 0": "eos-si/0",
19+
"Relaxation calculation (fixed cell) deformation 1": "eos-si/1",
20+
"Relaxation calculation (fixed cell) deformation 2": "eos-si/2",
21+
"Relaxation calculation (fixed cell) deformation 3": "eos-si/3",
22+
}
23+
24+
25+
def test_eos(mock_aims, tmp_path, species_dir):
26+
"""A test for the equation of state flow"""
27+
28+
# a relaxed structure for the test
29+
a = 2.80791457
30+
si = Structure(
31+
lattice=[[0.0, a, a], [a, 0.0, a], [a, a, 0.0]],
32+
species=["Si", "Si"],
33+
coords=[[0, 0, 0], [0.25, 0.25, 0.25]],
34+
)
35+
36+
# settings passed to fake_run_aims
37+
fake_run_kwargs = {}
38+
39+
# automatically use fake AIMS
40+
mock_aims(ref_paths, fake_run_kwargs)
41+
42+
# generate flow
43+
eos_relax_maker = RelaxMaker.fixed_cell_relaxation(
44+
user_params={
45+
"species_dir": (species_dir / "light").as_posix(),
46+
# "species_dir": "light",
47+
"k_grid": [2, 2, 2],
48+
}
49+
)
50+
51+
flow = AimsEosMaker(
52+
initial_relax_maker=None, eos_relax_maker=eos_relax_maker, number_of_frames=4
53+
).make(si)
54+
55+
# Run the flow or job and ensure that it finished running successfully
56+
os.chdir(tmp_path)
57+
responses = run_locally(flow, create_folders=True, ensure_success=True)
58+
os.chdir(cwd)
59+
60+
output = responses[flow.jobs[-1].uuid][1].output
61+
assert "EOS" in output["relax"]
62+
# there is no initial calculation; fit using 4 points
63+
assert len(output["relax"]["energy"]) == 4
64+
assert output["relax"]["EOS"]["birch_murnaghan"]["b0"] == pytest.approx(
65+
0.4897486348366812
66+
)
67+
68+
69+
def test_eos_from_parameters(mock_aims, tmp_path, si, species_dir):
70+
"""A test for the equation of state flow, created from the common parameters"""
71+
72+
# settings passed to fake_run_aims
73+
fake_run_kwargs = {}
74+
75+
# automatically use fake AIMS
76+
mock_aims(ref_paths, fake_run_kwargs)
77+
78+
# generate flow
79+
flow = AimsEosMaker.from_parameters(
80+
parameters={
81+
# TODO: to be changed after pymatgen PR is merged
82+
"species_dir": {
83+
"initial": species_dir,
84+
"eos": (species_dir / "light").as_posix(),
85+
},
86+
# "species_dir": "light",
87+
"k_grid": [2, 2, 2],
88+
},
89+
number_of_frames=4,
90+
).make(si)
91+
92+
# Run the flow or job and ensure that it finished running successfully
93+
os.chdir(tmp_path)
94+
responses = run_locally(flow, create_folders=True, ensure_success=True)
95+
os.chdir(cwd)
96+
97+
output = responses[flow.jobs[-1].uuid][1].output
98+
assert "EOS" in output["relax"]
99+
# there is an initial calculation; fit using 5 points
100+
assert len(output["relax"]["energy"]) == 5
101+
# the initial calculation also participates in the fit here
102+
assert output["relax"]["EOS"]["birch_murnaghan"]["b0"] == pytest.approx(
103+
0.5189578108402951
104+
)

tests/aims/test_flows/test_phonon_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def test_phonon_socket_flow(si, tmp_path, mock_aims, species_dir):
153153
)
154154

155155
# run the flow or job and ensure that it finished running successfully
156-
# os.chdir(tmp_path)
156+
os.chdir(tmp_path)
157157
responses = run_locally(flow, create_folders=True, ensure_success=True)
158-
# os.chdir(cwd)
158+
os.chdir(cwd)
159159

160160
# validation the outputs of the job
161161
output = responses[flow.job_uuids[-1]][1].output
Binary file not shown.
170 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
177 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)