How to use the pyqmc.mc.initial_guess function in pyqmc

To help you get started, we’ve selected a few pyqmc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WagnerGroup / pyqmc / tests / integration / test_vmc.py View on Github external
#Without blocks
        coords = initial_guess(mol, nconf)
        df, coords = vmc(
            wf, coords, nsteps=nsteps, accumulators={"energy": EnergyAccumulator(mol)}, verbose=True
        )

        df = pd.DataFrame(df)
        df = reblock(df["energytotal"][warmup:], 20)
        en = df.mean()
        err = df.sem()
        assert en - mf.energy_tot() < 5 * err, "pyscf {0}, vmc {1}, err {2}".format(
            mf.energy_tot(), en, err
        )

        #With blocks
        coords = initial_guess(mol, nconf)
        df, coords = vmc(
            wf, coords, nblocks=int(nsteps/30), nsteps_per_block=30, 
            accumulators={"energy": EnergyAccumulator(mol)}
        )

        df = pd.DataFrame(df)["energytotal"][int(warmup/30):]
        en = df.mean()
        err = df.sem()
        assert en - mf.energy_tot() < 5 * err, "pyscf {0}, vmc {1}, err {2}".format(
            mf.energy_tot(), en, err
        )
github WagnerGroup / pyqmc / tests / integration / test_multislater.py View on Github external
mc = mcscf.CASCI(mf, ncas=4, nelecas=(2, 0))
        mc.kernel()
        wf = MultiSlater(mol, mf, mc)

        nelec = np.sum(mol.nelec)
        epos = initial_guess(mol, nconf)

        for k, item in testwf.test_updateinternals(wf, epos).items():
            assert item < epsilon
        assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
        assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
        assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon

        # Quick VMC test
        nconf = 1000
        coords = initial_guess(mol, nconf)
        df, coords = vmc(
            wf, coords, nsteps=nsteps, accumulators={"energy": EnergyAccumulator(mol)}
        )

        df = pd.DataFrame(df)
        df = reblock(df["energytotal"][warmup:], 20)
        en = df.mean()
        err = df.sem()
        assert en - mc.e_tot < 5 * err
github WagnerGroup / pyqmc / tests / integration / test_obdm.py View on Github external
# Lowdin orthogonalized AO basis.
    lowdin = lo.orth_ao(mol, "lowdin")

    # MOs in the Lowdin basis.
    mo = solve(lowdin, mf.mo_coeff)

    # make AO to localized orbital coefficients.
    mfobdm = mf.make_rdm1(mo, mf.mo_occ)

    ### Test OBDM calculation.
    nconf = 500
    nsteps = 400
    warmup = 15
    wf = PySCFSlater(mol, mf)
    configs = initial_guess(mol, nconf)
    obdm_dict = dict(mol=mol, orb_coeff=lowdin, nsweeps=5, warmup=15)
    obdm = OBDMAccumulator(**obdm_dict)
    obdm_up = OBDMAccumulator(**obdm_dict, spin=0)
    obdm_down = OBDMAccumulator(**obdm_dict, spin=1)

    df, coords = vmc(
        wf,
        configs,
        nsteps=nsteps,
        accumulators={"obdm": obdm, "obdm_up": obdm_up, "obdm_down": obdm_down},
    )

    obdm_est = {}
    for k in ["obdm", "obdm_up", "obdm_down"]:
        avg_norm = np.mean(df[k + "norm"][warmup:], axis=0)
        avg_obdm = np.mean(df[k + "value"][warmup:], axis=0)
github WagnerGroup / pyqmc / tests / integration / test_tbdm.py View on Github external
mfobdm = mf.make_rdm1(mo, mf.mo_occ)
    # Mean-field tbdm in IAO basis
    mftbdm = singledet_tbdm(mf, mfobdm)

    ### Test TBDM calculation.
    # VMC params
    nconf = 500
    n_vmc_steps = 400
    vmc_tstep = 0.3
    vmc_warmup = 30
    # TBDM params
    tbdm_sweeps = 4
    tbdm_tstep = 0.5

    wf = PySCFSlater(mol, mf)  # Single-Slater (no jastrow) wf
    configs = initial_guess(mol, nconf)
    energy = EnergyAccumulator(mol)
    obdm_up = OBDMAccumulator(mol=mol, orb_coeff=iaos[0], nsweeps=tbdm_sweeps, spin=0)
    obdm_down = OBDMAccumulator(mol=mol, orb_coeff=iaos[1], nsweeps=tbdm_sweeps, spin=1)
    tbdm_upup = TBDMAccumulator(
        mol=mol, orb_coeff=iaos, nsweeps=tbdm_sweeps, tstep=tbdm_tstep, spin=(0, 0)
    )
    tbdm_updown = TBDMAccumulator(
        mol=mol, orb_coeff=iaos, nsweeps=tbdm_sweeps, tstep=tbdm_tstep, spin=(0, 1)
    )
    tbdm_downup = TBDMAccumulator(
        mol=mol, orb_coeff=iaos, nsweeps=tbdm_sweeps, tstep=tbdm_tstep, spin=(1, 0)
    )
    tbdm_downdown = TBDMAccumulator(
        mol=mol, orb_coeff=iaos, nsweeps=tbdm_sweeps, tstep=tbdm_tstep, spin=(1, 1)
    )
