コード例 #1
0
class TestHartreeFockHighLevelFrontend(HartreeFockTestCase):
    @unittest.skipUnless(
        "sturmian/atomic/cs_static14" in molsturm.available_basis_types,
        "Required basis type sturmian/atomic/cs_static14 is not "
        "available")
    def test_sturmian_basis_on_the_fly(self):
        case = testdata.test_cases_by_name("be_cs32")[0]

        try:
            params = molsturm.ScfParameters.from_dict(case["input_parameters"])
            params.normalise()
        except (ValueError, KeyError, TypeError) as e:
            raise unittest.SkipTest(
                "Skipped subtest " + case["testing"]["name"] +
                ", since construction of ScfParameters failed: " + str(e))
        system = params.system
        discretisation = params["discretisation"]
        scf = params["scf"]
        hfres = molsturm.hartree_fock(system,
                                      basis_type=discretisation["basis_type"],
                                      conv_tol=scf["max_error_norm"],
                                      max_iter=scf["max_iter"],
                                      n_eigenpairs=scf["n_eigenpairs"],
                                      restricted=(scf["kind"] == "restricted"),
                                      guess=params["guess/method"],
                                      eigensolver=scf["eigensolver/method"],
                                      print_iterations=scf["print_iterations"],
                                      k_exp=discretisation["k_exp"],
                                      n_max=discretisation["n_max"],
                                      l_max=discretisation["l_max"],
                                      m_max=discretisation["m_max"])

        # TODO test guess from previous via this interface, too

        self.compare_hf_results_small(case, hfres)
コード例 #2
0
def run_hf(xyz,
           basis,
           charge=0,
           multiplicity=1,
           conv_tol=1e-12,
           conv_tol_grad=1e-8,
           max_iter=150):

    import molsturm

    # Quick-and-dirty xyz parser:
    geom = xyz.split()
    n_atom = len(geom) // 4
    assert n_atom * 4 == len(geom)
    atoms = [geom[i * 4] for i in range(n_atom)]
    coords = [[
        float(geom[i * 4 + 1]),
        float(geom[i * 4 + 2]),
        float(geom[i * 4 + 3])
    ] for i in range(n_atom)]

    mol = molsturm.System(atoms, coords)
    mol.charge = charge
    mol.multiplicity = multiplicity

    return molsturm.hartree_fock(mol,
                                 basis_type="gaussian",
                                 basis_set_name=basis_remap.get(basis, basis),
                                 conv_tol=conv_tol_grad,
                                 max_iter=max_iter)
コード例 #3
0
ファイル: h2o_optimisation.py プロジェクト: chrinide/molsturm
    def objective_function(args):
        nonlocal recent_hf_res
        nonlocal recent_hf_res_for_args

        # Update geometry and run calculation:
        system = geometryfctn(args)
        res = molsturm.hartree_fock(system,
                                    conv_tol=conv_tol / 10,
                                    guess=recent_hf_res,
                                    **params)
        print("arguments: ", args, "niter:", res["n_iter"])

        # Update the stored recent_hf_res but only if it differs enough
        # from the one we currently have stored
        if recent_hf_res_for_args is None or \
           np.max(np.abs(np.array(recent_hf_res_for_args) - np.array(args))) > conv_tol:
            recent_hf_res_for_args = args
            recent_hf_res = res
            print("  -> guess update")

        if level == "hf":
            return res["energy_ground_state"]
        elif level == "mp2":
            res = molsturm.posthf.mp2(res)
            return res["energy_ground_state"]
        else:
            raise NotImplementedError("Level of theory not yet implemented")
コード例 #4
0
ファイル: water_def2_svp.py プロジェクト: chrinide/molsturm
def run(**extra):
    res = molsturm.hartree_fock(water,
                                basis_type="gaussian/libint",
                                basis_set_name="def2-svp",
                                **extra)

    molsturm.print_convergence_summary(res)
    molsturm.print_energies(res)
    molsturm.print_mo_occupation(res)
    molsturm.print_quote(res)
    return res
