How to use the pyqmc.pbc.enforce_pbc 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_twist.py View on Github external
#####################################
    ## compare values across boundary
    ## psi, KE, ecp,
    #####################################
    nconfig = 100
    coords = pyqmc.initial_guess(mol, nconfig, 1)
    nelec = coords.configs.shape[1]
    epos, wrap = enforce_pbc(coords.lvecs, coords.configs)
    coords = PeriodicConfigs(epos, coords.lvecs)

    shift_ = np.random.randint(10, size=coords.configs.shape) - 5
    phase = np.exp(2j * np.pi * np.einsum("ijk,k->ij", shift_, twist))

    shift = np.dot(shift_, mol.lattice_vectors())
    epos, wrap = enforce_pbc(coords.lvecs, epos + shift)
    newcoords = PeriodicConfigs(epos, coords.lvecs, wrap=wrap)

    assert np.linalg.norm(newcoords.configs - coords.configs) < 1e-12

    ph0, val0 = wf0.recompute(coords)
    pht, valt = wft.recompute(coords)
    enacc = pyqmc.accumulators.EnergyAccumulator(mol, threshold=np.inf)
    np.random.seed(0)
    en0 = enacc(coords, wf0)
    np.random.seed(0)
    ent = enacc(coords, wft)

    e = 0
    rat0 = wf0.testvalue(e, newcoords.electron(e))
    assert np.linalg.norm(rat0 - 1) < 1e-10, rat0 - 1
    ratt = wft.testvalue(e, newcoords.electron(e))
github WagnerGroup / pyqmc / tests / test_pbcs.py View on Github external
[
                [0.1, 0.1, 0.1],
                [0.1, 0, 0.2],
                [0.3, 0.6 * np.sqrt(3) / 2, 0.0],
                [0, 0, 0.3],
                [0.54, 0.31176915, 0],
                [1.08, 0.2078461, 0],
                [1.08, 0.2078461, 0.48],
            ]
        )
        + 1e-14
    )
    check_wrap = np.array(
        [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 0], [-1, 1, 0], [-4, 2, -1]]
    )
    final_trans, final_wrap = enforce_pbc(lattvecs, trans)
    # Checks output configs
    relative_tol = 1e-8
    absolute_tol = 1e-8
    test1a = np.all(
        np.isclose(final_trans, check_final, rtol=relative_tol, atol=absolute_tol)
    )
    # Checks wraparound matrix
    test1b = np.all(
        np.isclose(final_wrap, check_wrap, rtol=relative_tol, atol=absolute_tol)
    )
    test1 = test1a * test1b
    print("Test 1 success:", test1)

    # TEST 2: Check if any electron in new config
    #         is out of the simulation box for set
    #         of non-orthogonal lattice vectors.
github WagnerGroup / pyqmc / tests / integration / test_twist.py View on Github external
print(k, occ)
    kpt = mf.kpts[kind]
    twist = np.dot(kpt, mol.lattice_vectors().T / (2 * np.pi))
    print("kpt", kpt)
    print("twist", twist)
    wf0 = pyqmc.PySCFSlater(mol, mf)
    wft = pyqmc.PySCFSlater(mol, mf, twist=twist)

    #####################################
    ## compare values across boundary
    ## psi, KE, ecp,
    #####################################
    nconfig = 100
    coords = pyqmc.initial_guess(mol, nconfig, 1)
    nelec = coords.configs.shape[1]
    epos, wrap = enforce_pbc(coords.lvecs, coords.configs)
    coords = PeriodicConfigs(epos, coords.lvecs)

    shift_ = np.random.randint(10, size=coords.configs.shape) - 5
    phase = np.exp(2j * np.pi * np.einsum("ijk,k->ij", shift_, twist))

    shift = np.dot(shift_, mol.lattice_vectors())
    epos, wrap = enforce_pbc(coords.lvecs, epos + shift)
    newcoords = PeriodicConfigs(epos, coords.lvecs, wrap=wrap)

    assert np.linalg.norm(newcoords.configs - coords.configs) < 1e-12

    ph0, val0 = wf0.recompute(coords)
    pht, valt = wft.recompute(coords)
    enacc = pyqmc.accumulators.EnergyAccumulator(mol, threshold=np.inf)
    np.random.seed(0)
    en0 = enacc(coords, wf0)
