Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test file copying #306

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 55 additions & 184 deletions tests/qchem/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def _check_equivalent_inputs(self, input1, input2):
def test_unable_to_determine_lamda(self):
for ii in range(2):
shutil.copyfile(
os.path.join(TEST_DIR, "unable_to_determine_lamda.qin." + str(ii)),
os.path.join(SCR_DIR, "unable_to_determine_lamda.qin." + str(ii)),
f"{TEST_DIR}/unable_to_determine_lamda.qin.{ii}",
f"{SCR_DIR}/unable_to_determine_lamda.qin.{ii}",
)
shutil.copyfile(
os.path.join(TEST_DIR, "unable_to_determine_lamda.qout." + str(ii)),
os.path.join(SCR_DIR, "unable_to_determine_lamda.qout." + str(ii)),
f"{TEST_DIR}/unable_to_determine_lamda.qout.{ii}",
f"{SCR_DIR}/unable_to_determine_lamda.qout.{ii}",
)

handler = QChemErrorHandler(
Expand All @@ -72,12 +72,12 @@ def test_unable_to_determine_lamda(self):
def test_linear_dependent_basis_and_FileMan(self):
for ii in range(1, 3):
shutil.copyfile(
os.path.join(TEST_DIR, "unable_to_determine_lamda.qin." + str(ii)),
os.path.join(SCR_DIR, "unable_to_determine_lamda.qin." + str(ii)),
f"{TEST_DIR}/unable_to_determine_lamda.qin.{ii}",
f"{SCR_DIR}/unable_to_determine_lamda.qin.{ii}",
)
shutil.copyfile(
os.path.join(TEST_DIR, "unable_to_determine_lamda.qout." + str(ii)),
os.path.join(SCR_DIR, "unable_to_determine_lamda.qout." + str(ii)),
f"{TEST_DIR}/unable_to_determine_lamda.qout.{ii}",
f"{SCR_DIR}/unable_to_determine_lamda.qout.{ii}",
)

handler = QChemErrorHandler(
Expand All @@ -92,14 +92,8 @@ def test_linear_dependent_basis_and_FileMan(self):

def test_failed_to_transform(self):
for ii in range(2):
shutil.copyfile(
os.path.join(TEST_DIR, "qunino_vinyl.qin." + str(ii)),
os.path.join(SCR_DIR, "qunino_vinyl.qin." + str(ii)),
)
shutil.copyfile(
os.path.join(TEST_DIR, "qunino_vinyl.qout." + str(ii)),
os.path.join(SCR_DIR, "qunino_vinyl.qout." + str(ii)),
)
shutil.copyfile(f"{TEST_DIR}/qunino_vinyl.qin.{ii}", f"{SCR_DIR}/qunino_vinyl.qin.{ii}")
shutil.copyfile(f"{TEST_DIR}/qunino_vinyl.qout.{ii}", f"{SCR_DIR}/qunino_vinyl.qout.{ii}")

handler = QChemErrorHandler(input_file="qunino_vinyl.qin.0", output_file="qunino_vinyl.qout.0")
handler.check()
Expand All @@ -113,14 +107,8 @@ def test_failed_to_transform(self):

def test_scf_failed_to_converge(self):
for ii in range(3):
shutil.copyfile(
os.path.join(TEST_DIR, "crowd_gradient.qin." + str(ii)),
os.path.join(SCR_DIR, "crowd_gradient.qin." + str(ii)),
)
shutil.copyfile(
os.path.join(TEST_DIR, "crowd_gradient.qout." + str(ii)),
os.path.join(SCR_DIR, "crowd_gradient.qout." + str(ii)),
)
shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.{ii}", f"{SCR_DIR}/crowd_gradient.qin.{ii}")
shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qout.{ii}", f"{SCR_DIR}/crowd_gradient.qout.{ii}")

handler = QChemErrorHandler(input_file="crowd_gradient.qin.0", output_file="crowd_gradient.qout.0")
handler.check()
Expand All @@ -130,9 +118,9 @@ def test_scf_failed_to_converge(self):
self._check_equivalent_inputs("crowd_gradient.qin.0", "crowd_gradient.qin.1")

def test_scf_failed_to_converge_gdm_add_cycles(self):
shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qin"), os.path.join(SCR_DIR, "mol.qin"))
shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qin.1"), os.path.join(SCR_DIR, "mol.qin.1"))
shutil.copyfile(os.path.join(TEST_DIR, "gdm_add_cycles/mol.qout"), os.path.join(SCR_DIR, "mol.qout"))
shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qin", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qin.1", f"{SCR_DIR}/mol.qin.1")
shutil.copyfile(f"{TEST_DIR}/gdm_add_cycles/mol.qout", f"{SCR_DIR}/mol.qout")

handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
Expand All @@ -142,18 +130,9 @@ def test_scf_failed_to_converge_gdm_add_cycles(self):
self._check_equivalent_inputs("mol.qin", "mol.qin.1")

def test_advanced_scf_failed_to_converge_1(self):
shutil.copyfile(
os.path.join(TEST_DIR, "diis_guess_always/mol.qin.0"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "diis_guess_always/mol.qout.0"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "diis_guess_always/mol.qin.1"),
os.path.join(SCR_DIR, "mol.qin.1"),
)
shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qin.0", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qout.0", f"{SCR_DIR}/mol.qout")
shutil.copyfile(f"{TEST_DIR}/diis_guess_always/mol.qin.1", f"{SCR_DIR}/mol.qin.1")

handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
Expand All @@ -163,18 +142,9 @@ def test_advanced_scf_failed_to_converge_1(self):
self._check_equivalent_inputs("mol.qin", "mol.qin.1")

def test_scf_into_opt(self):
shutil.copyfile(
os.path.join(TEST_DIR, "scf_into_opt/mol.qin.0"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "scf_into_opt/mol.qout.0"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "scf_into_opt/mol.qin.1"),
os.path.join(SCR_DIR, "mol.qin.1"),
)
shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qin.0", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qout.0", f"{SCR_DIR}/mol.qout")
shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qin.1", f"{SCR_DIR}/mol.qin.1")

handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
Expand All @@ -183,29 +153,17 @@ def test_scf_into_opt(self):
assert dct["actions"] == [{"scf_algorithm": "gdm"}, {"max_scf_cycles": "500"}]
self._check_equivalent_inputs("mol.qin", "mol.qin.1")

shutil.copyfile(
os.path.join(TEST_DIR, "scf_into_opt/mol.qout.1"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/scf_into_opt/mol.qout.1", f"{SCR_DIR}/mol.qout")

handler.check()
dct = handler.correct()
assert dct["errors"] == ["out_of_opt_cycles"]
assert dct["actions"] == [{"molecule": "molecule_from_last_geometry"}]

def test_custom_smd(self):
shutil.copyfile(
os.path.join(TEST_DIR, "custom_smd/mol.qin.0"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "custom_smd/mol.qout.0"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "custom_smd/mol.qin.1"),
os.path.join(SCR_DIR, "mol.qin.1"),
)
shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qin.0", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qout.0", f"{SCR_DIR}/mol.qout")
shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qin.1", f"{SCR_DIR}/mol.qin.1")

handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
Expand All @@ -214,29 +172,17 @@ def test_custom_smd(self):
assert dct["actions"] == [{"scf_algorithm": "gdm"}, {"max_scf_cycles": "500"}]
self._check_equivalent_inputs("mol.qin", "mol.qin.1")

shutil.copyfile(
os.path.join(TEST_DIR, "custom_smd/mol.qout.1"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/custom_smd/mol.qout.1", f"{SCR_DIR}/mol.qout")

handler.check()
dct = handler.correct()
assert dct["errors"] == []
assert dct["actions"] is None

def test_out_of_opt_cycles(self):
shutil.copyfile(
os.path.join(TEST_DIR, "crowd_gradient.qin.2"),
os.path.join(SCR_DIR, "crowd_gradient.qin.2"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "crowd_gradient.qout.2"),
os.path.join(SCR_DIR, "crowd_gradient.qout.2"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "crowd_gradient.qin.3"),
os.path.join(SCR_DIR, "crowd_gradient.qin.3"),
)
shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.2", f"{SCR_DIR}/crowd_gradient.qin.2")
shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qout.2", f"{SCR_DIR}/crowd_gradient.qout.2")
shutil.copyfile(f"{TEST_DIR}/crowd_gradient.qin.3", f"{SCR_DIR}/crowd_gradient.qin.3")

handler = QChemErrorHandler(input_file="crowd_gradient.qin.2", output_file="crowd_gradient.qout.2")
handler.check()
Expand All @@ -246,57 +192,30 @@ def test_out_of_opt_cycles(self):
self._check_equivalent_inputs("crowd_gradient.qin.2", "crowd_gradient.qin.3")

def test_advanced_out_of_opt_cycles(self):
shutil.copyfile(
os.path.join(TEST_DIR, "2564_complete/error1/mol.qin"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "2564_complete/error1/mol.qout"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "2564_complete/mol.qin.opt_0"),
os.path.join(SCR_DIR, "mol.qin.opt_0"),
)
shutil.copyfile(f"{TEST_DIR}/2564_complete/error1/mol.qin", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/2564_complete/error1/mol.qout", f"{SCR_DIR}/mol.qout")
shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin.opt_0")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
assert dct["errors"] == ["out_of_opt_cycles"]
assert dct["actions"] == [{"s2thresh": "16"}, {"molecule": "molecule_from_last_geometry"}]
self._check_equivalent_inputs("mol.qin.opt_0", "mol.qin")
assert handler.opt_error_history[0] == "more_bonds"
shutil.copyfile(
os.path.join(TEST_DIR, "2564_complete/mol.qin.opt_0"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "2564_complete/mol.qout.opt_0"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/2564_complete/mol.qout.opt_0", f"{SCR_DIR}/mol.qout")
handler.check()
assert handler.opt_error_history == []

def test_advanced_out_of_opt_cycles1(self):
shutil.copyfile(
os.path.join(TEST_DIR, "2620_complete/mol.qin.opt_0"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "2620_complete/mol.qout.opt_0"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/2620_complete/mol.qin.opt_0", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/2620_complete/mol.qout.opt_0", f"{SCR_DIR}/mol.qout")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
assert handler.check() is False

def test_failed_to_read_input(self):
shutil.copyfile(
os.path.join(TEST_DIR, "unable_lamda_weird.qin"),
os.path.join(SCR_DIR, "unable_lamda_weird.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "unable_lamda_weird.qout"),
os.path.join(SCR_DIR, "unable_lamda_weird.qout"),
)
shutil.copyfile(f"{TEST_DIR}/unable_lamda_weird.qin", f"{SCR_DIR}/unable_lamda_weird.qin")
shutil.copyfile(f"{TEST_DIR}/unable_lamda_weird.qout", f"{SCR_DIR}/unable_lamda_weird.qout")
handler = QChemErrorHandler(input_file="unable_lamda_weird.qin", output_file="unable_lamda_weird.qout")
handler.check()
dct = handler.correct()
Expand All @@ -305,59 +224,35 @@ def test_failed_to_read_input(self):
self._check_equivalent_inputs("unable_lamda_weird.qin.last", "unable_lamda_weird.qin")

def test_input_file_error(self):
shutil.copyfile(
os.path.join(TEST_DIR, "bad_input.qin"),
os.path.join(SCR_DIR, "bad_input.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "bad_input.qout"),
os.path.join(SCR_DIR, "bad_input.qout"),
)
shutil.copyfile(f"{TEST_DIR}/bad_input.qin", f"{SCR_DIR}/bad_input.qin")
shutil.copyfile(f"{TEST_DIR}/bad_input.qout", f"{SCR_DIR}/bad_input.qout")
handler = QChemErrorHandler(input_file="bad_input.qin", output_file="bad_input.qout")
handler.check()
dct = handler.correct()
assert dct["errors"] == ["input_file_error"]
assert dct["actions"] is None

def test_basis_not_supported(self):
shutil.copyfile(
os.path.join(TEST_DIR, "basis_not_supported.qin"),
os.path.join(SCR_DIR, "basis_not_supported.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "basis_not_supported.qout"),
os.path.join(SCR_DIR, "basis_not_supported.qout"),
)
shutil.copyfile(f"{TEST_DIR}/basis_not_supported.qin", f"{SCR_DIR}/basis_not_supported.qin")
shutil.copyfile(f"{TEST_DIR}/basis_not_supported.qout", f"{SCR_DIR}/basis_not_supported.qout")
handler = QChemErrorHandler(input_file="basis_not_supported.qin", output_file="basis_not_supported.qout")
handler.check()
dct = handler.correct()
assert dct["errors"] == ["basis_not_supported"]
assert dct["actions"] is None

def test_NLebdevPts(self):
shutil.copyfile(
os.path.join(TEST_DIR, "lebdevpts.qin"),
os.path.join(SCR_DIR, "lebdevpts.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "lebdevpts.qout"),
os.path.join(SCR_DIR, "lebdevpts.qout"),
)
shutil.copyfile(f"{TEST_DIR}/lebdevpts.qin", f"{SCR_DIR}/lebdevpts.qin")
shutil.copyfile(f"{TEST_DIR}/lebdevpts.qout", f"{SCR_DIR}/lebdevpts.qout")
handler = QChemErrorHandler(input_file="lebdevpts.qin", output_file="lebdevpts.qout")
handler.check()
dct = handler.correct()
assert dct["errors"] == ["NLebdevPts"]
assert dct["actions"] == [{"esp_surface_density": "250"}]

def test_read_error(self):
shutil.copyfile(
os.path.join(TEST_DIR, "molecule_read_error/mol.qin"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "molecule_read_error/mol.qout"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/molecule_read_error/mol.qin", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/molecule_read_error/mol.qout", f"{SCR_DIR}/mol.qout")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
Expand All @@ -366,14 +261,8 @@ def test_read_error(self):
self._check_equivalent_inputs("mol.qin.last", "mol.qin")

def test_never_called_qchem_error(self):
shutil.copyfile(
os.path.join(TEST_DIR, "mpi_error/mol.qin"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "mpi_error/mol.qout"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/mpi_error/mol.qin", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/mpi_error/mol.qout", f"{SCR_DIR}/mol.qout")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
Expand All @@ -382,14 +271,8 @@ def test_never_called_qchem_error(self):
self._check_equivalent_inputs("mol.qin.last", "mol.qin")

def test_OOS_read_hess(self):
shutil.copyfile(
os.path.join(TEST_DIR, "OOS_read_hess.qin"),
os.path.join(SCR_DIR, "mol.qin"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "OOS_read_hess.qout"),
os.path.join(SCR_DIR, "mol.qout"),
)
shutil.copyfile(f"{TEST_DIR}/OOS_read_hess.qin", f"{SCR_DIR}/mol.qin")
shutil.copyfile(f"{TEST_DIR}/OOS_read_hess.qout", f"{SCR_DIR}/mol.qout")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
Expand All @@ -399,32 +282,20 @@ def test_OOS_read_hess(self):
{"molecule": "molecule_from_last_geometry"},
{"geom_opt_hessian": "deleted"},
]
self._check_equivalent_inputs(os.path.join(TEST_DIR, "OOS_read_hess_next.qin"), "mol.qin")
self._check_equivalent_inputs(f"{TEST_DIR}/OOS_read_hess_next.qin", "mol.qin")

def test_gdm_neg_precon_error(self):
shutil.copyfile(
os.path.join(TEST_DIR, "gdm_neg_precon_error.qin.gz"),
os.path.join(SCR_DIR, "mol.qin.gz"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "gdm_neg_precon_error.qout.gz"),
os.path.join(SCR_DIR, "mol.qout.gz"),
)
shutil.copyfile(f"{TEST_DIR}/gdm_neg_precon_error.qin.gz", f"{SCR_DIR}/mol.qin.gz")
shutil.copyfile(f"{TEST_DIR}/gdm_neg_precon_error.qout.gz", f"{SCR_DIR}/mol.qout.gz")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
assert dct["errors"] == ["gdm_neg_precon_error"]
assert dct["actions"] == [{"molecule": "molecule_from_last_geometry"}]

def test_fileman_cpscf_nseg_error(self):
shutil.copyfile(
os.path.join(TEST_DIR, "fileman_cpscf.qin.gz"),
os.path.join(SCR_DIR, "mol.qin.gz"),
)
shutil.copyfile(
os.path.join(TEST_DIR, "fileman_cpscf.qout.gz"),
os.path.join(SCR_DIR, "mol.qout.gz"),
)
shutil.copyfile(f"{TEST_DIR}/fileman_cpscf.qin.gz", f"{SCR_DIR}/mol.qin.gz")
shutil.copyfile(f"{TEST_DIR}/fileman_cpscf.qout.gz", f"{SCR_DIR}/mol.qout.gz")
handler = QChemErrorHandler(input_file="mol.qin", output_file="mol.qout")
handler.check()
dct = handler.correct()
Expand Down
Loading