Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(Lvecs, configs, nq):
sqacc = SqAccumulator(Lvecs=Lvecs, nq=nq)
configs = PeriodicConfigs(configs, Lvecs)
sqavg = sqacc.avg(configs, None)
df = {"qmag": np.linalg.norm(sqacc.qlist, axis=1)}
df.update(sqavg)
return pd.DataFrame(df)
#####################################
## 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))
rattdiff = ratt - phase[:, e]
def get_ewald_energy(cell, S, configs):
supercell = get_supercell(cell, S)
ewald = pyqmc.ewald.Ewald(supercell)
configs = PeriodicConfigs(configs, supercell.lattice_vectors())
ee, ei, ii = ewald.energy(configs)
etot = ee + ei + ii
print(dict(ee=ee, ei=ei, ii=ii))
print("total energy", etot)
return etot
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)
np.random.seed(0)
def electron(self, e):
return PeriodicConfigs(self.configs[:, e], self.lvecs, wrap=self.wrap[:, e])
def make_irreducible(self, e, vec):
"""
Input: a (nconfig, 3) vector
Output: a tuple with the wrapped vector and the number of wraps
"""
epos, wrap = enforce_pbc(self.lvecs, vec)
currentwrap = self.wrap if len(self.wrap.shape) == 2 else self.wrap[:, e]
if len(vec.shape) == 3:
currentwrap = currentwrap[:, np.newaxis]
return PeriodicConfigs(epos, self.lvecs, wrap=wrap + currentwrap)
def mask(self, mask):
return PeriodicConfigs(self.configs[mask], self.lvecs, wrap=self.wrap[mask])