Skip to content

Commit

Permalink
sdftd3
Browse files Browse the repository at this point in the history
  • Loading branch information
loriab committed Sep 26, 2024
1 parent a627ee4 commit 4f17724
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 52 deletions.
13 changes: 9 additions & 4 deletions qcengine/programs/tests/test_mrchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def h2o(schema_versions):


@pytest.fixture
def fh():
return qcel.models.Molecule(
def fh(schema_versions):
models, _ = schema_versions
return models.Molecule(
geometry=[[0.000000000000, 0.000000000000, -1.642850273986], [0.000000000000, 0.000000000000, 0.087149726014]],
symbols=["H", "F"],
fix_com=True,
Expand Down Expand Up @@ -105,13 +106,15 @@ def test_dipole(h2o, schema_versions, request):


@using("mrchem")
def test_gradient(fh):
def test_gradient(fh, schema_versions, request):
models, _ = schema_versions

mr_kws = {
"world_prec": 1.0e-3,
"world_size": 6,
}

inp = qcel.models.AtomicInput(
inp = models.AtomicInput(
molecule=fh,
driver="gradient",
model={
Expand All @@ -120,7 +123,9 @@ def test_gradient(fh):
keywords=mr_kws,
)

inp = checkver_and_convert(inp, request.node.name, "pre")
res = qcng.compute(inp, "mrchem", raise_error=True, return_dict=True)
res = checkver_and_convert(res, request.node.name, "post")

# Make sure the calculation completed successfully
assert compare_values(
Expand Down
58 changes: 38 additions & 20 deletions qcengine/programs/tests/test_sdftd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@
import qcelemental as qcel

import qcengine as qcng
from qcengine.testing import using
from qcengine.testing import checkver_and_convert, schema_versions, using


@using("s-dftd3")
def test_dftd3_task_b97m_m01():
def test_dftd3_task_b97m_m01(schema_versions, request):
models, _ = schema_versions

thr = 1.0e-8

return_result = -0.05879001214961249

atomic_input = qcel.models.AtomicInput(
molecule=qcng.get_molecule("mindless-01"),
atomic_input = models.AtomicInput(
molecule=models.Molecule(**qcng.get_molecule("mindless-01", return_dict=True)),
model={"method": "b97m"},
driver="energy",
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post")

print(atomic_result.return_result)
assert atomic_result.success
Expand All @@ -45,28 +48,32 @@ def test_dftd3_task_b97m_m01():
],
ids=["d3bj", "d3zero", "d3mbj", "d3mzero", "d3op"],
)
def test_dftd3_task_pbe_m02(inp):
def test_dftd3_task_pbe_m02(inp, schema_versions, request):
models, _ = schema_versions

# return to 1.0e-8 after https://github.com/MolSSI/QCEngine/issues/370
thr = 1.0e-7

return_result = inp["return_result"]

atomic_input = qcel.models.AtomicInput(
molecule=qcng.get_molecule("mindless-02"),
atomic_input = models.AtomicInput(
molecule=models.Molecule(**qcng.get_molecule("mindless-02", return_dict=True)),
model={"method": "pbe"},
keywords={"level_hint": inp["level_hint"]},
driver="energy",
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post")

assert atomic_result.success
assert pytest.approx(atomic_result.return_result, abs=thr) == return_result


@using("s-dftd3")
def test_dftd3_task_tpss_m02():
def test_dftd3_task_tpss_m02(schema_versions, request):
models, _ = schema_versions

thr = 1.0e-8

Expand All @@ -91,8 +98,8 @@ def test_dftd3_task_tpss_m02():
]
)

atomic_input = qcel.models.AtomicInput(
molecule=qcng.get_molecule("mindless-02"),
atomic_input = models.AtomicInput(
molecule=models.Molecule(**qcng.get_molecule("mindless-02", return_dict=True)),
model={"method": ""},
keywords={
"level_hint": "d3mbj",
Expand All @@ -105,14 +112,17 @@ def test_dftd3_task_tpss_m02():
driver="gradient",
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post")

assert atomic_result.success
assert pytest.approx(atomic_result.return_result, abs=thr) == return_result


@using("s-dftd3")
def test_dftd3_task_r2scan_m03():
def test_dftd3_task_r2scan_m03(schema_versions, request):
models, _ = schema_versions

thr = 1.0e-8

Expand All @@ -137,44 +147,50 @@ def test_dftd3_task_r2scan_m03():
]
)

atomic_input = qcel.models.AtomicInput(
molecule=qcng.get_molecule("mindless-03"),
atomic_input = models.AtomicInput(
molecule=models.Molecule(**qcng.get_molecule("mindless-03", return_dict=True)),
keywords={"level_hint": "d3bj"},
driver="gradient",
model={"method": "r2scan"},
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post")

assert atomic_result.success
assert pytest.approx(return_result, abs=thr) == atomic_result.return_result
assert pytest.approx(atomic_result.return_result, abs=thr) == return_result


@using("s-dftd3")
def test_dftd3_task_unknown_method():
def test_dftd3_task_unknown_method(schema_versions, request):
models, models_out = schema_versions

atomic_input = qcel.models.AtomicInput(
molecule=qcng.get_molecule("water"),
atomic_input = models.AtomicInput(
molecule=models.Molecule(**qcng.get_molecule("water", return_dict=True)),
keywords={"level_hint": "d3zero"},
model={"method": "non-existent-method"},
driver="energy",
)
error = qcel.models.ComputeError(
error = models_out.ComputeError(
error_type="input error", error_message="No entry for 'non-existent-method' present"
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post", vercheck=False, cast_dict_as="FailedOperation")

print(atomic_result.error)
assert not atomic_result.success
assert atomic_result.error == error


@using("s-dftd3")
def test_dftd3_task_cold_fusion():
def test_dftd3_task_cold_fusion(schema_versions, request):
models, models_out = schema_versions

atomic_input = qcel.models.AtomicInput(
atomic_input = models.AtomicInput(
molecule={
"symbols": ["Li", "Li", "Li", "Li"],
"geometry": [
Expand All @@ -189,12 +205,14 @@ def test_dftd3_task_cold_fusion():
model={"method": "pbe"},
driver="energy",
)
error = qcel.models.ComputeError(
error = models_out.ComputeError(
error_type="input error",
error_message="Too close interatomic distances found",
)

atomic_input = checkver_and_convert(atomic_input, request.node.name, "pre")
atomic_result = qcng.compute(atomic_input, "s-dftd3")
atomic_result = checkver_and_convert(atomic_result, request.node.name, "post", vercheck=False)

print(atomic_result.error)
assert not atomic_result.success
Expand Down
Loading

0 comments on commit 4f17724

Please sign in to comment.