github WagnerGroup / pyqmc / tests / integration / test_multislater.py View on Github external
"""
    mol = gto.M(atom="Li 0. 0. 0.; H 0. 0. 1.5", basis="cc-pvtz", unit="bohr", spin=0)
    epsilon = 1e-4
    delta = 1e-5
    nsteps = 200
    warmup = 10
    for mf in [scf.RHF(mol).run(), scf.ROHF(mol).run(), scf.UHF(mol).run()]:
        # Test same number of elecs
        mc = mcscf.CASCI(mf, ncas=4, nelecas=(1, 1))
        mc.kernel()
        wf = MultiSlater(mol, mf, mc)

        nconf = 10

        nelec = np.sum(mol.nelec)
        epos = initial_guess(mol, nconf)

        for k, item in testwf.test_updateinternals(wf, epos).items():
            assert item < epsilon
        assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
        assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
        assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon

        # Test same number of elecs
        mc = mcscf.CASCI(mf, ncas=4, nelecas=(1, 1))
        mc.kernel()
        wf = pyqmc.default_msj(mol, mf, mc)[0]

        nelec = np.sum(mol.nelec)
        epos = initial_guess(mol, nconf)

        for k, item in testwf.test_updateinternals(wf, epos).items():
github WagnerGroup / pyqmc / tests / unit / test_ecp_cutoff.py View on Github external
def test_ecp():
    mol = gto.M(
        atom="""C 0 0 0 
       C 1 0 0 
    """,
        ecp="bfd",
        basis="bfd_vtz",
    )
    mf = scf.RHF(mol).run()
    nconf = 1000
    coords = initial_guess(mol, nconf)
    thresholds = [1e15, 100, 50, 20, 10, 5, 1]
    label = ["S", "J", "SJ"]
    ind = 0
    for wf in [
        PySCFSlater(mol, mf),
        JastrowSpin(mol),
        MultiplyWF(PySCFSlater(mol, mf), JastrowSpin(mol)),
    ]:
        wf.recompute(coords)
        print(label[ind])
        ind += 1
        for threshold in thresholds:
            eacc = EnergyAccumulator(mol, threshold)
            start = time.time()
            eacc(coords, wf)
            end = time.time()
github WagnerGroup / pyqmc / pyqmc / optsr.py View on Github external
def test():
    from pyscf import lib, gto, scf
    from pyqmc.accumulators import EnergyAccumulator, PGradTransform, LinearTransform
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc.jastrow import Jastrow2B
    from pyqmc.func3d import GaussianFunction
    from pyqmc.slater import PySCFSlaterRHF
    from pyqmc.mc import initial_guess

    mol = gto.M(atom="H 0. 0. 0.; H 0. 0. 1.5", basis="cc-pvtz", unit="bohr", verbose=5)
    mf = scf.RHF(mol).run()
    nconf = 2500
    nsteps = 70
    warmup = 20

    coords = initial_guess(mol, nconf)
    basis = {
        "wf2coeff": [
            GaussianFunction(0.2),
            GaussianFunction(0.4),
            GaussianFunction(0.6),
        ]
    }
    wf = MultiplyWF(PySCFSlaterRHF(mol, mf), Jastrow2B(mol, basis["wf2coeff"]))
    params0 = {"wf2coeff": np.array([-0.8, -0.2, 0.4])}
    for k, p in wf.parameters.items():
        if k in params0:
            wf.parameters[k] = params0[k]

    energy_acc = EnergyAccumulator(mol)
    pgrad_acc = PGradTransform(energy_acc, LinearTransform(wf.parameters))
github WagnerGroup / pyqmc / pyqmc / obdm.py View on Github external
self.supercell = mol
            self._mol = mol.original_cell
        else:
            self._mol = mol
            self.evaluate_orbitals = self._evaluate_orbitals
            assert (
                len(orb_coeff.shape) == 2
            ), "orb_coeff should be a list of orbital coefficients."

        self._orb_coeff = orb_coeff
        self._tstep = tstep
        self.nelec = len(self._electrons)
        self._nsweeps = nsweeps
        self._nstep = nsweeps * self.nelec

        self._extra_config = initial_guess(mol, int(naux / self.nelec) + 1)
        self._extra_config.reshape((-1, 3))

        accept, extra_configs = self.sample_onebody(self._extra_config, warmup)
        self._extra_config = extra_configs[-1]