github WagnerGroup / pyqmc / pyqmc / multislaterpbc.py View on Github external
def evaluate_orbitals(self, configs, mask=None, eval_str="PBCGTOval_sph"):
        mycoords = configs.configs
        configswrap = configs.wrap
        if mask is not None:
            mycoords = mycoords[mask]
            configswrap = configswrap[mask]
        mycoords = mycoords.reshape((-1, mycoords.shape[-1]))
        # wrap supercell positions into primitive cell
        prim_coords, prim_wrap = pbc.enforce_pbc(self._mol.lattice_vectors(), mycoords)
        configswrap = configswrap.reshape(prim_wrap.shape)
        wrap = prim_wrap + np.dot(configswrap, self.supercell.S)
        kdotR = np.linalg.multi_dot((self._kpts, self._mol.lattice_vectors().T, wrap.T))
        wrap_phase = self.get_wrapphase(kdotR)
        # evaluate AOs for all electron positions
        ao = self._mol.eval_gto(eval_str, prim_coords, kpts=self._kpts)
        ao = [ao[k] * wrap_phase[k][:, np.newaxis] for k in range(self.nk)]
        return ao
github WagnerGroup / pyqmc / pyqmc / obdm.py View on Github external
def _evaluate_orbitals_pbc(self, configs):
        # wrap supercell positions into primitive cell
        lvecs = self._mol.lattice_vectors()
        prim_coords, prim_wrap = pbc.enforce_pbc(lvecs, configs.configs)
        wrap = prim_wrap + np.dot(configs.wrap, self.supercell.S)
        wrap = wrap.reshape(-1, 3)
        prim_coords = prim_coords.reshape(-1, 3)
        kdotR = np.linalg.multi_dot((self._kpts, lvecs.T, wrap.T))
        wrap_phase = self.get_wrapphase(kdotR)
        # evaluate AOs for all electron positions
        ao = self._mol.eval_gto("PBCGTOval_sph", prim_coords, kpts=self._kpts)
        ao = [aok * wrap_phase[k][:, np.newaxis] for k, aok in enumerate(ao)]
        borb = [aok.dot(ock) for aok, ock in zip(ao, self._orb_coeff)]
        return np.concatenate(borb, axis=1)
github WagnerGroup / pyqmc / pyqmc / coord.py View on Github external
def __init__(self, configs, lattice_vectors, wrap=None):
        configs, wrap_ = enforce_pbc(lattice_vectors, configs)
        self.configs = configs
        self.wrap = wrap_
        if wrap is not None:
            self.wrap += wrap
        self.lvecs = lattice_vectors
        self.dist = MinimalImageDistance(lattice_vectors)
github WagnerGroup / pyqmc / pyqmc / slater.py View on Github external
def _evaluate_orbitals_pbc(self, configs, mask=None, eval_str="GTOval_sph"):
        mycoords = configs.configs
        configswrap = configs.wrap
        if mask is not None:
            mycoords = mycoords[mask]
            configswrap = configswrap[mask]
        mycoords = mycoords.reshape((-1, mycoords.shape[-1]))
        # wrap supercell positions into primitive cell
        prim_coords, prim_wrap = pbc.enforce_pbc(self._cell.lattice_vectors(), mycoords)
        configswrap = configswrap.reshape(prim_wrap.shape)
        wrap = prim_wrap + np.dot(configswrap, self.supercell.S)
        kdotR = np.linalg.multi_dot(
            (self._kpts, self._cell.lattice_vectors().T, wrap.T)
        )
        wrap_phase = self.get_wrapphase(kdotR)
        # evaluate AOs for all electron positions
        ao = self._cell.eval_gto("PBC" + eval_str, prim_coords, kpts=self._kpts)
        ao = [ao[k] * wrap_phase[k][:, np.newaxis] for k in range(self.nk)]
        return ao