Beispiel #1
0
def test_pbc_wfs():
    """
    Ensure that the wave function objects are consistent in several situations.
    """

    from pyscf.pbc import lib, gto, scf
    from pyqmc.supercell import get_supercell
    from pyqmc.slater import Slater
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc import default_jastrow
    import pyqmc

    mol = gto.M(
        atom="H 0. 0. 0.; H 1. 1. 1.",
        basis="sto-3g",
        unit="bohr",
        a=(np.ones((3, 3)) - np.eye(3)) * 4,
    )
    mf = scf.KRKS(mol, mol.make_kpts((2, 2, 2))).run()
    # mf_rohf = scf.KROKS(mol).run()
    # mf_uhf = scf.KUKS(mol).run()
    epsilon = 1e-5
    nconf = 10
    supercell = get_supercell(mol, S=(np.ones((3, 3)) - 2 * np.eye(3)))
    epos = pyqmc.initial_guess(supercell, nconf)
    # For multislaterpbc
    # kinds = 0, 3, 5, 6  # G, X, Y, Z
    # d1 = {kind: [0] for kind in kinds}
    # d2 = d1.copy()
    # d2.update({0: [], 3: [0, 1]})
    # detwt = [2 ** 0.5, 2 ** 0.5]
    # occup = [[d1, d2], [d1]]
    # map_dets = [[0, 1], [0, 0]]
    for wf in [
        MultiplyWF(Slater(supercell, mf), default_jastrow(supercell)[0]),
        Slater(supercell, mf),
    ]:
        for k in wf.parameters:
            if "mo_coeff" not in k and k != "det_coeff":
                wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)

        _, epos = pyqmc.vmc(wf, epos, nblocks=1, nsteps=2, tstep=1)  # move off node

        for fname, func in zip(
            ["gradient", "laplacian", "pgradient"],
            [
                testwf.test_wf_gradient,
                testwf.test_wf_laplacian,
                testwf.test_wf_pgradient,
            ],
        ):
            err = []
            for delta in [1e-4, 1e-5, 1e-6, 1e-7, 1e-8]:
                err.append(func(wf, epos, delta))
            print(type(wf), fname, min(err))
            assert min(err) < epsilon

        for k, item in testwf.test_updateinternals(wf, epos).items():
            print(k, item)
            assert item < epsilon
Beispiel #2
0
def test_pbc_wfs():
    """
    Ensure that the wave function objects are consistent in several situations.
    """

    from pyscf.pbc import lib, gto, scf
    from pyqmc.slaterpbc import PySCFSlaterPBC, get_supercell
    from pyqmc.jastrowspin import JastrowSpin
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc.coord import OpenConfigs
    import pyqmc

    mol = gto.M(atom="H 0. 0. 0.; H 1. 1. 1.",
                basis="sto-3g",
                unit="bohr",
                a=np.eye(3) * 4)
    mf = scf.KRKS(mol).run()
    # mf_rohf = scf.KROKS(mol).run()
    # mf_uhf = scf.KUKS(mol).run()
    epsilon = 1e-5
    nconf = 10
    supercell = get_supercell(mol, S=np.eye(3))
    epos = pyqmc.initial_guess(supercell, nconf)
    for wf in [
            MultiplyWF(PySCFSlaterPBC(supercell, mf), JastrowSpin(mol)),
            PySCFSlaterPBC(supercell, mf),
            # PySCFSlaterPBC(supercell, mf_uhf),
            # PySCFSlaterPBC(supercell, 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,
            ],
        ):
            err = []
            for delta in [1e-4, 1e-5, 1e-6, 1e-7, 1e-8]:
                err.append(func(wf, epos, delta)[0])
            print(fname, min(err))
            assert min(err) < epsilon

        for k, item in testwf.test_updateinternals(wf, epos).items():
            print(k, item)
            assert item < epsilon
Beispiel #3
0
def test_info_functions_pbc():
    from pyscf.pbc import gto, scf
    from pyqmc.supercell import get_supercell

    mol = gto.Cell(atom="He 0.00 0.00 0.00",
                   basis="gth-szv",
                   pseudo="gth-pade",
                   unit="B")
    mol.a = 5.61 * np.eye(3)
    mol.build()

    mf = scf.KRKS(mol, kpts=mol.make_kpts([2, 2, 2]))  # .density_fit()
    ehf = mf.kernel()

    supercell = get_supercell(mol, 2 * np.eye(3))
    kinds = [0, 1]
    dm_orbs = [mf.mo_coeff[i][:, :2] for i in kinds]
    wf, to_opt = pyqmc.default_sj(mol, mf)
    accumulators = {
        "pgrad": pyqmc.gradient_generator(mol, wf, to_opt, ewald_gmax=10),
        "obdm": OBDMAccumulator(mol, dm_orbs, kpts=mf.kpts[kinds]),
        "Sq": pyqmc.accumulators.SqAccumulator(mol.lattice_vectors()),
    }
    info_functions(mol, wf, accumulators)