Skip to content

Commit

Permalink
Updates following GP's review.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwaroquiers committed Mar 27, 2024
1 parent ed41599 commit bb135c7
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 40 deletions.
1 change: 0 additions & 1 deletion docs_rst/api/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ turbomoleio
.. toctree::
:maxdepth: 4

turbomoleio
11 changes: 9 additions & 2 deletions src/turbomoleio/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def get_test_data_dir(module=None):
p = Path(module)
parts = p.parts
found_paths = []
# Depending on where we call this function (in which case module should be
# provided), we want to find the test_data directory. We do that by recursively
# looking for a path that "ends" with "/tests/test_data".
# For example if we apply it in a directory "/abc/def/ghi", it will see if it can
# find:
# 1/ /abc/def/ghi/tests/test_data, then
# 2/ /abc/def/tests/test_data, then
# 3/ /abc/tests/test_data, then
# 4/ /tests/test_data
for ii in range(len(parts), 0, -1):
test_path = Path(*parts[:ii]) / "tests" / "test_data"
if test_path.exists():
Expand All @@ -109,8 +118,6 @@ def get_tests_configs_tm_versions(test_data_dir):
"""Get the test configs for all supported tm versions."""
from monty.serialization import loadfn

from turbomoleio.testing import TM_VERSIONS

