def test(): from pyscf.pbc import gto, scf import pyqmc import pandas as pd L = 4 mol = gto.M( atom="""H {0} {0} {0}""".format(0.0), basis="sto-3g", a=np.eye(3) * L, spin=1, unit="bohr", ) mf = scf.UKS(mol) mf.xc = "pbe" mf = mf.density_fit().run() wf = pyqmc.PySCFSlaterUHF(mol, mf) ##################################### ## evaluate KE in PySCF ##################################### ke_mat = mol.pbc_intor("int1e_kin", hermi=1, kpts=np.array([0, 0, 0])) dm = mf.make_rdm1() pyscfke = np.einsum("ij,ji", ke_mat, dm[0]) print("PySCF kinetic energy: {0}".format(pyscfke)) ##################################### ## evaluate KE integral on grid ##################################### X = np.linspace(0, 1, 20, endpoint=False) XYZ = np.meshgrid(X, X, X, indexing="ij") pts = [np.outer(p.ravel(), mol.a[i]) for i, p in enumerate(XYZ)] coords = np.sum(pts, axis=0).reshape((-1, 1, 3)) phase, logdet = wf.recompute(coords) psi = phase * np.exp(logdet) lap = wf.laplacian(0, coords.reshape((-1, 3))) gridke = np.sum(-0.5 * lap * psi ** 2) / np.sum(psi ** 2) print("grid kinetic energy: {0}".format(gridke)) ##################################### ## evaluate KE integral with VMC ##################################### coords = pyqmc.initial_guess(mol, 600, 0.7) coords = PeriodicConfigs(coords, mol.a) warmup = 10 df, coords = pyqmc.vmc( wf, coords, nsteps=128 + warmup, tstep=L * 0.6, accumulators={"energy": pyqmc.accumulators.EnergyAccumulator(mol)}, ) df = pd.DataFrame(df) reblocked = pyqmc.reblock.optimally_reblocked(df["energyke"][warmup:]) print( "VMC kinetic energy: {0} $\pm$ {1}".format( reblocked["mean"], reblocked["standard error"] ) )
def test_init(self): from pyscf.pbc import dft cell_u = cell.copy() cell_u.spin = 2 self.assertTrue(isinstance(pscf.RKS (cell ), dft.rks.RKS )) self.assertTrue(isinstance(pscf.RKS (cell_u), dft.roks.ROKS )) self.assertTrue(isinstance(pscf.UKS (cell ), dft.uks.UKS )) self.assertTrue(isinstance(pscf.ROKS (cell ), dft.roks.ROKS )) self.assertTrue(isinstance(pscf.KS (cell ), dft.rks.RKS )) self.assertTrue(isinstance(pscf.KS (cell_u), dft.uks.UKS )) self.assertTrue(isinstance(pscf.KRKS (cell ), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KRKS (cell_u), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KUKS (cell ), dft.kuks.KUKS )) self.assertTrue(isinstance(pscf.KROKS(cell ), dft.kroks.KROKS)) self.assertTrue(isinstance(pscf.KKS (cell ), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KKS (cell_u), dft.kuks.KUKS )) self.assertTrue(isinstance(pscf.RHF (cell ), pscf.hf.RHF )) self.assertTrue(isinstance(pscf.RHF (cell_u), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.KRHF (cell ), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.KRHF (cell_u), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.UHF (cell ), pscf.uhf.UHF )) self.assertTrue(isinstance(pscf.KUHF (cell_u), pscf.kuhf.KUHF )) self.assertTrue(isinstance(pscf.GHF (cell ), pscf.ghf.GHF )) self.assertTrue(isinstance(pscf.KGHF (cell_u), pscf.kghf.KGHF )) self.assertTrue(isinstance(pscf.ROHF (cell ), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.ROHF (cell_u), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.KROHF(cell ), pscf.krohf.KROHF)) self.assertTrue(isinstance(pscf.KROHF(cell_u), pscf.krohf.KROHF)) self.assertTrue(isinstance(pscf.HF (cell ), pscf.hf.RHF )) self.assertTrue(isinstance(pscf.HF (cell_u), pscf.uhf.UHF )) self.assertTrue(isinstance(pscf.KHF (cell ), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.KHF (cell_u), pscf.kuhf.KUHF ))
def multislater(kind=0, nk=(1, 1, 1)): L = 3 mol = gto.Cell( atom="""H {0} {0} {0} H {1} {1} {1}""".format(0.0, L / 2), basis="cc-pvtz", spin=0, unit="bohr", ) mol.exp_to_discard = 0.1 mol.build(a=np.eye(3) * L) kpts = mol.make_kpts(nk) mf = scf.UKS(mol, (0, 0, 0)) mf.xc = "pbe" mf = multigrid(mf) mf = remove_linear_dep_(mf) mf.chkfile = "h_bcc.chkfile" mf = mf.run() runtest(mol, mf, kind=kind, do_mc=True)