def test_validate_parameters(): assert validate_parameters({}) assert validate_parameters(get_define_template("dscf")) assert validate_parameters(get_define_template("ridft")) assert validate_parameters(get_define_template("dscf_escf")) assert validate_parameters(get_define_template("ridft_escf")) assert validate_parameters(get_define_template("ridft_rimp2")) assert not validate_parameters({"fake_key": 1}) # check dependency d = {"use_f12*": True} assert not validate_parameters(d) d["use_f12"] = True assert not validate_parameters(d) d["method"] = "mp2" assert validate_parameters(d) #wrong type assert not validate_parameters({"method": 1}) assert validate_parameters({"disp": "DFT-D1"}) # value not in possible options assert not validate_parameters({"disp": "wrong_value"})
def test_get_define_template(): """Testing get define template util function.""" dscf_dict = get_define_template("dscf") assert dscf_dict["basis"] == "def-SV(P)" with pytest.raises(ValueError, match=r'^Could not find template file ' r'\S*non_existing_template.yaml$'): get_define_template("non_existing_template.yaml")
def test_wrong_method(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") define_opt["method"] = "wrong_method" with temp_dir(delete_tmp_dir) as tmp_dir: with pytest.raises(DefineParameterError): self.run_define_runner(define_opt, molecule_filepath)
def test_wrong_xc_func(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") define_opt["functional"] = "pbexxxx" with temp_dir(delete_tmp_dir) as tmp_dir: with pytest.raises(DefineParameterError): self.run_define_runner(define_opt, molecule_filepath)
def test_not_converged_ired(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") define_opt["ired"] = True with temp_dir(delete_tmp_dir) as tmp_dir: with pytest.raises(DefineIredError): self.run_define_runner(define_opt, molecule_filepath)
def test_run_ridft_aoforce_nosym(self, structure): dp = get_define_template("ridft") dp["desy"] = False assert run_itest(["ridft", "aoforce"], dp, structure, "ridft_aoforce_{}_nosym".format(structure), [ScfOutput, AoforceOutput])
def test_run_dscf_aoforce_sym(self, structure): dp = get_define_template("dscf") dp["desy"] = True assert run_itest(["dscf", "aoforce"], dp, structure, "dscf_aoforce_{}_sym".format(structure), [ScfOutput, AoforceOutput])
def test_remove_last_energy(self, molecule_filepath, delete_tmp_dir): """ Tests the remove_last_energy method of Control. First runs twice an energy-grad-relax loop, then removes the last energy and runs escf. The output of escf contains the gs energy and it reads it from the energy file. The test checks that the value from the escf.log output corresponds to the first value of the energy and not to the one that should have been removed. """ with temp_dir(delete_tmp_dir) as tmp_dir: dp = get_define_template("ridft_escf") run_define_runner(define_opt=dp, mol_path=molecule_filepath) for i in range(2): run_tm("ridft") run_tm("rdgrad") run_tm("statpt") c = Control.from_file() en = c.energy.total assert len(c.energy.total) == 2 c.remove_last_energy() run_tm("escf") p = Parser.from_file("escf.log") gs_en_from_escf = p.escf_gs_total_en assert gs_en_from_escf == pytest.approx(en[0]) assert not gs_en_from_escf == pytest.approx(en[1])
def test_remove_last_gradient(self, molecule_filepath, delete_tmp_dir): """ Tests the remove_last_gradient method of Control. First runs twice an energy-grad-relax loop, then removes the last energy and runs escf. The output of escf contains the gs energy and it reads it from the energy file. The test checks that the value from the escf.log output corresponds to the first value of the energy and not to the one that should have been removed. """ with temp_dir(delete_tmp_dir) as tmp_dir: dp = get_define_template("ridft") run_define_runner(define_opt=dp, mol_path=molecule_filepath) run_tm("ridft") run_tm("rdgrad") run_tm("statpt") run_tm("ridft") run_tm("rdgrad") c = Control.from_file() g = c.gradient assert len(g.gradients) == 2 c.remove_last_gradient() run_tm("statpt") p = Parser.from_file("statpt.log") g_from_statp = p.relax_gradient_values assert np.allclose(g.norms[0], g_from_statp["norm_cartesian"]) assert not np.allclose(g.norms[1], g_from_statp["norm_cartesian"])
def test_run_ridft_escf(self, structure): dp = get_define_template("ridft_escf") dp["desy"] = True dp["ex_all_states"] = 12 assert run_itest(["ridft", "escf"], dp, structure, "ridft_escf_{}_std".format(structure), [ScfOutput, EscfOutput])
def test_generate_mo(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") with temp_dir(delete_tmp_dir) as tmp: # run the full to generate all the files self.run_define_runner(define_opt, molecule_filepath) os.remove("mos") self.run_define_runner({}, None, "mo") assert os.path.isfile("mos")
def test_run_dscf_egrad_relax(self, structure): dp = get_define_template("dscf_escf") dp["desy"] = False dp["ired"] = False assert run_itest(["dscf", "egrad", "relax"], dp, structure, "dscf_escf_relax_{}_nosym".format(structure), [ScfOutput, EgradOutput, RelaxOutput])
def test_run_ridft_rdgrad_relax(self, structure): dp = get_define_template("ridft") dp["desy"] = True dp["ired"] = True assert run_itest(["ridft", "rdgrad", "relax"], dp, structure, "ridft_rdgrad_relax_{}_sym".format(structure), [ScfOutput, GradOutput, StatptOutput])
def test_run_dscf_grad_statpt(self, structure): dp = get_define_template("dscf") dp["desy"] = True dp["ired"] = True assert run_itest(["dscf", "grad", "statpt"], dp, structure, "dscf_grad_statpt_{}_sym".format(structure), [ScfOutput, GradOutput, StatptOutput])
def test_run_ridft_fermi(self, structure): define_opt = get_define_template("ridft") define_opt["ri"] = False define_opt["rijk"] = True datagroups_options = {"fermi": "tmstrt=500 tmend=50 tmfac=0.9 hlcrt=0.2"} assert run_itest("ridft", define_opt, structure, "ridft_{}_fermi".format(structure), ScfOutput, datagroups_options=datagroups_options)
def test_run_ridft_f12x(self, structure): define_opt = get_define_template("ridft_rimp2") define_opt["use_f12"] = False define_opt["use_f12*"] = True assert run_itest(["ridft", "rimp2"], define_opt, structure, "ridft_rimp2_{}_f12*".format(structure), {})
def test_run_dscf_escf_charged(self, structure): dp = get_define_template("dscf_escf") dp["desy"] = True dp["ex_all_states"] = 10 dp["charge"] = 1 assert run_itest(["dscf", "escf"], dp, structure, "dscf_escf_{}_charged".format(structure), [ScfOutput, EscfOutput])
def test_run_dscf_escf(self, structure): dp = get_define_template("dscf_escf") dp["desy"] = False dp["ex_all_states"] = None dp["ex_irrep_states"] = {"a": 8} assert run_itest(["dscf", "escf"], dp, structure, "dscf_escf_{}_std".format(structure), [ScfOutput, EscfOutput])
def test_run_dscf_escf_triplet(self, structure): dp = get_define_template("dscf_escf") dp["desy"] = True dp["ex_all_states"] = 10 dp["ex_multi"] = "triplet" assert run_itest(["dscf", "escf"], dp, structure, "dscf_escf_{}_triplet".format(structure), [ScfOutput, EscfOutput])
def test_run_ridft_adc2(self): define_opt = get_define_template("ridft_rimp2") define_opt["method"] = "adc(2)" define_opt["ex_mp2"] = {"a1": [1, 10], "a2": [3, 10]} define_opt["maxiter"] = 100 define_opt["maxcor"] = 400 assert run_itest(["ridft", "rimp2"], define_opt, "nh3", "ridft_rimp2_nh3_adc2", [ScfOutput, None])
def test_run_ridft_egrad_statpt_ex_irrep(self, structure): dp = get_define_template("ridft_escf") dp["desy"] = True dp["ired"] = True dp["ex_all_states"] = None dp["ex_irrep_states"] = {"a1": 1} assert run_itest(["ridft", "egrad", "statpt"], dp, structure, "ridft_egrad_statpt_{}_ex_irrep".format(structure), [ScfOutput, EgradOutput, RelaxOutput])
def test_timeout(self, molecule_filepath, delete_tmp_dir): """ Tests an example where expect fails and a DefineExpectError is raised because of TIMEOUT. """ define_opt = get_define_template("dscf") define_opt["scfconv"] = 1e-5 with temp_dir(delete_tmp_dir) as tmp_dir: with pytest.raises(DefineExpectError): self.run_define_runner(define_opt, molecule_filepath)
def test_run_jobex_dscf(self, structure): dp = get_define_template("dscf") dp["desy"] = True dp["ired"] = True assert run_itest("jobex", dp, structure, "jobex_dscf_{}_sym".format(structure), JobexOutput, arguments="-c 2")
def test_run_dscf_copymo(self): """ Tests the copy functionalities with mos file """ define_opt = get_define_template("dscf") define_opt["basis"] = "def2-SV(P)" define_opt["copymo"] = os.path.join(get_tfp(), "mo", "mos_nh3") assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_copymo_mos", ScfOutput)
def test_eof(self, molecule_filepath, delete_tmp_dir): """ Tests an example where expect fails and a DefineExpectError is raised because of EOF. """ define_opt = get_define_template("ridft_rimp2") define_opt["method"] = "ccsdt" define_opt["mp2energy"] = False with temp_dir(delete_tmp_dir) as tmp_dir: with pytest.raises(DefineExpectError): self.run_define_runner(define_opt, molecule_filepath)
def test_run_dscf_hf(self, structure): define_opt = get_define_template("dscf") define_opt["method"] = "hf" define_opt["desy"] = False define_opt["sym"] = "c1" define_opt["sym_eps"] = 0.001 define_opt["scfiterlimit"] = 300 define_opt["scfconv"] = 6 define_opt["title"] = None assert run_itest("dscf", define_opt, structure, "dscf_{}_hf".format(structure), ScfOutput)
def test_run_dscf_copymo_alpha_unpaired(self): """ Tests the copy functionalities with mos file """ define_opt = get_define_template("dscf") define_opt["basis"] = "def2-SV(P)" define_opt["charge"] = 1 define_opt["unpaired_electrons"] = 1 define_opt["copymo"] = os.path.join(get_tfp(), "mo", "alpha_beta_nh3") assert run_itest("dscf", define_opt, "nh3", "dscf_nh3_copymo_alpha_unpaired", ScfOutput)
def test_generate_mo_symmetry(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") define_opt["desy"] = True with temp_dir(delete_tmp_dir) as tmp: # run the full to generate all the files self.run_define_runner(define_opt, molecule_filepath) s = States.from_file("control") # check that there are other irreps coming from the mos assert len(s.irreps) != 1 or s.irreps[0] != "a" # do not remove mos to trigger another path in DefineRunner self.run_define_runner({"sym": "c1"}, None, "mo") assert os.path.isfile("mos") s_new = States.from_file("control") assert s_new.irreps[0] == "a"
def testrun_update_internal_coords(self, molecule_filepath, delete_tmp_dir): define_opt = get_define_template("dscf") define_opt["ired"] = True with temp_dir(delete_tmp_dir) as tmp: # run the full to generate all the files self.run_define_runner(define_opt, molecule_filepath) s = States.from_file("control") dg = DataGroups.from_file("coord") dg.kdg("redundant") dg.to_file("coord") # do not remove mos to trigger another path in DefineRunner self.run_define_runner({"ired": True}, None, "internal") dg_new = DataGroups.from_file("coord") assert dg_new.sdg("redundant")
def test_run_dscf_cosmo(self, structure): define_opt = get_define_template("dscf") define_opt["use_cosmo"] = True define_opt.update({ "epsilon": 60.0, "nppa": 92, "nspa": None, "disex": 0, "rsolv": 1.3, "routf": None, "cavity": "open" }) assert run_itest("dscf", define_opt, structure, "dscf_{}_cosmo".format(structure), ScfOutput)