Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
],
):
from pyqmc.jastrowspin import JastrowSpin
from pyqmc.dmc import limdrift, rundmc
from pyqmc.mc import vmc
from pyqmc.accumulators import EnergyAccumulator
from pyqmc.func3d import CutoffCuspFunction
from pyqmc.multiplywf import MultiplyWF
from pyqmc.coord import OpenConfigs
import pandas as pd
mol = gto.M(atom="H 0. 0. 0.", basis="sto-3g", unit="bohr", spin=1)
mf = scf.UHF(mol).run()
nconf = 1000
configs = OpenConfigs(np.random.randn(nconf, 1, 3))
wf1 = PySCFSlaterUHF(mol, mf)
wf = wf1
wf2 = JastrowSpin(mol, a_basis=[CutoffCuspFunction(5, 0.2)], b_basis=[])
wf2.parameters["acoeff"] = np.asarray([[[1.0, 0]]])
wf = MultiplyWF(wf1, wf2)
dfvmc, configs_ = vmc(
wf, configs, nsteps=50, accumulators={"energy": EnergyAccumulator(mol)}
)
dfvmc = pd.DataFrame(dfvmc)
print(
"vmc energy",
np.mean(dfvmc["energytotal"]),
np.std(dfvmc["energytotal"]) / np.sqrt(len(dfvmc)),
)
warmup = 200
dfdmc, configs_, weights_ = rundmc(
wf,
print("Warning: using both ECP and ion_cusp")
elif ion_cusp is None:
ion_cusp = [l for l in mol._basis.keys() if l not in mol._ecp.keys()]
print("default ion_cusp:", ion_cusp)
else:
assert isinstance(ion_cusp, list)
if len(ion_cusp) > 0:
abasis = [CutoffCuspFunction(gamma=24, rcut=rcut)]
else:
abasis = []
abasis += [PolyPadeFunction(beta=ba, rcut=rcut) for ba in beta_abasis]
bbasis = [CutoffCuspFunction(gamma=24, rcut=rcut)]
bbasis += [PolyPadeFunction(beta=bb, rcut=rcut) for bb in beta_bbasis]
jastrow = JastrowSpin(mol, a_basis=abasis, b_basis=bbasis)
if len(ion_cusp) > 0:
coefs = mol.atom_charges().copy()
coefs[[l[0] not in ion_cusp for l in mol._atom]] = 0.0
jastrow.parameters["acoeff"][:, 0, :] = coefs[:, None]
jastrow.parameters["bcoeff"][0, [0, 1, 2]] = np.array([-0.25, -0.50, -0.25])
to_opt = {}
to_opt["acoeff"] = np.ones(jastrow.parameters["acoeff"].shape).astype(bool)
if len(ion_cusp) > 0:
to_opt["acoeff"][:, 0, :] = False # Cusp conditions
to_opt["bcoeff"] = np.ones(jastrow.parameters["bcoeff"].shape).astype(bool)
to_opt["bcoeff"][0, [0, 1, 2]] = False # Cusp conditions
return jastrow, to_opt