def __run_find_kopt(self, case): system = molsturm.System(case.atom) system.multiplicity = case.multiplicity scfparams = molsturm.ScfParameters() scfparams.system = system basis_type = "sturmian/atomic/cs_reference_pc" if basis_type not in molsturm.available_basis_types: raise unittest.SkipTest("Skipped subtest " + case.atom + ", since basis type not available: " + basis_type) scfparams.basis = molsturm.construct_basis( basis_type, scfparams.system, k_exp=0.0, # dummy n_max=case.n_max, l_max=case.l_max) scfparams["scf/eigensolver/method"] = "lapack" scfparams["guess/eigensolver/method"] = "lapack" conv_tol = 1e-3 best = molsturm.sturmian.cs.find_kopt(scfparams, conv_tol=conv_tol) k = best["input_parameters"]["discretisation"]["k_exp"] self.assertAlmostEqual(k, case.ref_kexp, tol=conv_tol, prefix="optimal exponent kopt: ") self.assertAlmostEqual(best["energy_ground_state"], case.ref_energy, tol=conv_tol / 100, prefix="ground state energy: ")
def dump_integrals_gaussian(atoms, coords, electrons, basis_set_name, ifile=None): system = molsturm.System(atoms, coords, electrons) params = molsturm.ScfParameters() params.system = system params.basis = molsturm.construct_basis("gaussian", params.system, basis_set_name=basis_set_name) if ifile is None: latoms = [a.lower() for a in atoms] ifile = "integrals_{}_{}.hdf5".format("".join(latoms), basis_set_name) with h5py.File(ifile, "w") as h5f: write_integrals_to_hdf5(params, h5f) g_discr = h5f.create_group("discretisation") g_discr.create_dataset("basis_type", data="gaussian", dtype=h5py.special_dtype(vlen=str)) g_discr.create_dataset("basis_set_name", dtype=h5py.special_dtype(vlen=str), data=basis_set_name) g_discr.create_dataset("has_real_harmonics", data=1, dtype=np.uint8)
def main(): carbon = molsturm.System("c") carbon.multiplicity = 3 params = molsturm.ScfParameters() params.system = carbon params.basis = molsturm.construct_basis("sturmian/atomic/cs_reference_pc", params.system, k_exp=3.3, n_max=4, l_max=3) params["scf/eigensolver/method"] = "lapack" params["scf/print_iterations"] = True params["guess/eigensolver/method"] = "lapack" res = molsturm.self_consistent_field(params) molsturm.print_convergence_summary(res) molsturm.print_energies(res) molsturm.print_mo_occupation(res) molsturm.print_quote(res) return res
def dump_integrals_sturmian(atoms, coords, electrons, k_exp, n_max, l_max, m_max, ifile=None): system = molsturm.System(atoms, coords, electrons) params = molsturm.ScfParameters() params.system = system basis = molsturm.construct_basis("sturmian/atomic", params.system, k_exp=k_exp, n_max=n_max, l_max=l_max, m_max=m_max) basis.backend = "cs_reference" params.basis = basis if ifile is None: latoms = [a.lower() for a in atoms] ifile = ("integrals_{}_{:02d}{:02d}{:02d}_{:.4f}.hdf5" "".format("".join(latoms), n_max, l_max, m_max, k_exp)) with h5py.File(ifile, "w") as h5f: write_integrals_to_hdf5(params, h5f) g_discr = h5f.create_group("discretisation") g_discr.create_dataset("basis_type", data="sturmian/atomic", dtype=h5py.special_dtype(vlen=str)) g_discr.create_dataset("nlm_basis", data=basis.functions) g_discr.create_dataset("k_exp", data=k_exp) g_discr.create_dataset("n_max", data=n_max) g_discr.create_dataset("l_max", data=l_max) g_discr.create_dataset("m_max", data=m_max) g_discr.create_dataset("has_real_harmonics", data=basis.has_real_harmonics, dtype=np.uint8)
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with molsturm. If not, see <http://www.gnu.org/licenses/>. ## ## --------------------------------------------------------------------- ## vi: tabstop=2 shiftwidth=2 softtabstop=2 expandtab import molsturm import molsturm.posthf sys = molsturm.System(["beryllium"], [[0, 0, 0]]) bas = molsturm.construct_basis("sturmian/atomic", sys, k_exp=2.1, n_max=11, l_max=0, backend="cs_reference_pc") res = molsturm.hartree_fock(sys, bas, conv_tol=1e-10, print_iterations=True) molsturm.print_convergence_summary(res) molsturm.print_energies(res) molsturm.print_mo_occupation(res) print() res_adc = molsturm.posthf.mp2(res) print("MP2 energy", res_adc["energy_mp2"]) print("tot energy", res_adc["energy_ground_state"]) molsturm.print_quote(res)
# This done to stabilise the outcome such that we don't # get the correct minimum once and a wrong minimum at another time scfparams["guess/method"] = "random" try: scfparams.normalise() except (ValueError, KeyError, TypeError) as e: raise unittest.SkipTest("Skipped subtest " + case["testing"]["name"] + ", since construction of ScfParameters " "failed: " + str(e)) smallparams = scfparams.copy() origbasis = scfparams.basis smallparams.basis = molsturm.construct_basis( "sturmian/atomic", scfparams.system, n_max=n_max, l_max=l_max, m_max=m_max, k_exp=origbasis.k_exp, backend=origbasis.backend ) smallres = molsturm.self_consistent_field(smallparams) res_no_guess = molsturm.self_consistent_field(scfparams) guess = molsturm.scf_guess.extrapolate_from_previous(smallres, scfparams) scfparams.set_guess_external(*guess) res_guess = molsturm.self_consistent_field(scfparams) self.assertAlmostEqual(res_no_guess["energy_ground_state"], res_guess["energy_ground_state"], tol=case["testing"]["numeric_tolerance"], prefix="Energy of ground state without and with guess: ") self.assertLess(res_guess["n_iter"], res_no_guess["n_iter"],
## ## --------------------------------------------------------------------- import molsturm import multiprocessing import numpy as np # This scripts runs `n_points` molsturm calculations starting from # a random guess and checks the SCF energies we get if we converge # up to an error of error n_points = 100 error = 1e-7 system = molsturm.MolecularSystem("Be") basis = molsturm.construct_basis("sturmian/atomic", system, k_exp=1.3, n_max=3, l_max=2, backend="cs_static14") # We want the data gathering to be parallel ... try: nproc = multiprocessing.cpu_count() except NotImplementedError: nproc = 2 # arbitrary default # Function which runs molsturm and sends the total energy # and the number of iterations to the main process def run_molsturm(x): res = molsturm.hartree_fock(system, basis, eigensolver="lapack", max_iter=200, conv_tol=error, guess="random") return (res["n_iter"], res["energy_ground_state"])
## You should have received a copy of the GNU General Public License ## along with molsturm. If not, see <http://www.gnu.org/licenses/>. ## ## --------------------------------------------------------------------- import molsturm import molsturm.gaussian import numpy as np import matplotlib.pyplot as plt import warnings params = molsturm.ScfParameters() params.system = molsturm.MolecularSystem("Be") params["scf/print_iterations"] = True params.basis = molsturm.construct_basis("gaussian", params.system, basis_set_name="cc-pvdz") print("Running fit, please wait") with warnings.catch_warnings(): warnings.simplefilter("ignore") res = molsturm.gaussian.extrapolate_cbs_limit(params) # Print the result cov = res.cov print("Estimated parameters: value (stddev)") print(" E(CBS) == {0:16.14G} ({1: >9.4G})".format(res.cbs, np.sqrt(cov[0][0]))) print(" A == {0:16.14G} ({1: >9.4G})".format(res.A, np.sqrt(cov[0][1]))) print(" B == {0:16.14G} ({1: >9.4G})".format(res.B,
atom_numbers = np.array(h5f["system/atom_numbers"]) coords = np.array(h5f["system/coords"]) system = molsturm.System( atoms=atom_numbers, coords=coords, electrons=nelec, ) params = molsturm.ScfParameters() params.system = system basis_type = str(h5f["discretisation/basis_type"].value) if basis_type == "gaussian": bas = str(h5f["discretisation/basis_set_name"].value) params.basis = molsturm.construct_basis("gaussian", params.system, basis_set_name=bas) elif basis_type == "sturmian/atomic": k_exp = float(h5f["discretisation/k_exp"].value) n_max = int(h5f["discretisation/n_max"].value) l_max = int(h5f["discretisation/l_max"].value) m_max = int(h5f["discretisation/m_max"].value) params.basis = molsturm.construct_basis("sturmian/atomic", params.system, k_exp=k_exp, n_max=n_max, l_max=l_max, m_max=m_max) else: raise NotImplementedError("Basis type {} is not " "implemented".format(basis_type))
from scipy import linalg import numpy as np params = molsturm.ScfParameters() # Supply molecular structure atoms = ["Be"] # as a list of names, symbols, atom numbers ... positions = [[0, 0, 0]] # as a list of triples x,y,z system = molsturm.System(atoms, positions) system.charge = 0 # Optional, 0 by default system.multiplicity = 1 # Optional, 1 by default for even-electron systems, # 2 for odd-electron systems params.system = system # Supply basis set information basis = molsturm.construct_basis("gaussian", system, basis_set_name="pc-3") # basis = molsturm.construct_basis("sturmian/atomic", system, k_exp=1.988, # n_max=5, l_max=1, m_max=1) params.basis = basis # Compute integral data print("Computing integrals ... ", end="", flush=True) s_bb = integrals.overlap_bb(params) t_bb = integrals.kinetic_bb(params) v_bb = integrals.nuclear_attraction_bb(params) eri_bbbb = integrals.electron_repulsion_bbbb(params) print("done") # # Restricted Hartree-Fock routine starts #
## ## molsturm is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with molsturm. If not, see <http://www.gnu.org/licenses/>. ## ## --------------------------------------------------------------------- import molsturm system = molsturm.MolecularSystem(atoms=[4], coords=[[0, 0, 0]]) basis = molsturm.construct_basis("sturmian/atomic", system, k_exp=2.3, n_max=4, l_max=1) def run_matrix_free(system, basis, extra={}): params = molsturm.ScfParameters() params.system = system params.basis = basis params["guess/method"] = "random" params["guess/eigensolver/method"] = "arpack" params["scf/eigensolver/method"] = "arpack" params["scf/n_eigenpairs"] = 2 * (basis.size // 2) params.update(extra) res = molsturm.self_consistent_field(params) molsturm.print_convergence_summary(res) molsturm.print_energies(res)
import molsturm 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)