Skip to content

Commit

Permalink
start 5 modes testing
Browse files Browse the repository at this point in the history
  • Loading branch information
loriab committed Sep 24, 2024
1 parent 3e1de18 commit 37bb361
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
#if: false
run: |
conda remove qcelemental --force
python -m pip install 'git+https://github.com/loriab/QCElemental.git@csse_pyd2_shimclasses' --no-deps
python -m pip install 'git+https://github.com/loriab/QCElemental.git@loriab:csse_pyd2_converterclasses' --no-deps
# note: conda remove --force, not mamba remove --force b/c https://github.com/mamba-org/mamba/issues/412
# alt. is micromamba but not yet ready for setup-miniconda https://github.com/conda-incubator/setup-miniconda/issues/75
Expand Down
34 changes: 23 additions & 11 deletions qcengine/programs/tests/test_ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

import qcengine as qcng
from qcengine.programs.tests.test_dftd3_mp2d import eneyne_ne_qcschemamols
from qcengine.testing import using
from qcengine.testing import checkver_and_convert, schema_versions, using


@pytest.fixture
def hene():
smol = """
def hene_data():
return """
0 1
He 0 0 0
@Ne 2.5 0 0
nocom
noreorient
"""
return qcel.models.Molecule.from_data(smol)


@pytest.mark.parametrize("driver", ["energy", "gradient"])
Expand All @@ -39,15 +38,20 @@ def hene():
pytest.param("psi4", "aug-cc-pvdz", {"scf_type": "direct"}, marks=using("psi4")),
],
)
def test_simple_ghost(driver, program, basis, keywords, hene):
def test_simple_ghost(driver, program, basis, keywords, hene_data, schema_versions, request):
models, models_out = schema_versions
hene = models.Molecule.from_data(hene_data)

resi = {"molecule": hene, "driver": driver, "model": {"method": "hf", "basis": basis}, "keywords": keywords}

if program == "gamess":
with pytest.raises(qcng.exceptions.InputError) as e:
qcng.compute(resi, program, raise_error=True, return_dict=True)
pytest.xfail("no ghosts with gamess")

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

assert res["driver"] == driver
assert "provenance" in res
Expand Down Expand Up @@ -166,7 +170,9 @@ def test_simple_ghost(driver, program, basis, keywords, hene):
),
],
)
def test_tricky_ghost(driver, qcprog, subject, basis, keywords):
def test_tricky_ghost(driver, qcprog, subject, basis, keywords, schema_versions, request):
models, models_out = schema_versions

dmol = eneyne_ne_qcschemamols()["eneyne"][subject]
# Freeze the input orientation so that output arrays are aligned to input
# and all programs match gradient.
Expand All @@ -178,13 +184,13 @@ def test_tricky_ghost(driver, qcprog, subject, basis, keywords):
# to the in_mol vs. calc_mol aligner. Gradients don't change much
# w/symm geometry but enough that the symmetrizer must be defeated.
keywords["geometry__autosym"] = "1d-4"
kmol = qcel.models.Molecule(**dmol)
kmol = models.Molecule(**dmol)
ref = bimol_ref["eneyne"]

assert len(kmol.symbols) == ref["natom"][subject]
assert sum([int(at) for at in kmol.real]) == ref["nreal"][subject]

atin = qcel.models.AtomicInput(
atin = models.AtomicInput(
**{"molecule": kmol, "model": {"method": "mp2", "basis": basis}, "driver": driver, "keywords": keywords}
)

Expand All @@ -193,7 +199,9 @@ def test_tricky_ghost(driver, qcprog, subject, basis, keywords):
res = qcng.compute(atin, qcprog, raise_error=True)
pytest.xfail("no ghosts with gamess")

atin = checkver_and_convert(atin, request.node.name, "pre")
atres = qcng.compute(atin, qcprog)
atres = checkver_and_convert(atres, request.node.name, "post")
pprint.pprint(atres.dict(), width=200)

assert compare_values(
Expand Down Expand Up @@ -261,8 +269,10 @@ def test_tricky_ghost(driver, qcprog, subject, basis, keywords):
),
],
)
def test_atom_labels(qcprog, basis, keywords):
kmol = qcel.models.Molecule.from_data(
def test_atom_labels(qcprog, basis, keywords, schema_versions, request):
models, models_out = schema_versions

kmol = models.Molecule.from_data(
"""
H 0 0 0
H5 5 0 0
Expand All @@ -275,11 +285,13 @@ def test_atom_labels(qcprog, basis, keywords):
assert compare(["H", "H", "H", "H"], kmol.symbols, "elem")
assert compare(["", "5", "_other", "_4sq"], kmol.atom_labels, "elbl")

