Skip to content

Commit 4944aed

Browse files
Implementation to adjust get_supercell_size to also generate orthorhombic supercells (#923)
* starting with implementation to adjust get_supercell_size * adding orthorhombic supercells * add unit test * fixed the reason for the failing unit tests * adjust pymatgen version * adjust pymatgen version * fix linting * fix missing max_length in unit test * adjusted pymatgen version * add step_size to common_kwds * put max_atoms to common_kwds * adjustments to make unit tests pass * fixing ase unit test * Update test_jobs.py --------- Co-authored-by: J. George <[email protected]>
1 parent 4b71309 commit 4944aed

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

src/atomate2/common/flows/phonons.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class BasePhononMaker(Maker, ABC):
132132
symprec: float = SETTINGS.PHONON_SYMPREC
133133
displacement: float = 0.01
134134
min_length: float | None = 20.0
135+
max_length: float | None = None
135136
prefer_90_degrees: bool = True
137+
allow_orthorhombic: bool = False
136138
get_supercell_size_kwargs: dict = field(default_factory=dict)
137139
use_symmetrized_structure: Literal["primitive", "conventional"] | None = None
138140
bulk_relax_maker: ForceFieldRelaxMaker | BaseVaspMaker | BaseAimsMaker | None = None
@@ -252,9 +254,11 @@ def make(
252254
# maker to ensure that cell lengths are really larger than threshold
253255
if supercell_matrix is None:
254256
supercell_job = get_supercell_size(
255-
structure,
256-
self.min_length,
257-
self.prefer_90_degrees,
257+
structure=structure,
258+
min_length=self.min_length,
259+
max_length=self.max_length,
260+
prefer_90_degrees=self.prefer_90_degrees,
261+
allow_orthorhombic=self.allow_orthorhombic,
258262
**self.get_supercell_size_kwargs,
259263
)
260264
jobs.append(supercell_job)

src/atomate2/common/jobs/phonons.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,47 +57,64 @@ def get_total_energy_per_cell(
5757

5858
@job
5959
def get_supercell_size(
60-
structure: Structure, min_length: float, prefer_90_degrees: bool, **kwargs
60+
structure: Structure,
61+
min_length: float,
62+
max_length: float,
63+
prefer_90_degrees: bool,
64+
allow_orthorhombic: bool = False,
65+
**kwargs,
6166
) -> list[list[float]]:
6267
"""
63-
Determine supercell size with given min_length.
68+
Determine supercell size with given min_length and max_length.
6469
6570
Parameters
6671
----------
6772
structure: Structure Object
6873
Input structure that will be used to determine supercell
6974
min_length: float
7075
minimum length of cell in Angstrom
76+
max_length: float
77+
maximum length of cell in Angstrom
7178
prefer_90_degrees: bool
7279
if True, the algorithm will try to find a cell with 90 degree angles first
80+
allow_orthorhombic: bool
81+
if True, orthorhombic supercells are allowed
7382
**kwargs:
7483
Additional parameters that can be set.
7584
"""
7685
kwargs.setdefault("force_diagonal", False)
77-
common_kwds = {
78-
"min_length": min_length,
79-
"min_atoms": kwargs.get("min_atoms"),
80-
"force_diagonal": kwargs["force_diagonal"],
81-
}
86+
common_kwds = dict(
87+
min_length=min_length,
88+
max_length=max_length,
89+
min_atoms=kwargs.get("min_atoms"),
90+
max_atoms=kwargs.get("max_atoms"),
91+
step_size=kwargs.get("step_size", 0.1),
92+
force_diagonal=kwargs["force_diagonal"],
93+
)
8294

8395
if not prefer_90_degrees:
8496
transformation = CubicSupercellTransformation(
85-
**common_kwds, max_atoms=kwargs.get("max_atoms"), force_90_degrees=False
97+
**common_kwds,
98+
force_90_degrees=False,
99+
allow_orthorhombic=allow_orthorhombic,
86100
)
87101
transformation.apply_transformation(structure=structure)
88102
else:
89103
try:
104+
common_kwds.update({"max_atoms": kwargs.get("max_atoms", 1200)})
90105
transformation = CubicSupercellTransformation(
91106
**common_kwds,
92-
max_atoms=kwargs.get("max_atoms", 1200),
93107
force_90_degrees=True,
94108
angle_tolerance=kwargs.get("angle_tolerance", 1e-2),
109+
allow_orthorhombic=allow_orthorhombic,
95110
)
96111
transformation.apply_transformation(structure=structure)
97112

98113
except AttributeError:
99114
transformation = CubicSupercellTransformation(
100-
**common_kwds, max_atoms=kwargs.get("max_atoms"), force_90_degrees=False
115+
**common_kwds,
116+
force_90_degrees=False,
117+
allow_orthorhombic=allow_orthorhombic,
101118
)
102119
transformation.apply_transformation(structure=structure)
103120

tests/forcefields/test_phonon.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,48 @@
1212

1313

1414
def test_phonon_get_supercell_size(clean_dir, si_structure: Structure):
15-
job = get_supercell_size(si_structure, min_length=18, prefer_90_degrees=True)
15+
job = get_supercell_size(
16+
si_structure, min_length=18, max_length=25, prefer_90_degrees=True
17+
)
1618

1719
# run the flow or job and ensure that it finished running successfully
1820
responses = run_locally(job, create_folders=True, ensure_success=True)
1921

2022
assert_allclose(responses[job.uuid][1].output, [[6, -2, 0], [0, 6, 0], [-3, -2, 5]])
2123

2224

25+
def test_supercell_orthorhombic(clean_dir, si_structure: Structure):
26+
job1 = get_supercell_size(
27+
si_structure,
28+
min_length=5,
29+
max_length=10,
30+
prefer_90_degrees=False,
31+
allow_orhtorhombic=True,
32+
)
33+
34+
# run the flow or job and ensure that it finished running successfully
35+
responses = run_locally(job1, create_folders=True, ensure_success=True)
36+
37+
assert_allclose(
38+
responses[job1.uuid][1].output, [[2, -1, 0], [0, 2, 0], [-1, -1, 2]]
39+
)
40+
41+
job2 = get_supercell_size(
42+
si_structure,
43+
min_length=5,
44+
max_length=10,
45+
prefer_90_degrees=True,
46+
allow_orhtorhombic=True,
47+
)
48+
49+
# run the flow or job and ensure that it finished running successfully
50+
responses = run_locally(job2, create_folders=True, ensure_success=True)
51+
52+
assert_allclose(
53+
responses[job2.uuid][1].output, [[2, -1, 0], [0, 3, 0], [-1, -1, 2]]
54+
)
55+
56+
2357
def test_phonon_maker_initialization_with_all_mlff(
2458
si_structure: Structure, test_dir: Path
2559
):

0 commit comments

Comments
 (0)