Skip to content

Commit

Permalink
MRCC recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
benshi97 committed Jan 10, 2025
1 parent 89f8553 commit 0ff08c4
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/core/recipes/mrcc_recipes/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

from pathlib import Path

import pytest

FILE_DIR = Path(__file__).parent
MRCC_DIR = Path(FILE_DIR, "mrcc_run")


def mock_execute(self, directory, *args, **kwargs):
import gzip

with (
gzip.open(MRCC_DIR / "mrcc.out.gz", "rb") as f,
open(Path(directory, "mrcc.out"), "wb") as out,
):
out.write(f.read())


@pytest.fixture(autouse=True)
def patch_execute(monkeypatch):
from quacc.calculators.mrcc.mrcc import MrccTemplate

monkeypatch.setattr(MrccTemplate, "execute", mock_execute)
Binary file not shown.
108 changes: 108 additions & 0 deletions tests/core/recipes/mrcc_recipes/test_mrcc_recipes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from __future__ import annotations

from pathlib import Path

import pytest
from ase import Atoms

from quacc import change_settings
from quacc.recipes.mrcc._base import prep_calculator, run_and_summarize
from quacc.recipes.mrcc.core import static_job

FILE_DIR = Path(__file__).parent


def test_static_job(tmp_path):
atoms = Atoms("H2O", positions=[[1.0, 0.0, 0.0], [2.0, 0.0, 0.0], [3.0, 0.0, 0.0]])
with change_settings({"RESULTS_DIR": tmp_path}):
output = static_job(
atoms,
charge=0,
spin_multiplicity=1,
method="SCAN",
basis="def2-TZVP",
calc="PBE",
)
assert output["natoms"] == len(atoms)
assert output["parameters"]["basis"] == "def2-TZVP"
assert output["parameters"]["calc"] == "PBE"
assert output["parameters"]["symm"] == "off"
assert output["parameters"]["charge"] == 0
assert output["parameters"]["mult"] == 1
assert output["spin_multiplicity"] == 1
assert output["charge"] == 0
assert output["results"]["energy"] == pytest.approx(-2061.4010013440234)

# Check if it runs without specifying anything besides atoms
atoms = Atoms("H2O", positions=[[1.0, 0.0, 0.0], [2.0, 0.0, 0.0], [3.0, 0.0, 0.0]])
with change_settings({"RESULTS_DIR": tmp_path}):
output = static_job(atoms)

assert output["results"]["energy"] == pytest.approx(-2061.4010013440234)


def test_run_and_summarize(tmp_path):
atoms = Atoms("H2O", positions=[[1.0, 0.0, 0.0], [2.0, 0.0, 0.0], [3.0, 0.0, 0.0]])

with change_settings({"RESULTS_DIR": tmp_path}):
output = run_and_summarize(
atoms,
charge=0,
spin_multiplicity=1,
default_inputs={"calc": "PBE", "basis": "def2-tzvp", "symm": "off"},
)
assert output["natoms"] == len(atoms)
assert output["parameters"]["basis"] == "def2-tzvp"
assert output["parameters"]["calc"] == "PBE"
assert output["parameters"]["charge"] == 0
assert output["parameters"]["mult"] == 1
assert output["spin_multiplicity"] == 1
assert output["charge"] == 0
assert output["results"]["energy"] == pytest.approx(-2061.4010013440234)


def test_prep_calculator():
with pytest.raises(
ValueError,
match="For spin_multiplicity > 1, scftype keyword must be specified in mrccinput",
):
calc = prep_calculator(
spin_multiplicity=2,
default_inputs={"calc": "PBE", "basis": "def2-tzvp", "symm": "off"},
)

with pytest.raises(
ValueError,
match="For spin_multiplicity > 1, scftype must not be set to RHF or RKS",
):
calc = prep_calculator(
spin_multiplicity=2,
default_inputs={
"calc": "HF",
"basis": "def2-tzvp",
"symm": "off",
"scftype": "RHF",
},
)

calc = prep_calculator(
charge=2,
spin_multiplicity=1,
default_inputs={"calc": "HF", "basis": "def2-tzvp"},
input_swaps={
"calc": "PBE",
"basis": "def2-SVP",
"dfbasis_scf": """atomtype
H: def2-SVP
O: def2-SVP""",
},
)
ref_parameters = {
"calc": "PBE",
"basis": "def2-SVP",
"dfbasis_scf": "atomtype\nH: def2-SVP\nO: def2-SVP",
"charge": 2,
"mult": 1,
}

assert calc.parameters == ref_parameters

0 comments on commit 0ff08c4

Please sign in to comment.