atin = qcel.models.AtomicInput(
atin = models.AtomicInput(
**{"molecule": kmol, "model": {"method": "mp2", "basis": basis}, "driver": "energy", "keywords": keywords}
)

atin = checkver_and_convert(atin, request.node.name, "pre")
atres = qcng.compute(atin, qcprog)
atres = checkver_and_convert(atres, request.node.name, "post")
pprint.pprint(atres.dict(), width=200)

nre = 1.0828427
Expand Down
49 changes: 40 additions & 9 deletions qcengine/programs/tests/test_nwchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from qcelemental.testing import compare_values

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

# Molecule where autoz fails
_auto_z_problem = xyz = """C 15.204188380000 -3.519180270000 -10.798726560000
Expand Down Expand Up @@ -48,8 +48,8 @@


@pytest.fixture
def nh2():
smol = """
def nh2_data():
return """
# R=1.008 #A=105.0
0 2
N 0.000000000000000 0.000000000000000 -0.145912918634892
Expand All @@ -58,14 +58,19 @@ def nh2():
units au
symmetry c1
"""
return qcel.models.Molecule.from_data(smol)


@using("nwchem")
def test_b3lyp(nh2):
def test_b3lyp(nh2_data, schema_versions, request):
models, models_out = schema_versions
nh2 = models.Molecule.from_data(nh2_data)

# Run NH2
resi = {"molecule": nh2, "driver": "energy", "model": {"method": "b3lyp", "basis": "3-21g"}}

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

# Make sure the calculation completed successfully
assert compare_values(-55.554037, res["return_result"], atol=1e-3)
Expand All @@ -86,9 +91,16 @@ def test_b3lyp(nh2):


@using("nwchem")
def test_hess(nh2):
def test_hess(nh2_data, schema_versions, request):
models, models_out = schema_versions
nh2 = models.Molecule.from_data(nh2_data)

resi = {"molecule": nh2, "driver": "hessian", "model": {"method": "b3lyp", "basis": "3-21g"}}

resi = checkver_and_convert(resi, request.node.name, "pre")
res = qcng.compute(resi, "nwchem", raise_error=True, return_dict=False)
res = checkver_and_convert(res, request.node.name, "post")

assert compare_values(-3.5980754370e-02, res.return_result[0, 0], atol=1e-3)
assert compare_values(0, res.return_result[1, 0], atol=1e-3)
assert compare_values(0.018208307756, res.return_result[3, 0], atol=1e-3)
Expand All @@ -98,27 +110,40 @@ def test_hess(nh2):
shifted_nh2, _ = nh2.scramble(do_shift=False, do_mirror=False, do_rotate=True, do_resort=False)

resi["molecule"] = shifted_nh2

resi = checkver_and_convert(resi, request.node.name, "pre")
res_shifted = qcng.compute(resi, "nwchem", raise_error=True, return_dict=False)
res_shifted = checkver_and_convert(res_shifted, request.node.name, "post")

assert not np.allclose(res.return_result, res_shifted.return_result, atol=1e-8)
assert np.isclose(np.linalg.det(res.return_result), np.linalg.det(res_shifted.return_result))


@using("nwchem")
def test_gradient(nh2):
def test_gradient(nh2_data, schema_versions, request):
models, models_out = schema_versions
nh2 = models.Molecule.from_data(nh2_data)

resi = {
"molecule": nh2,
"driver": "gradient",
"model": {"method": "b3lyp", "basis": "3-21g"},
"keywords": {"dft__convergence__gradient": "1e-6"},
}
resi = checkver_and_convert(resi, request.node.name, "pre")
res = qcng.compute(resi, "nwchem", raise_error=True, return_dict=True)
res = checkver_and_convert(res, request.node.name, "post")

assert compare_values(4.22418267e-2, res["return_result"][2], atol=1e-7) # Beyond accuracy of NWChem stdout

# Rotate the molecule and verify that the gradient changes
shifted_nh2, _ = nh2.scramble(do_shift=False, do_mirror=False, do_rotate=True, do_resort=False)

resi["molecule"] = shifted_nh2

resi = checkver_and_convert(resi, request.node.name, "pre")
res_shifted = qcng.compute(resi, "nwchem", raise_error=True, return_dict=True)
res = checkver_and_convert(res, request.node.name, "post")

assert not compare_values(4.22418267e-2, res_shifted["return_result"][2], atol=1e-7)

Expand Down Expand Up @@ -150,15 +175,18 @@ def h20():


@using("nwchem")
def test_dipole(h20):
def test_dipole(h20, schema_versions, request):
# Run NH2
resi = {
"molecule": h20,
"driver": "properties",
"model": {"method": "dft", "basis": "3-21g"},
"keywords": {"dft__xc": "b3lyp", "property__dipole": True},
}

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

# Make sure the calculation completed successfully
assert compare_values(-75.764944, res["return_result"], atol=1e-3)
Expand Down Expand Up @@ -194,15 +222,18 @@ def h20v2():


@using("nwchem")
def test_homo_lumo(h20v2):
def test_homo_lumo(h20v2, schema_versions, request):
# Run NH2
resi = {
"molecule": h20v2,
"driver": "energy",
"model": {"method": "dft", "basis": "3-21g"},
"keywords": {"dft__xc": "b3lyp"},
}

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

# Make sure the calculation completed successfully
assert compare_values(-75.968095, res["return_result"], atol=1e-3)
Expand Down
33 changes: 23 additions & 10 deletions qcengine/programs/tests/test_standard_suite_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
from qcelemental.testing import compare_values

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


@pytest.fixture
def h2o():
smol = """
def h2o_data():
return """
# R=0.958 A=104.5
H 0.000000000000 1.431430901356 0.984293362719
O 0.000000000000 0.000000000000 -0.124038860300
H 0.000000000000 -1.431430901356 0.984293362719
units au
"""
return qcel.models.Molecule.from_data(smol)


@pytest.fixture
def nh2():
smol = """
def nh2_data():
return """
# R=1.008 #A=105.0
0 2
N 0.000000000000000 0.000000000000000 -0.145912918634892
Expand All @@ -29,7 +28,6 @@ def nh2():
units au
symmetry c1
"""
return qcel.models.Molecule.from_data(smol)


@pytest.mark.parametrize(
Expand All @@ -53,14 +51,19 @@ def nh2():
pytest.param("terachem_pbs", "aug-cc-pvdz", {}, marks=using("terachem_pbs")),
],
)
def test_sp_hf_rhf(program, basis, keywords, h2o):
def test_sp_hf_rhf(program, basis, keywords, h2o_data, schema_versions, request):
"""cfour/sp-rhf-hf/input.dat
#! single point HF/adz on water
"""
models, models_out = schema_versions
h2o = models.Molecule.from_data(h2o_data)

