def job_dump_hdf5(name, output, scfparams, dump_params): """Run a full calculation and dump the result as a yaml file""" res = run_scf_calculation(name, scfparams) # Remove keys which are given by the parameters for key in dump_params.get("remove_keys", []): if key in res: del res[key] molsturm.dump_state(res, output, type="hdf5")
def test_hdf5_serialisation(self): for case in self.cases: with self.subTest(label=case["testing"]["name"]): hfres = case["hf"] tmp = tempfile.mktemp(suffix=".hdf5") molsturm.dump_state(hfres, tmp, type="hdf5") back = molsturm.load_state(tmp) os.remove(tmp) self.assert_equal(hfres, back)
def job_orca_hf(name, params): """Run an orca HF calculation and extract reference values from it.""" orca_in_file = os.path.join(ORCADIR, name + ".orca_hf.in") build_orca_input(params, ["hf"], orca_in_file) res = run_orca(orca_in_file) def parse_restricted(value): return False if value == "UHF" else True orca_patterns = [ { "key": "energy_ground_state", "regex": "FINAL SINGLE POINT ENERGY\s*(?P<value>" + FLPAT + ")", "convert": float, "default": None, }, { "key": "energy_1e", "regex": "One Electron Energy\s*:\s*(?P<value>" + FLPAT + ") Eh", "convert": float, "default": None, }, { "key": "energy_2e", "regex": "Two Electron Energy\s*:\s*(?P<value>" + FLPAT + ") Eh", "convert": float, "default": None, }, { "key": "energy_kinetic", "regex": "Kinetic Energy\s*:\s*(?P<value>" + FLPAT + ") Eh", "convert": float, "default": None, }, { "key": "energy_potential", "regex": "Potential Energy\s*:\s*(?P<value>" + FLPAT + ") Eh", "convert": float, "default": None, }, { "key": "energy_nuclear_repulsion", "regex": "Nuclear Repulsion\s*:\s*(?P<value>" + FLPAT + ") Eh", "convert": float, "default": None, }, { "key": "restricted", "regex": "Hartree-Fock type\s*HFTyp\s*\.*\s*(?P<value>\w+)", "convert": lambda value: False if value == "UHF" else True, "default": None, }, { "key": "spin_squared", "regex": "Expectation value of <S\*\*2>\s*:\s*(?P<value>" + FLPAT + ")", "convert": float, "default": 0, }, ] reference = output_find_patterns(res, orca_patterns) print("TODO: It would be nice if the MO coefficients would be extracted " "from ORCA, too.") # Extra parsing reference["orben_f"] = orca_extract_orben(res) with open(os.path.join(dir_of_this_script(), name + ".hf.yaml"), "w") as f: # TODO It would be really nice if this was an actual hfres yaml # data file and not just a faked one as it is now. # This would require extracting a couple of more keys from # the ORCA output. f.write("# Data from ORCA calculation " + os.path.relpath(orca_in_file) + "\n") molsturm.dump_state(reference, f, type="yaml")
import molsturm.sturmian l_max = 1 n_max = 5 for atom, mult in [("He", 1), ("Be", 1), ("C", 3), ("Ne", 1)]: system = molsturm.System(atom) system.multiplicity = mult scfparams = molsturm.ScfParameters() scfparams.system = system k_guess = molsturm.sturmian.cs.empirical_kopt(scfparams.system) scfparams.basis = molsturm.construct_basis("sturmian/atomic/cs_reference_pc", scfparams.system, k_exp=k_guess, n_max=n_max, l_max=l_max) scfparams["scf/eigensolver/method"] = "lapack" scfparams["guess/eigensolver/method"] = "lapack" print("Running for " + atom + " please wait") best = molsturm.sturmian.cs.find_kopt(scfparams, print_iterations=True) k = best["input_parameters"]["discretisation"]["k_exp"] print("kopt for " + atom + " is {0:.4g}".format(k) + " with energy {0:.10g}".format(best["energy_ground_state"])) out = atom + "_" + str(n_max) + "_" + str(l_max) + "_kopt.hdf5" print("Dumping kopt solution for " + atom + " at " + out) molsturm.dump_state(best, out)