Skip to content

Commit

Permalink
Implementation to adjust get_supercell_size to also generate orthorho…
Browse files Browse the repository at this point in the history
…mbic 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]>
  • Loading branch information
2 people authored and hrushikesh-s committed Nov 16, 2024
1 parent 1a22235 commit ffbad05
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/atomate2/common/flows/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class BasePhononMaker(Maker, ABC):
symprec: float = SETTINGS.PHONON_SYMPREC
displacement: float = 0.01
min_length: float | None = 20.0
max_length: float | None = None
prefer_90_degrees: bool = True
allow_orthorhombic: bool = False
get_supercell_size_kwargs: dict = field(default_factory=dict)
use_symmetrized_structure: Literal["primitive", "conventional"] | None = None
bulk_relax_maker: ForceFieldRelaxMaker | BaseVaspMaker | BaseAimsMaker | None = None
Expand Down Expand Up @@ -252,9 +254,11 @@ def make(
# maker to ensure that cell lengths are really larger than threshold
if supercell_matrix is None:
supercell_job = get_supercell_size(
structure,
self.min_length,
self.prefer_90_degrees,
structure=structure,
min_length=self.min_length,
max_length=self.max_length,
prefer_90_degrees=self.prefer_90_degrees,
allow_orthorhombic=self.allow_orthorhombic,
**self.get_supercell_size_kwargs,
)
jobs.append(supercell_job)
Expand Down
37 changes: 27 additions & 10 deletions src/atomate2/common/jobs/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,64 @@ def get_total_energy_per_cell(

@job
def get_supercell_size(
structure: Structure, min_length: float, prefer_90_degrees: bool, **kwargs
structure: Structure,
min_length: float,
max_length: float,
prefer_90_degrees: bool,
allow_orthorhombic: bool = False,
**kwargs,
) -> list[list[float]]:
"""
Determine supercell size with given min_length.
Determine supercell size with given min_length and max_length.
Parameters
----------
structure: Structure Object
Input structure that will be used to determine supercell
min_length: float
minimum length of cell in Angstrom
max_length: float
maximum length of cell in Angstrom
prefer_90_degrees: bool
if True, the algorithm will try to find a cell with 90 degree angles first
allow_orthorhombic: bool
if True, orthorhombic supercells are allowed
**kwargs:
Additional parameters that can be set.
"""
kwargs.setdefault("force_diagonal", False)
common_kwds = {
"min_length": min_length,
"min_atoms": kwargs.get("min_atoms"),
"force_diagonal": kwargs["force_diagonal"],
}
common_kwds = dict(
min_length=min_length,
max_length=max_length,
min_atoms=kwargs.get("min_atoms"),
max_atoms=kwargs.get("max_atoms"),
step_size=kwargs.get("step_size", 0.1),
force_diagonal=kwargs["force_diagonal"],
)

if not prefer_90_degrees:
transformation = CubicSupercellTransformation(
**common_kwds, max_atoms=kwargs.get("max_atoms"), force_90_degrees=False
**common_kwds,
force_90_degrees=False,
allow_orthorhombic=allow_orthorhombic,
)
transformation.apply_transformation(structure=structure)
else:
try:
common_kwds.update({"max_atoms": kwargs.get("max_atoms", 1200)})
transformation = CubicSupercellTransformation(
**common_kwds,
max_atoms=kwargs.get("max_atoms", 1200),
force_90_degrees=True,
angle_tolerance=kwargs.get("angle_tolerance", 1e-2),
allow_orthorhombic=allow_orthorhombic,
)
transformation.apply_transformation(structure=structure)

except AttributeError:
transformation = CubicSupercellTransformation(
**common_kwds, max_atoms=kwargs.get("max_atoms"), force_90_degrees=False
**common_kwds,
force_90_degrees=False,
allow_orthorhombic=allow_orthorhombic,
)
transformation.apply_transformation(structure=structure)

Expand Down
36 changes: 35 additions & 1 deletion tests/forcefields/test_phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,48 @@


def test_phonon_get_supercell_size(clean_dir, si_structure: Structure):
job = get_supercell_size(si_structure, min_length=18, prefer_90_degrees=True)
job = get_supercell_size(
si_structure, min_length=18, max_length=25, prefer_90_degrees=True
)

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

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


def test_supercell_orthorhombic(clean_dir, si_structure: Structure):
job1 = get_supercell_size(
si_structure,
min_length=5,
max_length=10,
prefer_90_degrees=False,
allow_orhtorhombic=True,
)

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

assert_allclose(
responses[job1.uuid][1].output, [[2, -1, 0], [0, 2, 0], [-1, -1, 2]]
)

job2 = get_supercell_size(
si_structure,
min_length=5,
max_length=10,
prefer_90_degrees=True,
allow_orhtorhombic=True,
)

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

assert_allclose(
responses[job2.uuid][1].output, [[2, -1, 0], [0, 3, 0], [-1, -1, 2]]
)


def test_phonon_maker_initialization_with_all_mlff(
si_structure: Structure, test_dir: Path
):
Expand Down

0 comments on commit ffbad05

Please sign in to comment.