resi = {"molecule": h2o, "driver": "energy", "model": {"method": "hf", "basis": basis}, "keywords": keywords}

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

assert res["driver"] == "energy"
assert "provenance" in res
Expand Down Expand Up @@ -103,10 +106,15 @@ def test_sp_hf_rhf(program, basis, keywords, h2o):
pytest.param("turbomole", "aug-cc-pVDZ", {}, marks=using("turbomole")),
],
)
def test_sp_hf_uhf(program, basis, keywords, nh2):
def test_sp_hf_uhf(program, basis, keywords, nh2_data, schema_versions, request):
models, models_out = schema_versions

nh2 = models.Molecule.from_data(nh2_data)
resi = {"molecule": nh2, "driver": "energy", "model": {"method": "hf", "basis": basis}, "keywords": keywords}

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

assert res["driver"] == "energy"
assert "provenance" in res
Expand Down Expand Up @@ -142,10 +150,15 @@ def test_sp_hf_uhf(program, basis, keywords, nh2):
pytest.param("qchem", "aug-cc-pvdz", {"UNRESTRICTED": False}, marks=using("qchem")),
],
)
def test_sp_hf_rohf(program, basis, keywords, nh2):
def test_sp_hf_rohf(program, basis, keywords, nh2_data, schema_versions, request):
models, models_out = schema_versions

nh2 = models.Molecule.from_data(nh2_data)
resi = {"molecule": nh2, "driver": "energy", "model": {"method": "hf", "basis": basis}, "keywords": keywords}

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

assert res["driver"] == "energy"
assert "provenance" in res
Expand Down
7 changes: 5 additions & 2 deletions qcengine/stock_mols.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@
}


def get_molecule(name):
def get_molecule(name, *, return_dict: bool = False):
"""
Returns a QC JSON representation of a test molecule.
"""
if name not in _test_mols:
raise KeyError("Molecule name '{}' not found".format(name))

return Molecule(**copy.deepcopy(_test_mols[name]))
if return_dict:
return copy.deepcopy(_test_mols[name])
else:
return Molecule(**copy.deepcopy(_test_mols[name]))
Loading

0 comments on commit 37bb361

Please sign in to comment.