How to use the pyqmc.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 / test_derivatives.py View on Github external
"""

    from pyscf import lib, gto, scf
    from pyqmc.slateruhf import PySCFSlaterUHF
    from pyqmc.jastrowspin import JastrowSpin
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc.coord import OpenConfigs
    import pyqmc

    mol = gto.M(atom="Li 0. 0. 0.; H 0. 0. 1.5", basis="cc-pvtz", unit="bohr")
    mf = scf.RHF(mol).run()
    mf_rohf = scf.ROHF(mol).run()
    mf_uhf = scf.UHF(mol).run()
    epsilon = 1e-4
    nconf = 10
    epos = pyqmc.initial_guess(mol, nconf)
    for wf in [
        JastrowSpin(mol),
        MultiplyWF(PySCFSlaterUHF(mol, mf), JastrowSpin(mol)),
        PySCFSlaterUHF(mol, mf_uhf),
        PySCFSlaterUHF(mol, mf),
        PySCFSlaterUHF(mol, mf_rohf),
    ]:
        for k in wf.parameters:
            if k != "mo_coeff":
                wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)
        for fname, func in zip(
            ["gradient", "laplacian", "pgradient"],
            [
                testwf.test_wf_gradient,
                testwf.test_wf_laplacian,
                testwf.test_wf_pgradient,
github WagnerGroup / pyqmc / tests / integration / test_periodic.py View on Github external
dm = np.sum(dm, axis=0)
        dm = dm[kind]

    #####################################
    ## evaluate KE in PySCF
    #####################################
    ke_mat = mol.pbc_intor("int1e_kin", hermi=1, kpts=np.array(kpt))
    print("ke_mat", ke_mat.shape)
    print("dm", dm.shape)
    pyscfke = np.real(np.einsum("ij,ji->", ke_mat, dm))
    print("PySCF kinetic energy: {0}".format(pyscfke))

    #####################################
    ## evaluate KE integral with VMC
    #####################################
    coords = pyqmc.initial_guess(mol, 1200, 0.7)
    warmup = 10
    start = time.time()
    df, coords = pyqmc.vmc(
        wf,
        coords,
        nsteps=100 + warmup,
        tstep=1,
        accumulators={"energy": pyqmc.accumulators.EnergyAccumulator(mol)},
        verbose=False,
        hdf_file=str(uuid.uuid4()),
    )
    print("VMC time", time.time() - start)
    df = pd.DataFrame(df)
    dfke = reblock(df["energyke"][warmup:], 10)
    dfke /= mol.scale
    vmcke, err = dfke.mean(), dfke.sem()
github WagnerGroup / pyqmc / examples / excited_state.py View on Github external
"excited2_vmc": "excited2_vmc.hdf5",
        "linemin_final": "linemin_final.hdf5",
        "excited1_final": "excited1_final.hdf5",
        "excited2_final": "excited2_final.hdf5",
    }

    for k, it in savefiles.items():
        if os.path.isfile(it):
            os.remove(it)

    # Run
    setuph2(savefiles["mf"], "test")
    sys = pyqmc_from_hdf(savefiles["mf"])

    df, coords = vmc(
        sys["wf"], pyqmc.initial_guess(sys["mol"], nconfig), client=client, nsteps=10, npartitions=ncore,
    )

    line_minimization(
        sys["wf"],
        coords,
        sys["pgrad"],
        hdf_file=savefiles["linemin"],
        client=client,
        npartitions=ncore,
        verbose=True,
    )

    # First excited state
    wfs = [sys["wf"], deepcopy(sys["wf"])]
    optimize_orthogonal(
        wfs,
github WagnerGroup / pyqmc / examples / excited_state.py View on Github external
with h5py.File(hdf_vmc, "r") as vmc_hdf:
        obdm_up = np.mean(np.array(vmc_hdf["obdm_upvalue"]), axis=0)
        obdm_down = np.mean(np.array(vmc_hdf["obdm_downvalue"]), axis=0)
    basis_up = gen_basis(mol, sys["mf"], obdm_up)
    basis_down = gen_basis(mol, sys["mf"], obdm_down)
    obdm_up_acc = OBDMAccumulator(mol=mol, orb_coeff=basis_up, spin=0)
    obdm_down_acc = OBDMAccumulator(mol=mol, orb_coeff=basis_down, spin=1)
    tbdm = TBDMAccumulator(mol, np.array([basis_up, basis_down]), spin=(0, 1))
    acc = {
        "energy": EnergyAccumulator(mol),
        "obdm_up": obdm_up_acc,
        "obdm_down": obdm_down_acc,
        "tbdm": tbdm,
    }

    configs = pyqmc.initial_guess(sys["mol"], 1000)
    pyqmc.vmc(sys["wf"], configs, nsteps=500, hdf_file=hdf_final, accumulators=acc)
github WagnerGroup / pyqmc / examples / parsl_h2o.py View on Github external
# It's better to load parsl after pyscf has run. Some of the
# executors have timeouts and will kill the job while pyscf is running!
parsl.load(config)


# We make a Slater-Jastrow wave function and
# only optimize the Jastrow coefficients.
wf = pyqmc.slater_jastrow(mol, mf)
acc = pyqmc.gradient_generator(mol, wf, ["wf2acoeff", "wf2bcoeff"])


# Generate the initial configurations.
# Here we run VMC for a few steps with no accumulators to equilibrate the
# walkers.
configs = pyqmc.initial_guess(mol, nconf)
df, configs = distvmc(wf, configs, accumulators={}, nsteps=10, npartitions=ncore)

# This uses a stochastic reconfiguration step to generate parameter changes along a line,
# then minimizes the energy along that line.
wf, dfgrad, dfline = line_minimization(
    wf,
    configs,
    acc,
    npartitions=ncore,
    vmcoptions={"nsteps": 30},
    dataprefix="parsl_h2o",
)
github WagnerGroup / pyqmc / examples / he.py View on Github external
if __name__ == "__main__":
    import pyscf
    import pyqmc

    mol = pyscf.gto.M(atom="He 0. 0. 0.", basis="bfd_vdz", ecp="bfd", unit="bohr")

    mf = pyscf.scf.RHF(mol).run()
    wf, to_opt = pyqmc.default_sj(mol, mf)

    nconfig = 1000
    configs = pyqmc.initial_guess(mol, nconfig)

    acc = pyqmc.gradient_generator(mol, wf, to_opt)
    pyqmc.line_minimization(wf, configs, acc, hdf_file="he_opt.hdf5", verbose=True)

    pyqmc.rundmc(
        wf,
        configs,
        nsteps=5000,
        accumulators={"energy": pyqmc.EnergyAccumulator(mol)},
        tstep=0.02,
        hdf_file="he_dmc.hdf5",
        verbose=True,
    )
github WagnerGroup / pyqmc / examples / dask_h2o.py View on Github external
mol = gto.M(
        atom="O 0 0 0; H 0 -2.757 2.587; H 0 2.757 2.587", basis="bfd_vtz", ecp="bfd"
    )
    mf = scf.RHF(mol).run()
    return mol, mf


if __name__ == "__main__":
    cluster = LocalCluster(n_workers=ncore, threads_per_worker=1)
    client = Client(cluster)
    mol, mf = run_scf()
    from pyqmc import vmc, line_minimization, rundmc

    wf, to_opt = pyqmc.default_sj(mol, mf)
    pgrad_acc = pyqmc.gradient_generator(mol, wf, to_opt)
    configs = pyqmc.initial_guess(mol, nconfig)
    line_minimization(
        wf,
        configs,
        pgrad_acc,
        hdf_file="h2o_opt.hdf",
        client=client,
        npartitions=ncore,
        verbose=True,
    )
    df, configs = vmc(
        wf,
        configs,
        hdf_file="h2o_vmc.hdf",
        accumulators={"energy": pgrad_acc.enacc},
        client=client,
        npartitions=ncore,
github WagnerGroup / pyqmc / examples / periodic_he.py View on Github external
kmf.kpts = cell.make_kpts([nk, nk, nk])
    ehf = kmf.kernel()
    print("EHF", ehf)
    return cell, kmf


if __name__ == "__main__":
    # Run SCF
    cell, kmf = run_scf(nk=2)

    # Set up wf and configs
    nconfig = 100
    S = np.eye(3) * 2  # 2x2x2 supercell
    supercell = get_supercell(cell, S)
    wf, to_opt = pyqmc.default_sj(supercell, kmf)
    configs = pyqmc.initial_guess(supercell, nconfig)

    # Initialize energy accumulator (and Ewald)
    pgrad = pyqmc.gradient_generator(supercell, wf, to_opt=to_opt)

    # Optimize jastrow
    wf, lm_df = pyqmc.line_minimization(
        wf, configs, pgrad, hdf_file="pbc_he_linemin.hdf", verbose=True
    )

    # Run VMC
    df, configs = pyqmc.vmc(
        wf,
        configs,
        nblocks=100,
        accumulators={"energy": pgrad.enacc},
        hdf_file="pbc_he_vmc.hdf",