Exemplo n.º 1
0
def test_wfs():
    """
    Ensure that the wave function objects are consistent in several situations.
    """

    from pyscf import lib, gto, scf
    from pyqmc import Slater
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc.manybody_jastrow import J3
    from pyqmc import default_jastrow
    import pyqmc

    mol = gto.M(atom="Li 0. 0. 0.; H 0. 0. 1.5", basis="sto-3g", unit="bohr")
    mf = scf.RHF(mol).run()
    mf_rohf = scf.ROHF(mol).run()
    mf_uhf = scf.UHF(mol).run()
    epsilon = 1e-5
    nconf = 10
    epos = pyqmc.initial_guess(mol, nconf)
    for wf in [
        default_jastrow(mol)[0],
        J3(mol),
        MultiplyWF(Slater(mol, mf), default_jastrow(mol)[0]),
        MultiplyWF(Slater(mol, mf), default_jastrow(mol)[0], J3(mol)),
        Slater(mol, mf_uhf),
        Slater(mol, mf),
        Slater(mol, mf_rohf),
    ]:
        for k in wf.parameters:
            if k != "mo_coeff":
                wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)
        for k, item in testwf.test_updateinternals(wf, epos).items():
            print(k, item)
            assert item < epsilon

        testwf.test_mask(wf, 0, epos)

        _, 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, "epsilon {0}".format(epsilon)
Exemplo n.º 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.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
Exemplo n.º 3
0
 def setup(self):
     self.mol = pyscf.gto.M(atom="O 0 0 0; H 0 -2.757 2.587; H 0 2.757 2.587", basis=f'ccecpccpvdz', ecp='ccecp')
     self.mf = pyscf.scf.RHF(self.mol).run()
     self.configs = pyqmc.initial_guess(self.mol, 500)
     self.slater, self.slater_to_opt =  pyqmc.default_slater(self.mol, self.mf, optimize_orbitals=True)
     self.jastrow, self.jastrow_to_opt =  pyqmc.default_jastrow(self.mol)
     self.pgrad_acc = pyqmc.gradient_generator(self.mol, self.slater, self.slater_to_opt)
     self.slater.recompute(self.configs)
     self.jastrow.recompute(self.configs)
Exemplo n.º 4
0
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 [
            Slater(mol, mf),
            default_jastrow(mol)[0],
            MultiplyWF(Slater(mol, mf),
                       default_jastrow(mol)[0]),
    ]:
        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()
            print("Threshold=", threshold, np.around(end - start, 2), "s")
    mc = mcscf.CASCI(mf, ncas=4, nelecas=(2, 2))
    mc.kernel()

    label = ["MS"]
    ind = 0
    for wf in [Slater(mol, mf, mc)]:
        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()
            print("Threshold=", threshold, np.around(end - start, 2), "s")
Exemplo n.º 5
0
    def setup(self):

        self.cell = pyscf.pbc.gto.Cell()
        self.cell.atom = '''C     0.      0.      0.    
              C     0.8917  0.8917  0.8917
              C     1.7834  1.7834  0.    
              C     2.6751  2.6751  0.8917
              C     1.7834  0.      1.7834
              C     2.6751  0.8917  2.6751
              C     0.      1.7834  1.7834
              C     0.8917  2.6751  2.6751'''
        self.cell.basis = f'ccecpccpvdz'
        self.cell.pseudo = 'ccecp'
        self.cell.a = np.eye(3)*3.5668
        self.cell.exp_to_discard=0.2
        self.cell.build()

        self.configs = pyqmc.initial_guess(self.cell, 500)
        self.jastrow, self.jastrow_to_opt =  pyqmc.default_jastrow(self.cell)
        self.jastrow.recompute(self.configs)