コード例 #5
0
def compute_curve(atom,
                  basis_set="sto-3g",
                  conv_tol=1e-6,
                  zrange=(0.5, 8.0),
                  n_points=25,
                  restricted=False,
                  verbose=False,
                  method="hf"):
    if method not in ["hf", "mp2", "fci"]:
        raise ValueError("Only implemented for hf and mp2")

    z = np.linspace(zrange[0], zrange[1], n_points)
    f = np.empty_like(z)
    previous_hf = None

    idcs = np.argsort(z)[::-1]
    for i in idcs:
        sys = molsturm.MolecularSystem(atoms=[atom, atom],
                                       coords=[(0, 0, 0), (0, 0, z[i])])

        guess = previous_hf if previous_hf is not None else "random"
        try:
            hf = molsturm.hartree_fock(sys,
                                       basis_type="gaussian",
                                       conv_tol=conv_tol,
                                       basis_set_name=basis_set,
                                       guess=guess,
                                       restricted=restricted,
                                       print_iterations=verbose,
                                       max_iter=100)

            if previous_hf is None:
                previous_hf = hf

            if method == "hf":
                f[i] = hf["energy_ground_state"]
            elif method == "mp2":
                mp2 = molsturm.posthf.mp2(hf)
                f[i] = mp2["energy_ground_state"]
            elif method == "fci":
                fci = molsturm.posthf.fci(hf, n_roots=1)
                f[i] = fci["states"][0]["energy"]

        except RuntimeError as e:
            print("Caught error for z=", z[i])
            print(str(e))
            print()
            f[i] = np.nan

    return z, f
コード例 #6
0
ファイル: be_cs_14_mp2.py プロジェクト: chrinide/molsturm
## 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)
コード例 #7
0
        residual_norm = np.max(np.max(residual))
        print(fmt.format(n_iter, corr, residual_norm))

        # Quasi-Newton update step
        n_iter += 1
        t2 -= residual / ccd_approx_jacobian(t2, state.fock, eri_asym)

        if n_iter > 100:
            raise RuntimeError("CCD not converged after 100 iterations.")
    return corr, t2


if __name__ == "__main__":
    sys = molsturm.System(
        atoms=["O", "O"],
        coords=[(0, 0, 0), (0, 0, 2.8535)],
    )
    sys.multiplicity = 3
    state = molsturm.hartree_fock(sys, basis_type="gaussian",
                                  basis_set_name="6-31g", conv_tol=5e-7)

    corr, t2 = ccd(state)
    maxamp = np.max(np.abs(t2))
    print("CCD correlation energy: ", corr)
    print("Largest t2 amplitude:   ", maxamp)
    print()

    hf = state.energy_ground_state
    print("HF energy:              ", hf)
    print("CCD total energy:       ", corr + hf)
コード例 #8
0
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"])
コード例 #9
0
ファイル: molsturm_sto3g_adc2.py プロジェクト: yychuang/adcc
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
import adcc

import molsturm

# Run SCF in molsturm
atoms = ["O", "H", "H"]
coords = [[0, 0, 0],
          [0, 0, 1.795239827225189],
          [1.693194615993441, 0, -0.599043184453037]]
system = molsturm.System(atoms, coords)

hfres = molsturm.hartree_fock(system, basis_type="gaussian",
                              basis_set_name="sto-3g",
                              conv_tol=1e-12, print_iterations=True)

# Run an adc2 calculation:
singlets = adcc.adc2(hfres, n_singlets=5, conv_tol=1e-9)
triplets = adcc.adc2(singlets.matrix, n_triplets=3, conv_tol=1e-9)

print(singlets.describe())
print(triplets.describe())
コード例 #10
0
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## 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/>.
##
## ---------------------------------------------------------------------
## vi: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

import molsturm
import molsturm.posthf

sys = molsturm.System([4], [[0, 0, 0]])
res = molsturm.hartree_fock(sys, basis_type="gaussian", basis_set_name="cc-pvdz",
                            print_iterations=True, conv_tol=1e-10)
molsturm.print_convergence_summary(res)
molsturm.print_energies(res)
molsturm.print_mo_occupation(res)

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)
コード例 #11
0
                         "Required basis type gaussian/libint is not available"
                         )
    def test_gaussian_basis_on_the_flay(self):
        case = testdata.test_cases_by_name("c_321g")[0]

        try:
            params = molsturm.ScfParameters.from_dict(case["input_parameters"])
            params.normalise()
        except (ValueError, KeyError, TypeError) as e:
            raise unittest.SkipTest(
                "Skipped subtest " + case["testing"]["name"] +
                ", since construction of ScfParameters failed: " + str(e))
        system = params.system
        discretisation = params["discretisation"]
        scf = params["scf"]
        hfres = molsturm.hartree_fock(
            system,
            basis_type=discretisation["basis_type"],
            conv_tol=scf["max_error_norm"],
            max_iter=scf["max_iter"],
            n_eigenpairs=scf["n_eigenpairs"],
            restricted=(scf["kind"] == "restricted"),
            guess=params["guess/method"],
            eigensolver=scf["eigensolver/method"],
            print_iterations=scf["print_iterations"],
            basis_set_name=discretisation["basis_set_name"])

        # TODO test guess from previous via this interface, too

        self.compare_hf_results_small(case, hfres)