Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix_symmetry: bool = False option to forcefield relax makers #789

Merged
merged 20 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d7e8109
add fix_symmetry option and tests to force field relaxer
JonathanSchmidt1 Mar 25, 2024
b15944b
add fix_symmetry option to one test job
JonathanSchmidt1 Mar 25, 2024
36d3f11
fix linting of test_jobs
JonathanSchmidt1 Mar 25, 2024
f5a2bfa
add missing documentation to GAP/MACE relaxmaker
JonathanSchmidt1 Mar 25, 2024
7eff631
Merge branch 'main' into pr/JonathanSchmidt1/789
janosh Apr 4, 2024
1b40a3a
restore test_fix_symmetry
janosh Apr 4, 2024
da7cfd4
restore fix_symmetry to NequipRelaxMaker doc str
janosh Apr 4, 2024
828e283
add fix_symmetry and symprec back into relaxer jobs. Add fix_symmetry…
JonathanSchmidt1 Apr 5, 2024
94a1bdc
add fix_symmetry and symprec to task_doc, add test for chgnet
JonathanSchmidt1 Apr 5, 2024
73bb548
separated fix_symmetry from standard relax_maker tests
JonathanSchmidt1 Apr 5, 2024
6f26bfb
fixed test_chgnet_relax_maker_fix_symmetry
JonathanSchmidt1 Apr 5, 2024
acf08f5
changed fix_symmetry and symprec to optional arguments in from_ase_co…
JonathanSchmidt1 Apr 5, 2024
c428126
test_fix_symmetry set steps=1 in relaxer.relax(), takes test from 6 t…
janosh Apr 6, 2024
99a5ddf
assert expected spacegroup in test_fix_symmetry
janosh Apr 6, 2024
a74f008
cut fix_symmetry and symprec combos in half in test_nequip_relax_make…
janosh Apr 6, 2024
12be77c
parametrize fix_symmetry=True|False on test_mace_relax_maker
janosh Apr 7, 2024
692d5d3
test_relax_maker_mace check for subgroup instead of group when using …
JonathanSchmidt1 Apr 7, 2024
38523bb
Merge branch 'main' into fix_symmetry
janosh Apr 25, 2024
1caebe0
fix test_mace_relax_maker
janosh Apr 25, 2024
9948246
from ase.(spacegroup.symmetrize->constraints) import FixSymmetry
janosh Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/atomate2/forcefields/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class NequipRelaxMaker(ForceFieldRelaxMaker):
name: str = f"{MLFF.Nequip} relax"
force_field_name: str = f"{MLFF.Nequip}"
relax_cell: bool = True
fix_symmetry: bool = False
steps: int = 500
relax_kwargs: dict = field(default_factory=dict)
optimizer_kwargs: dict = field(default_factory=dict)
Expand Down Expand Up @@ -351,6 +352,8 @@ class MACERelaxMaker(ForceFieldRelaxMaker):
The name of the force field.
relax_cell : bool = True
Whether to allow the cell shape/volume to change during relaxation.
fix_symmetry : bool = False
Whether to fix the symmetry during relaxation.
steps : int
Maximum number of ionic steps allowed during relaxation.
relax_kwargs : dict
Expand All @@ -372,6 +375,7 @@ class MACERelaxMaker(ForceFieldRelaxMaker):
name: str = f"{MLFF.MACE} relax"
force_field_name: str = f"{MLFF.MACE}"
relax_cell: bool = True
fix_symmetry: bool = False
steps: int = 500
relax_kwargs: dict = field(default_factory=dict)
optimizer_kwargs: dict = field(default_factory=dict)
Expand Down Expand Up @@ -419,6 +423,8 @@ class GAPRelaxMaker(ForceFieldRelaxMaker):
The name of the force field.
relax_cell : bool = True
Whether to allow the cell shape/volume to change during relaxation.
fix_symmetry : bool = False
Whether to fix the symmetry during relaxation.
steps : int
Maximum number of ionic steps allowed during relaxation.
relax_kwargs : dict
Expand All @@ -432,6 +438,7 @@ class GAPRelaxMaker(ForceFieldRelaxMaker):
name: str = f"{MLFF.GAP} relax"
force_field_name: str = f"{MLFF.GAP}"
relax_cell: bool = True
fix_symmetry: bool = False
steps: int = 500
relax_kwargs: dict = field(default_factory=dict)
optimizer_kwargs: dict = field(default_factory=dict)
Expand Down
6 changes: 5 additions & 1 deletion src/atomate2/forcefields/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from ase.filters import Filter
from ase.optimize.optimize import Optimizer


OPTIMIZERS = {
"FIRE": FIRE,
"BFGS": BFGS,
Expand Down Expand Up @@ -290,6 +289,7 @@
calculator: Calculator,
optimizer: Optimizer | str = "FIRE",
relax_cell: bool = True,
fix_symmetry: bool = False,
) -> None:
"""
Initialize the Relaxer.
Expand All @@ -299,6 +299,7 @@
calculator (ase Calculator): an ase calculator
optimizer (str or ase Optimizer): the optimization algorithm.
relax_cell (bool): if True, cell parameters will be optimized.
fix_symmetry (bool): if True, symmetry will be fixed during relaxation.
"""
self.calculator = calculator

Expand All @@ -312,6 +313,7 @@
self.opt_class: Optimizer = optimizer_obj
self.relax_cell = relax_cell
self.ase_adaptor = AseAtomsAdaptor()
self.fix_symmetry = fix_symmetry

def relax(
self,
Expand Down Expand Up @@ -350,6 +352,8 @@
"""
if isinstance(atoms, (Structure, Molecule)):
atoms = self.ase_adaptor.get_atoms(atoms)
if self.fix_symmetry:
atoms.set_constraint(FixSymmetry(atoms))

Check warning on line 356 in src/atomate2/forcefields/utils.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/forcefields/utils.py#L356

Added line #L356 was not covered by tests
atoms.set_calculator(self.calculator)
stream = sys.stdout if verbose else io.StringIO()
with contextlib.redirect_stdout(stream):
Expand Down
11 changes: 8 additions & 3 deletions tests/forcefields/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,15 @@ def test_nequip_static_maker(sr_ti_o3_structure: Structure, test_dir: Path):
assert output1.forcefield_version == get_imported_version("nequip")


@pytest.mark.parametrize("relax_cell", [True, False])
@pytest.mark.parametrize(
("relax_cell", "fix_symmetry"),
[(True, False), (False, False), (True, True), (False, True)],
)
def test_nequip_relax_maker(
sr_ti_o3_structure: Structure, test_dir: Path, relax_cell: bool
sr_ti_o3_structure: Structure,
test_dir: Path,
relax_cell: bool,
fix_symmetry: bool,
):
importorskip("nequip")
# translate one atom to ensure a small number of relaxation steps are taken
Expand All @@ -236,7 +242,6 @@ def test_nequip_relax_maker(
"model_path": test_dir / "forcefields" / "nequip" / "nequip_ff_sr_ti_o3.pth"
},
).make(sr_ti_o3_structure)

# run the flow or job and ensure that it finished running successfully
JonathanSchmidt1 marked this conversation as resolved.
Show resolved Hide resolved
responses = run_locally(job, ensure_success=True)

Expand Down
2 changes: 2 additions & 0 deletions tests/forcefields/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

import pytest
from ase.build import bulk
from ase.calculators.lj import LennardJones
from ase.optimize import BFGS
from ase.spacegroup.symmetrize import check_symmetry
from numpy.testing import assert_allclose
from pymatgen.io.ase import AseAtomsAdaptor

Expand Down
Loading