Skip to content

Commit

Permalink
fix the pytest
Browse files Browse the repository at this point in the history
Signed-off-by: Runze Liu <[email protected]>
  • Loading branch information
rul048 committed Sep 6, 2024
1 parent 26a45b2 commit 2e3b2c3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/test_relaxation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@pytest.mark.parametrize(
("cell_filter", "expected_a", "expected_energy"),
[(ExpCellFilter, 3.288585, -14.176882), (FrechetCellFilter, 3.291071, -14.176743)],
[(ExpCellFilter, 3.288585, -14.176867), (FrechetCellFilter, 3.291072, -14.176713)],
)
def test_relax_calc_relax_cell(
Li2O: Structure,
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_relax_calc_relax_cell(
assert final_struct.volume == pytest.approx(a * b * c / 2**0.5, abs=0.1)


@pytest.mark.parametrize(("expected_a", "expected_energy"), [(3.291071, -14.1767423)])
@pytest.mark.parametrize(("expected_a", "expected_energy"), [(3.291072, -14.176713)])
def test_relax_calc_relax_atoms(
Li2O: Structure, M3GNetCalc: M3GNetCalculator, tmp_path: Path, expected_a: float, expected_energy: float
) -> None:
Expand Down Expand Up @@ -82,28 +82,27 @@ def test_relax_calc_relax_atoms(
("expected_energy", "expected_forces", "expected_stresses"),
[
(
-14.176743,
-14.176713,
np.array(
[
[-4.252263e-03, -3.029412e-03, -7.360560e-03],
[4.272716e-03, 3.017864e-03, 7.360807e-03],
[-2.035008e-05, 1.152878e-05, -2.714805e-07],
[6.577218e-06, 1.851469e-06, -7.080846e-06],
[-4.507415e-03, -3.310852e-03, -7.090813e-03],
[4.500971e-03, 3.309000e-03, 7.097944e-03],
],
dtype=np.float32,
),
np.array([0.003945, 0.004185, 0.003000, -0.000584, -0.000826, -0.000337], dtype=np.float32),
np.array([0.003883, 0.004126, 0.003089, -0.000617, -0.000839, -0.000391], dtype=np.float32),
),
],
)
def test_static_calc(
Li2O: Structure,
M3GNetCalc: M3GNetCalculator,
tmp_path: Path,
expected_energy: float,
expected_forces: ArrayLike,
expected_stresses: ArrayLike,
) -> None:
relax_calc = RelaxCalc(M3GNetCalc, traj_file=f"{tmp_path}/li2o_relax.txt", relax_atoms=False, relax_cell=False)
relax_calc = RelaxCalc(M3GNetCalc, relax_atoms=False, relax_cell=False)
result = relax_calc.calc(Li2O)

energy: float = result["energy"]
Expand All @@ -115,7 +114,7 @@ def test_static_calc(
assert np.allclose(stresses, expected_stresses, rtol=1e-3)


@pytest.mark.parametrize(("cell_filter", "expected_a"), [(ExpCellFilter, 3.288585), (FrechetCellFilter, 3.291071)])
@pytest.mark.parametrize(("cell_filter", "expected_a"), [(ExpCellFilter, 3.288585), (FrechetCellFilter, 3.291072)])
def test_relax_calc_many(Li2O: Structure, M3GNetCalc: M3GNetCalculator, cell_filter: Filter, expected_a: float) -> None:
relax_calc = RelaxCalc(M3GNetCalc, optimizer="FIRE", cell_filter=cell_filter)
results = list(relax_calc.calc_many([Li2O] * 2))
Expand Down

0 comments on commit 2e3b2c3

Please sign in to comment.