return {
tmv: loadfn(os.path.join(test_data_dir, "outputs", tmv, "tests_config.yaml"))
for tmv in TM_VERSIONS
Expand Down
6 changes: 4 additions & 2 deletions tests/integration_tests/test_aoforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@pytest.mark.integration
class TestAoforce:
@pytest.mark.parametrize("structure", structures)
def test_run_ridft_aoforce_nosym(self, structure):
def test_run_ridft_aoforce_nosym(self, structure, test_data):
dp = get_define_template("ridft")
dp["desy"] = False

Expand All @@ -42,10 +42,11 @@ def test_run_ridft_aoforce_nosym(self, structure):
structure,
"ridft_aoforce_{}_nosym".format(structure),
[ScfOutput, AoforceOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_aoforce_sym(self, structure):
def test_run_dscf_aoforce_sym(self, structure, test_data):
dp = get_define_template("dscf")
dp["desy"] = True

Expand All @@ -55,4 +56,5 @@ def test_run_dscf_aoforce_sym(self, structure):
structure,
"dscf_aoforce_{}_sym".format(structure),
[ScfOutput, AoforceOutput],
test_data=test_data,
)
85 changes: 68 additions & 17 deletions tests/integration_tests/test_dscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,33 @@
@pytest.mark.integration
class TestDscf:
@pytest.mark.parametrize("structure", structures)
def test_run_dscf(self, structure):
def test_run_dscf(self, structure, test_data):

assert run_itest(
"dscf",
get_define_template("dscf"),
structure,
"dscf_{}_std".format(structure),
ScfOutput,
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_ired(self, structure):
def test_run_dscf_ired(self, structure, test_data):
define_opt = get_define_template("dscf")
define_opt["ired"] = True

assert run_itest(
"dscf", define_opt, structure, "dscf_{}_ired".format(structure), ScfOutput
"dscf",
define_opt,
structure,
"dscf_{}_ired".format(structure),
ScfOutput,
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_hf(self, structure):
def test_run_dscf_hf(self, structure, test_data):

define_opt = get_define_template("dscf")
define_opt["method"] = "hf"
Expand All @@ -76,7 +82,12 @@ def test_run_dscf_hf(self, structure):
define_opt["title"] = None

assert run_itest(
"dscf", define_opt, structure, "dscf_{}_hf".format(structure), ScfOutput
"dscf",
define_opt,
structure,
"dscf_{}_hf".format(structure),
ScfOutput,
test_data=test_data,
)

def test_run_dscf_usemo(self, test_data):
Expand All @@ -89,9 +100,11 @@ def test_run_dscf_usemo(self, test_data):
define_opt["basis"] = "def2-SV(P)"
define_opt["usemo"] = test_data / "mo" / "mos_nh3_nosym"

assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_usemo", ScfOutput)
assert run_itest(
"dscf", define_opt, "nh3", "dscf_nh3_usemo", ScfOutput, test_data=test_data
)

def test_run_dscf_ecp_atom(self):
def test_run_dscf_ecp_atom(self, test_data):
"""
Tests the usemo functionalities with mos file
"""
Expand All @@ -101,10 +114,17 @@ def test_run_dscf_ecp_atom(self):
define_opt["basis"] = "def2-SV(P)"
define_opt["ecp_atom"] = {"N": "ecp-2-sdf"}

assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_ecp_atom", ScfOutput)
assert run_itest(
"dscf",
define_opt,
"nh3",
"dscf_nh3_ecp_atom",
ScfOutput,
test_data=test_data,
)

# TODO check if alpha/beta for usemo are needed
# def test_run_dscf_usemo_alpha(self):
# def test_run_dscf_usemo_alpha(self, test_data):
# """
# Tests the usemo functionalities with alpha and
# beta files in the case of unpaired electrons
Expand All @@ -117,7 +137,14 @@ def test_run_dscf_ecp_atom(self):
# define_opt["unpaired_electrons"] = 1
# define_opt["usemo"] = os.path.join(get_tfp(), "mo", "alpha_beta_nh3")
#
# assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_usemo_alpha", {})
# assert run_itest(
# "dscf",
# define_opt,
# "nh3",
# "dscf_nh3_usemo_alpha",
# {},
# test_data=test_data
# )

def test_run_dscf_copymo(self, test_data):
"""
Expand All @@ -129,7 +156,14 @@ def test_run_dscf_copymo(self, test_data):
define_opt["basis"] = "def2-SV(P)"
define_opt["copymo"] = test_data / "mo" / "mos_nh3"

assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_copymo_mos", ScfOutput)
assert run_itest(
"dscf",
define_opt,
"nh3",
"dscf_nh3_copymo_mos",
ScfOutput,
test_data=test_data,
)

def test_run_dscf_copymo_mos_unpaired(self, test_data):
"""
Expand All @@ -144,7 +178,12 @@ def test_run_dscf_copymo_mos_unpaired(self, test_data):
define_opt["copymo"] = test_data / "mo" / "mos_nh3"

assert run_itest(
"dscf", define_opt, "nh3", "dscf_nh3_copymo_mos_unpaired", ScfOutput
"dscf",
define_opt,
"nh3",
"dscf_nh3_copymo_mos_unpaired",
ScfOutput,
test_data=test_data,
)

def test_run_dscf_copymo_alpha_unpaired(self, test_data):
Expand All @@ -160,11 +199,16 @@ def test_run_dscf_copymo_alpha_unpaired(self, test_data):
define_opt["copymo"] = test_data / "mo" / "alpha_beta_nh3"

assert run_itest(
"dscf", define_opt, "nh3", "dscf_nh3_copymo_alpha_unpaired", ScfOutput
"dscf",
define_opt,
"nh3",
"dscf_nh3_copymo_alpha_unpaired",
ScfOutput,
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_cosmo(self, structure):
def test_run_dscf_cosmo(self, structure, test_data):

define_opt = get_define_template("dscf")
define_opt["use_cosmo"] = True
Expand All @@ -180,13 +224,20 @@ def test_run_dscf_cosmo(self, structure):
}
)
assert run_itest(
"dscf", define_opt, structure, "dscf_{}_cosmo".format(structure), ScfOutput
"dscf",
define_opt,
structure,
"dscf_{}_cosmo".format(structure),
ScfOutput,
test_data=test_data,
)

@pytest.mark.parametrize("disp", disp_corrections)
def test_run_dscf_disp(self, disp):
def test_run_dscf_disp(self, disp, test_data):

define_opt = get_define_template("dscf")
define_opt["disp"] = disp
disp_fn = "dscf_nh3_disp_{}".format("_".join(disp.split()))
assert run_itest("dscf", define_opt, "nh3", disp_fn, ScfOutput)
assert run_itest(
"dscf", define_opt, "nh3", disp_fn, ScfOutput, test_data=test_data
)
15 changes: 10 additions & 5 deletions tests/integration_tests/test_escf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@pytest.mark.integration
class TestEscf:
@pytest.mark.parametrize("structure", structures)
def test_run_ridft_escf(self, structure):
def test_run_ridft_escf(self, structure, test_data):
dp = get_define_template("ridft_escf")
dp["desy"] = True
dp["ex_all_states"] = 12
Expand All @@ -45,10 +45,11 @@ def test_run_ridft_escf(self, structure):
structure,
"ridft_escf_{}_std".format(structure),
[ScfOutput, EscfOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_escf(self, structure):
def test_run_dscf_escf(self, structure, test_data):
dp = get_define_template("dscf_escf")
dp["desy"] = False
dp["ex_all_states"] = None
Expand All @@ -60,10 +61,11 @@ def test_run_dscf_escf(self, structure):
structure,
"dscf_escf_{}_std".format(structure),
[ScfOutput, EscfOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_escf_triplet(self, structure):
def test_run_dscf_escf_triplet(self, structure, test_data):
dp = get_define_template("dscf_escf")
dp["desy"] = True
dp["ex_all_states"] = 10
Expand All @@ -75,10 +77,11 @@ def test_run_dscf_escf_triplet(self, structure):
structure,
"dscf_escf_{}_triplet".format(structure),
[ScfOutput, EscfOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_escf_charged(self, structure):
def test_run_dscf_escf_charged(self, structure, test_data):
dp = get_define_template("dscf_escf")
dp["desy"] = True
dp["ex_all_states"] = 10
Expand All @@ -90,9 +93,10 @@ def test_run_dscf_escf_charged(self, structure):
structure,
"dscf_escf_{}_charged".format(structure),
[ScfOutput, EscfOutput],
test_data=test_data,
)

def test_run_dscf_escf_set_dict(self):
def test_run_dscf_escf_set_dict(self, test_data):
"""
Tests some properties that are set with a dictionary.
Expand All @@ -119,4 +123,5 @@ def test_run_dscf_escf_set_dict(self):
"nh3_wrong_internal",
"dscf_escf_nh3_set_dict",
[ScfOutput, EscfOutput],
test_data=test_data,
)
6 changes: 4 additions & 2 deletions tests/integration_tests/test_jobex.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@pytest.mark.integration
class TestJobex:
@pytest.mark.parametrize("structure", structures)
def test_run_jobex_dscf(self, structure):
def test_run_jobex_dscf(self, structure, test_data):
dp = get_define_template("dscf")
dp["desy"] = True
dp["ired"] = True
Expand All @@ -47,10 +47,11 @@ def test_run_jobex_dscf(self, structure):
"jobex_dscf_{}_sym".format(structure),
JobexOutput,
arguments="-c 2",
test_data=test_data,
)

@pytest.mark.parametrize("structure_filename", ["graphene"])
def test_run_jobex_riper(self, structure_filepath):
def test_run_jobex_riper(self, structure_filepath, test_data):
structure_filename = os.path.basename(structure_filepath)
dp = get_define_template("ridft")
periodic = sdg("periodic", structure_filepath)
Expand All @@ -63,4 +64,5 @@ def test_run_jobex_riper(self, structure_filepath):
JobexOutput,
arguments="-c 2",
datagroups_options={"periodic": periodic, "cell": cell, "optcell": ""},
test_data=test_data,
)
12 changes: 8 additions & 4 deletions tests/integration_tests/test_relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@pytest.mark.integration
class TestRelax:
@pytest.mark.parametrize("structure", structures)
def test_run_dscf_grad_statpt(self, structure):
def test_run_dscf_grad_statpt(self, structure, test_data):
dp = get_define_template("dscf")
dp["desy"] = True
dp["ired"] = True
Expand All @@ -49,10 +49,11 @@ def test_run_dscf_grad_statpt(self, structure):
structure,
"dscf_grad_statpt_{}_sym".format(structure),
[ScfOutput, GradOutput, StatptOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_ridft_rdgrad_relax(self, structure):
def test_run_ridft_rdgrad_relax(self, structure, test_data):
dp = get_define_template("ridft")
dp["desy"] = True
dp["ired"] = True
Expand All @@ -63,10 +64,11 @@ def test_run_ridft_rdgrad_relax(self, structure):
structure,
"ridft_rdgrad_relax_{}_sym".format(structure),
[ScfOutput, GradOutput, RelaxOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_dscf_egrad_relax(self, structure):
def test_run_dscf_egrad_relax(self, structure, test_data):
dp = get_define_template("dscf_escf")
dp["desy"] = False
dp["ired"] = False
Expand All @@ -77,10 +79,11 @@ def test_run_dscf_egrad_relax(self, structure):
structure,
"dscf_escf_relax_{}_nosym".format(structure),
[ScfOutput, EgradOutput, RelaxOutput],
test_data=test_data,
)

@pytest.mark.parametrize("structure", structures)
def test_run_ridft_egrad_statpt_ex_irrep(self, structure):
def test_run_ridft_egrad_statpt_ex_irrep(self, structure, test_data):
dp = get_define_template("ridft_escf")
dp["desy"] = True
dp["ired"] = True
Expand All @@ -93,4 +96,5 @@ def test_run_ridft_egrad_statpt_ex_irrep(self, structure):
structure,
"ridft_egrad_statpt_{}_ex_irrep".format(structure),
[ScfOutput, EgradOutput, StatptOutput],
test_data=test_data,
)
Loading

0 comments on commit bb135c7

Please sign in to comment.