def test_rhf_0d(self): from pyscf.df import mdf_jk from pyscf.scf import hf L = 4 cell = pbcgto.Cell() cell.build(unit = 'B', a = numpy.eye(3)*L*5, gs = [10]*3, atom = '''He 2 2 2; He 2 2 3''', dimension = 0, verbose = 0, basis = { 'He': [[0, (0.8, 1.0)], [0, (1.0, 1.0)], [0, (1.2, 1.0)]]}) mol = cell.to_mol() mf = mdf_jk.density_fit(hf.RHF(mol)) mf.with_df.gs = [10]*3 mf.with_df.auxbasis = {'He':[[0, (1e6, 1)]]} mf.with_df.charge_constraint = False mf.with_df.metric = 'S' eref = mf.kernel() mf = pbchf.RHF(cell) mf.with_df = pdf.PWDF(cell) mf.get_hcore = lambda *args: hf.get_hcore(mol) mf.energy_nuc = lambda *args: mol.energy_nuc() e1 = mf.kernel() self.assertAlmostEqual(e1, eref, 8)
def test_rhf_0d(self): from pyscf.df import mdf_jk from pyscf.scf import hf L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=numpy.eye(3) * L * 5, gs=[10] * 3, atom='''He 2 2 2; He 2 2 3''', dimension=0, verbose=0, basis={'He': [[0, (0.8, 1.0)], [0, (1.0, 1.0)], [0, (1.2, 1.0)]]}) mol = cell.to_mol() mf = mdf_jk.density_fit(hf.RHF(mol)) mf.with_df.gs = [10] * 3 mf.with_df.auxbasis = {'He': [[0, (1e6, 1)]]} mf.with_df.charge_constraint = False mf.with_df.metric = 'S' eref = mf.kernel() mf = pbchf.RHF(cell) mf.with_df = pdf.PWDF(cell) mf.exxdiv = None mf.get_hcore = lambda *args: hf.get_hcore(mol) mf.energy_nuc = lambda *args: mol.energy_nuc() e1 = mf.kernel() self.assertAlmostEqual(e1, eref, 8)
def init_guess_by_wolfsberg_helmholtz(mol): """Diagonal will be taken from core hamiltonian, the off diagonal elements are interpolated by wolfsberg helmholtz scheme. H_ji = k_ji (H_ii + H_ij) S_ij / 2, with k_ij =1.75 (Generalized Wolfsberg Helmholtz GWH). See here: http://www.q-chem.com/qchem-website/manual/qchem50_manual/sect-initialguess.html M. Wolfsberg and L. Helmholz, J. Chem. Phys. 20, 837 (1952). """ from pyscf.scf.hf import eig, get_hcore, get_ovlp, get_occ, make_rdm1, SCF import numpy H = numpy.diag(get_hcore(mol)) k = numpy.ones((len(H), len(H))) * 1.75 - \ numpy.diag(numpy.ones(H.shape)) * 0.75 S = get_ovlp(mol) H = k * numpy.add.outer(H, H) * S / 2 mo_energy, mo_coeff = eig(H, S) mo_occ = get_occ(SCF(mol), mo_energy, mo_coeff) return make_rdm1(mo_coeff, mo_occ)
def get_hcore(ks,mol=None): if mol is None: mol = ks.mol h = hf.get_hcore(mol) if ks.vext_1e is not None: h = h + ks.vext_1e return h
def get_hcore(self, mol=None): if mol is None: mol = self.mol hcore = hf.get_hcore(mol) hcore = scipy.linalg.block_diag(hcore, hcore) if self.with_soc and mol.has_ecp_soc(): # The ECP SOC contribution = <|1j * s * U_SOC|> s = .5 * lib.PauliMatrices ecpso = numpy.einsum('sxy,spq->xpyq', -1j * s, mol.intor('ECPso')) hcore = hcore + ecpso.reshape(hcore.shape) return hcore
def get_hcore(mf, mol=None): if mol is None: mol = mf.mol h = 0.0 if (mf.oei is not None): h = mf.oei else: h = hf.get_hcore(mol) if mf.vext_1e is not None: h = h + mf.vext_1e return h
def test_gwh_by_density(self): from SCFInitialGuess.construction.fock import gwh_scheme mol = self.molecule h = hf.get_hcore(mol) s = hf.get_ovlp(mol) f_gwh = gwh_scheme(np.diag(h), s) p_gwh = density_from_fock(f_gwh, s, mol) #TODO: use pyscf method p_ref = init_guess_by_wolfsberg_helmholtz(mol) np.testing.assert_allclose(p_gwh, p_ref)
def energy_elec(ks, dm=None, h1e=None, vhf=None): tot_e,e_hxc = rks.energy_elec(ks, dm=dm, h1e=h1e, vhf=vhf) if(ks.smear_sigma > 1e-8 ): #add entropy contribution tot_e += entropy_corr(ks.mo_occ, ks.smear_sigma) #add frozen density hcore energy if(isinstance(ks.coredm, numpy.ndarray) and ks.coredm.ndim == 2): h = hf.get_hcore(ks.mol) if(ks.add_coredm_ext_energy == True): h = h + ks.vext_1e e1 = numpy.einsum('ij,ji', h, ks.coredm).real tot_e += e1 return tot_e, e_hxc
def get_hcore(self, mol=None): if mol is None: mol = self.mol hcore = hf.get_hcore(mol) return scipy.linalg.block_diag(hcore, hcore)