def test_info_functions_pbc(): from pyscf.pbc import gto, scf from pyqmc.supercell import get_supercell mol = gto.Cell(atom="He 0.00 0.00 0.00", basis="ccpvdz", unit="B") mol.a = 5.61 * np.eye(3) mol.build() mf = scf.KRHF(mol, kpts=mol.make_kpts([2, 2, 2])).density_fit() ehf = mf.kernel() supercell = get_supercell(mol, 2 * np.eye(3)) kinds = [0, 1] dm_orbs = [mf.mo_coeff[i][:, :2] for i in kinds] wf, to_opt = pyqmc.default_sj(mol, mf) accumulators = { "pgrad": pyqmc.gradient_generator(mol, wf, to_opt, ewald_gmax=10), "obdm": OBDMAccumulator(mol, dm_orbs, kpts=mf.kpts[kinds]), "Sq": pyqmc.accumulators.SqAccumulator(mol.lattice_vectors()), } info_functions(mol, wf, accumulators)
def test_pbc(): from pyscf.pbc import gto, scf from pyqmc import PySCFSlaterUHF, PySCFSlaterPBC from pyqmc import slaterpbc import scipy lvecs = (np.ones((3, 3)) - np.eye(3)) * 2.0 mol = gto.M( atom="H 0. 0. -{0}; H 0. 0. {0}".format(0.7), basis="sto-3g", unit="bohr", verbose=0, a=lvecs, ) mf = scf.KRHF(mol, kpts=mol.make_kpts((2, 2, 2))) mf = mf.run() S = np.ones((3, 3)) - 2 * np.eye(3) mol = slaterpbc.get_supercell(mol, S) kpts = slaterpbc.get_supercell_kpts(mol)[:2] kdiffs = mf.kpts[np.newaxis] - kpts[:, np.newaxis] kinds = np.nonzero(np.linalg.norm(kdiffs, axis=-1) < 1e-12)[1] # Lowdin orthogonalized AO basis. # lowdin = lo.orth_ao(mol, "lowdin") loiao = lo.iao.iao(mol.original_cell, mf.mo_coeff, kpts=kpts) occs = [mf.mo_occ[k] for k in kinds] coefs = [mf.mo_coeff[k] for k in kinds] ovlp = mf.get_ovlp()[kinds] lowdin = [lo.vec_lowdin(l, o) for l, o in zip(loiao, ovlp)] lreps = [np.linalg.multi_dot([l.T, o, c]) for l, o, c in zip(lowdin, ovlp, coefs)] # make AO to localized orbital coefficients. mfobdm = [np.einsum("ij,j,kj->ik", l.conj(), o, l) for l, o in zip(lreps, occs)] ### Test OBDM calculation. nconf = 800 nsteps = 50 warmup = 6 wf = PySCFSlaterPBC(mol, mf) configs = initial_guess(mol, nconf) obdm_dict = dict(mol=mol, orb_coeff=lowdin, kpts=kpts, nsweeps=4, warmup=10) obdm = OBDMAccumulator(**obdm_dict) obdm_up = OBDMAccumulator(**obdm_dict, spin=0) obdm_down = OBDMAccumulator(**obdm_dict, spin=1) df, coords = vmc( wf, configs, nsteps=nsteps, accumulators={"obdm": obdm, "obdm_up": obdm_up, "obdm_down": obdm_down}, verbose=True, ) df = DataFrame(df) obdm_est = {} for k in ["obdm", "obdm_up", "obdm_down"]: avg_norm = np.array(df.loc[warmup:, k + "norm"].values.tolist()).mean(axis=0) avg_obdm = np.array(df.loc[warmup:, k + "value"].values.tolist()).mean(axis=0) obdm_est[k] = normalize_obdm(avg_obdm, avg_norm) print("Average OBDM(orb,orb)", obdm_est["obdm"].round(3)) mfobdm = scipy.linalg.block_diag(*mfobdm) print("mf obdm", mfobdm.round(3)) max_abs_err = np.max(np.abs(obdm_est["obdm"] - mfobdm)) assert max_abs_err < 0.05, "max abs err {0}".format(max_abs_err) print(obdm_est["obdm_up"].diagonal().round(3)) print(obdm_est["obdm_down"].diagonal().round(3)) mae = np.mean(np.abs(obdm_est["obdm_up"] + obdm_est["obdm_down"] - mfobdm)) maup = np.mean(np.abs(obdm_est["obdm_up"])) madn = np.mean(np.abs(obdm_est["obdm_down"])) mamf = np.mean(np.abs(mfobdm)) assert mae < 0.05, "mae {0}\n maup {1}\n madn {2}\n mamf {3}".format( mae, maup, madn, mamf )
# lattice sum for Vnuc = \sum_{A in unit_cell} \sum_a <i^0 | Z_A/r_A | j^a> shls_slice = [nimgs*nbas1,(nimgs+1)*nbas1,0,nbasN] h1e = molN.intor('int1e_kin', shls_slice=shls_slice[:4]).dot(c) for i in range(unit_cell.natm): molN.set_rinv_orig(unit_cell.atom_coord(i)) h1e -= c.T.dot(molN.intor('int1e_rinv')).dot(c) * unit_cell.atom_charge(i) ovlp = molN.intor('int1e_ovlp', shls_slice=shls_slice[:4]).dot(c) mol = gto.M() mol.nelectron = unit_cell.nelectron mf = scf.RHF(mol) mf.get_hcore = lambda *args: h1e mf.get_ovlp = lambda *args: ovlp mf.get_veff = get_veff mf.energy_nuc = lambda *args: enuc return mf if __name__ == '__main__': R = 3.6 nimgs = 200 unit_cell = gto.M(atom='H 0 0 0; H 1.8 0 0', unit='bohr')#, basis='3-21g') mf = scf.RHF(unit_cell).run() mf = pbc1d_mf(unit_cell, (R,0,0), nimgs).run() from pyscf.pbc import gto, scf, tools, df cell = gto.M(atom='H 0 0 0; H 1.8 0 0', a=numpy.eye(3)*R, unit='bohr', dimension=1)#, basis='321g') mf = scf.KRHF(cell, cell.make_kpts([1,1,1])).density_fit().run()
# ''' # cell.basis = 'gth-szv' # cell.pseudo = 'gth-pade' # cell.a = ''' # 0.000000000, 3.370137329, 3.370137329 # 3.370137329, 0.000000000, 3.370137329 # 3.370137329, 3.370137329, 0.000000000''' cell.build() nmp = [1, 1, 2] nroots_test = 4 # KRHF kpts = cell.make_kpts(nmp) kmf = scf.KRHF(cell, kpts=kpts, exxdiv=None).density_fit() ekrhf = kmf.kernel() # KRCCSD mycc = cc.KRCCSD(kmf) ekrcc, t1, t2 = mycc.kernel() # EOM-EE-KRCCSD myeomee = eom_krccsd.EOMEESinglet(mycc) eee, vee = myeomee.kernel(nroots=nroots_test) # Supercell scell = super_cell(cell, nmp) # Gamma-point RHF based on supercell mf = scf.RHF(scell, exxdiv=None).density_fit()