def test_init_mp2(self): mf0 = mf mf1 = scf.RHF(gto.M(atom='H', spin=1)) self.assertTrue(isinstance(mp.MP2(mf0), mp.mp2.RMP2)) self.assertTrue(isinstance(mp.MP2(mf1), mp.ump2.UMP2)) self.assertTrue(isinstance(mp.MP2(mf0.density_fit()), mp.dfmp2.DFMP2)) #self.assertTrue(isinstance(mp.MP2(mf1.density_fit()), mp.dfmp2.DFUMP2)) self.assertTrue(isinstance(mp.MP2(mf0.newton()), mp.mp2.RMP2)) self.assertTrue(isinstance(mp.MP2(mf1.newton()), mp.ump2.UMP2))
def test_mbpt2(self): myucc = uccsd.UCCSD(mf) e = myucc.kernel(mbpt2=True)[0] self.assertAlmostEqual(e, -0.12886859466216125, 10) emp2 = mp.MP2(mf).kernel()[0] self.assertAlmostEqual(e, emp2, 10) myucc = uccsd.UCCSD(mf_s2) e = myucc.kernel(mbpt2=True)[0] self.assertAlmostEqual(e, -0.096257842171487293, 10) emp2 = mp.MP2(mf_s2).kernel()[0] self.assertAlmostEqual(e, emp2, 10)
def test_ump2_outcore_frozen(self): pt = mp.MP2(mf) pt.max_memory = 0 pt.nmo = (12, 11) pt.frozen = [[4, 5], [2, 3]] e = pt.kernel(with_t2=False)[0] self.assertAlmostEqual(e, -0.033400699456971966, 9) pt = mp.MP2(mf) pt.nmo = (12, 11) pt.nocc = (4, 2) e = pt.kernel(with_t2=False)[0] self.assertAlmostEqual(e, -0.033400699456971966, 9)
def _run_mp2(self, hf=None, **kwargs): from pyscf import mp if hf is None: hf = self._get_hf(**kwargs) mp2 = mp.MP2(hf) mp2.kernel() return mp2
def test_MP2_grad(self): from pkg_resources import resource_filename from pyxdhalpha.Utilities.test_molecules import Mol_H2O2 from pyxdhalpha.Utilities import FormchkInterface from pyscf import mp, grad H2O2 = Mol_H2O2() config = { "scf_eng": H2O2.hf_eng } gmh = GradMP2(config) mp2_eng = mp.MP2(gmh.scf_eng) mp2_eng.kernel() mp2_grad = grad.mp2.Gradients(mp2_eng) mp2_grad.kernel() assert(np.allclose( gmh.E_1, mp2_grad.de, atol=1e-6, rtol=1e-4 )) formchk = FormchkInterface(resource_filename("pyxdhalpha", "Validation/gaussian/H2O2-MP2-freq.fchk")) assert(np.allclose( gmh.E_1, formchk.grad(), atol=1e-6, rtol=1e-4 ))
def _pyscf_qm(qm_atnm, qm_crds, qm_basis, qm_chg_tot, l_mp2=False, l_esp=False, esp_opts={}): atm_list = [] for ia, xyz in enumerate(qm_crds): sym = qm_atnm[ia] atm_list.append([sym, (xyz[0], xyz[1], xyz[2])]) qm_mol = _pyscf_mol_build(atm_list, qm_basis, qm_chg_tot) mf = scf.RHF(qm_mol) mf.run() esp_chg = None if l_mp2: postmf = mp.MP2(mf).run() ener_QM = postmf.e_tot grds_QM = postmf.Gradients().kernel() if l_esp: dm = make_rdm1_with_orbital_response(postmf) esp_chg = esp_atomic_charges(qm_mol, dm, esp_opts) else: ener_QM = mf.e_tot grds_QM = mf.Gradients().kernel() if l_esp: dm = mf.make_rdm1() esp_chg = esp_atomic_charges(qm_mol, dm, esp_opts) return ener_QM, grds_QM, esp_chg
def test_frozen(self): pt = mp.MP2(mf) pt.frozen = [0,1,10,11,12] pt.max_memory = 1 pt.kernel() g1 = ump2_grad.Gradients(pt).kernel(pt.t2) self.assertAlmostEqual(lib.finger(g1), -0.22437278030057645, 6)
def test_make_natural_orbitals_from_restricted(self): from pyscf import mp, ci, cc npt = numpy.testing mol = gto.M(atom='C 0 0 0; O 0 0 1.2', basis='3-21g', spin=0) myhf = scf.RHF(mol).run() ncas, nelecas = (8, 10) mymc = mcscf.CASCI(myhf, ncas, nelecas) # Test MP2 # Trusted results from ORCA v4.2.1 rmp2_noons = [ 1.99992732, 1.99989230, 1.99204357, 1.98051334, 1.96825487, 1.94377615, 1.94376239, 0.05792320, 0.05791037, 0.02833335, 0.00847013, 0.00531989, 0.00420320, 0.00420280, 0.00257965, 0.00101638, 0.00101606, 0.00085503 ] mymp = mp.MP2(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(mymp) npt.assert_array_almost_equal(rmp2_noons, noons, decimal=5) mymc.kernel(natorbs) # The tests below are only to ensure that `make_natural_orbitals` can # run at all since we've confirmed above that the NOONs are correct. # Test CISD mycisd = ci.CISD(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(mycisd) mymc.kernel(natorbs) # Test CCSD myccsd = cc.CCSD(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(myccsd) mymc.kernel(natorbs)
def run_pyscf_mp2(mol=None, hf=None, **kwargs): from pyscf import mp if hf is None: hf = compute_pyscf_hf(mol=mol, **kwargs) mp2 = mp.MP2(hf) mp2.kernel() return mp2
def get_h(self, iexe=True, href=None, frozen=0): """ get hamitonian of the sysem, which is to be described by a hf/dft single slater determinant :param href: reference hamiltonian, could be hf/uhf/rohf/rks/uks :type href: str """ meth = self.meth self.xc = None if href is None: if meth in [ 'eht', 'hf', 'mp2', 'cisd', 'ccsd', ]: fun = scf.RHF if self.restricted else scf.UHF mf = fun(self.mol) elif meth in ['pbe', 'b3lyp', 'w95xb']: fun = dft.RKS if self.restricted else dft.UKS mf = fun(self.mol) mf.xc = meth self.xc = meth else: raise Exception('Unknow method: %s' % meth) else: dct = {'rohf':scf.ROHF, 'rhf':scf.RHF, 'hf':scf.RHF,\ 'rks': dft.RKS, 'uks':dft.UKS, 'ks':dft.RKS} assert href in dct fun = dct[href] mf = fun(self.mol) if 'ks' in href: mf.xc = meth if iexe: mf.kernel() self.mf = mf h2 = None self.isd = T # single (slater) determinant # final hamiltonian if meth[:2] in ['mp', 'ci', 'cc']: self.isd = F if meth in ['mp2', 'mp3', 'mp4']: h2 = mp.MP2(self.mf) #.set(frozen=frozen) elif meth in [ 'cisd', ]: h2 = ci.CISD(self.mf) #.set(frozen=frozen) elif meth in ['ccsd', 'ccsd(t)']: h2 = cc.CCSD(self.mf) #.set(frozen=frozen) h2.direct = True else: raise Exception('Todo') if frozen: h2.set(frozen=frozen) if iexe: h2.kernel() self.h2 = h2
def test_as_scanner(self): pt = mp.MP2(mf) pt.frozen = [0,1,10,11,12] gscan = pt.nuc_grad_method().as_scanner() e, g1 = gscan(mol) self.assertTrue(gscan.converged) self.assertAlmostEqual(e, -75.759091758835353, 9) self.assertAlmostEqual(lib.finger(g1), -0.22437278030057645, 6)
def test_energy_skip(self): mol = gto.Mole(atom='Ne', basis='ccpvdz') mf = scf.RHF(mol).run() auxmol = gto.M(atom=mol.atom, basis=('ccpvdz-fit', 'cc-pVDZ-F12-OptRI'), verbose=0) e = mp.MP2(mf).kernel()[0] + mp2f12.energy_f12(mf, auxmol, 1.) self.assertAlmostEqual(e, -0.27522161783457028, 9)
def mol_electron(mol, frozen=0, chkfile=None, verbose=False): if verbose: start_t = time() nao = mol.nao natm = mol.natm rhf = scf.RHF(mol) if chkfile: rhf.set(chkfile=chkfile) erhf = rhf.kernel() if verbose: rhf_t = time() print(f"time of rhf: {rhf_t - start_t}") mo_energy = rhf.mo_energy mo_occ = rhf.mo_occ # mo_coeff = rhf.mo_coeff mo_coeff_ = rhf.mo_coeff mo_coeff = fix_gauge(mo_coeff_) occ_a = (mo_occ > 0) occ_a[:frozen] = False # occ_b = (mo_occ[1]>0) vir_a = (mo_occ == 0) # vir_b = (mo_occ[1]==0) nocc_a = sum(occ_a) # nocc_b = sum(occ_b) nocc = nocc_a nvir_a = sum(vir_a) # nvir_b = sum(vir_b) nvir = nvir_a assert (nocc + nvir + frozen == nao) if verbose: print('nao = %d, nocc = %d, nvir = %d' % \ (nao, nocc, nvir)) print('shape of a and b coeffs: ', mo_coeff[0].shape, mo_coeff[1].shape) c_occ = mo_coeff[:, occ_a] c_vir = mo_coeff[:, vir_a] e_occ = mo_energy[occ_a] e_vir = mo_energy[vir_a] c_occ = c_occ.T c_vir = c_vir.T meta = [natm, nao, nocc, nvir] if verbose: print('shape of coeff data ', c_occ.shape) print('shape of ener data ', e_occ.shape) print('shape of coeff data ', c_vir.shape) print('shape of ener data ', e_vir.shape) mid_t = time() # print(f"time of collecting results: {mid_t - rhf_t}") mp2 = mp.MP2(rhf, frozen=frozen) # emp2 = mp2.kernel() emp2, emp2_ij = my_kernel(mp2) if verbose: print('E(HF) = %.9g' % erhf) print('E(RMP2) = %.9g' % emp2) print(f"time of mp2: {time()-mid_t}") return meta, erhf, emp2, emp2_ij, (e_occ, e_vir), (c_occ, c_vir)
def test_ump2(self): pt = mp.MP2(mf) emp2, t2 = pt.kernel(mf.mo_energy, mf.mo_coeff) self.assertAlmostEqual(emp2, -0.16575150552336643, 9) pt.max_memory = 1 pt.frozen = None emp2, t2 = pt.kernel() self.assertAlmostEqual(emp2, -0.16575150552336643, 9)
def get_mp2_energy(self): if self.spin == 0: mf = scf.RHF(self.mol) else: mf = scf.UHF(self.mol) e0 = mf.kernel() mp2 = mp.MP2(mf) ecorr = mp2.kernel()[0] return e0, ecorr, e0+ecorr
def test_check_mp2_energy(self): mp2 = mp.MP2(mf) e_mp2 = mp2.kernel()[0] myadc.max_memory = 20 e_adc_mp2, t_amp1, t_amp2 = myadc.kernel_gs() diff_mp2 = e_adc_mp2 - e_mp2 self.assertAlmostEqual(diff_mp2, 0.0000000000000, 6)
def __init__(self, mf): self.mf = mf self.mp_ee = mp.MP2(self.mf.mf_elec) if(self.mf.unrestricted==True): raise NotImplementedError('NEO-MP2 is for RHF wave functions only') if(len(self.mf.mol.nuc)>1): raise NotImplementedError('NEO-MP2 is for single quantum nuclei')
def get_MP2_natural_orbitals(mf, n, nfreeze): mp2 = mp.MP2(mf, nfreeze) mp2.kernel() C_mf = mf.mo_coeff rho = mp2.make_rdm1() n_mp, UU = np.linalg.eigh(rho) idx = n_mp.argsort()[::-1] n_mp = n_mp[idx] UU = UU[:, idx] C_mp = np.dot(mf.mo_coeff, UU) return C_mp[:, :n]
def mp2_energy(self, dim): print("ECW method is MP2") energy = 0.0 Ne_frag = self.Ne_frag ops = self.ops umat = self.umat Ne_env = self.Ne_env P_bath_JK = libgen.coreJK_sub( self.ints, self.loc2sub, dim, tools.dm_sub2ao(self.P_bath, self.loc2sub[:, :dim]), Ne_env, 1.0) subOEI = ops["subKin"] + ops["subVnuc1"] + ops[ "subVnuc2"] + P_bath_JK + 0.5 * 1e4 * self.P_bath #subOEI = ops["subKin"]+ops["subVnuc1"]+ops["subVnuc_bound1"]+umat subTEI = ops["subTEI"] mf = qcwrap.qc_scf(Ne_frag, dim, 'hf', mol=self.mol, oei=subOEI, tei=subTEI, dm0=self.P_imp) mf.runscf() #self.ints.submo_molden( mf.mo_coeff, mf.mo_occ, self.loc2sub, 'mo_imp.molden' ) print('|diffP| = ', np.linalg.norm(mf.rdm1 + self.P_bath - self.P_ref_sub)) print("mo_energy") print(mf.mo_energy) e_emb = 0.0 #onedm = mf.make_rdm1() #e_emb=np.trace(np.dot(umat,onedm)) #print "diffP = ",np.linalg.norm(self.P_imp - onedm) mp2 = mp.MP2(mf) mp2.kernel() e_mp2 = mf.elec_energy + mp2.e_corr e_mp2 -= e_emb imp_mf_energy = self.imp_mf_energy(dim) energy = e_mp2 - imp_mf_energy print("dmfet correction energy = ", energy) return energy
def test_r_mp2_grad(self): scf_eng = scf.RHF(self.mol).run() mp2_eng = mp.MP2(scf_eng).run() mp2_grad = mp2_eng.Gradients().run() gradh = GradMP2({"scf_eng": scf_eng}) formchk = FormchkInterface(resource_filename("pyxdh", "Validation/gaussian/NH3-MP2-freq.fchk")) # ASSERT: energy - Gaussian assert np.allclose(gradh.eng, formchk.total_energy()) # ASSERT: energy - PySCF assert np.allclose(gradh.eng, mp2_eng.e_tot) # ASSERT: grad - Gaussian assert np.allclose(gradh.E_1, formchk.grad(), atol=1e-6, rtol=1e-4) # ASSERT: grad - PySCF assert np.allclose(gradh.E_1, mp2_grad.de, atol=1e-6, rtol=1e-4)
def FNOCCSD(mf, thresh=1e-6, pct_occ=None, nvir_act=None): """Frozen natural orbital CCSD Attributes: thresh : float Threshold on NO occupation numbers. Default is 1e-6 (very conservative). pct_occ : float Percentage of total occupation number. Default is None. If present, overrides `thresh`. nvir_act : int Number of virtual NOs to keep. Default is None. If present, overrides `thresh` and `pct_occ`. """ from pyscf import mp pt = mp.MP2(mf).set(verbose=0).run() frozen, no_coeff = pt.make_fno(thresh=thresh, pct_occ=pct_occ, nvir_act=nvir_act) pt_no = mp.MP2(mf, frozen=frozen, mo_coeff=no_coeff).set(verbose=0).run() mycc = ccsd.CCSD(mf, frozen=frozen, mo_coeff=no_coeff) mycc.delta_emp2 = pt.e_corr - pt_no.e_corr from pyscf.lib import logger def _finalize(self): '''Hook for dumping results and clearing up the object.''' if self.converged: logger.info(self, 'FNO-%s converged', self.__class__.__name__) else: logger.note(self, 'FNO-%s not converged', self.__class__.__name__) logger.note(self, 'E(FNO-%s) = %.16g E_corr = %.16g', self.__class__.__name__, self.e_tot, self.e_corr) logger.note(self, 'E(FNO-%s+delta-MP2) = %.16g E_corr = %.16g', self.__class__.__name__, self.e_tot + self.delta_emp2, self.e_corr + self.delta_emp2) return self mycc._finalize = _finalize.__get__(mycc, mycc.__class__) return mycc
def test_mp2(self): nocc = mol.nelectron // 2 nmo = mf.mo_energy.size nvir = nmo - nocc co = mf.mo_coeff[:, :nocc] cv = mf.mo_coeff[:, nocc:] g = ao2mo.incore.general(mf._eri, (co, cv, co, cv)).ravel() eia = mf.mo_energy[:nocc, None] - mf.mo_energy[nocc:] t2ref0 = g / (eia.reshape(-1, 1) + eia.reshape(-1)).ravel() t2ref0 = t2ref0.reshape(nocc, nvir, nocc, nvir).transpose(0, 2, 3, 1) pt = mp.MP2(mf) emp2, t2 = pt.kernel() self.assertAlmostEqual(emp2, -0.204019967288338, 9)
def test_rdm_complex(self): mol = gto.M() mol.verbose = 0 nocc = 3 nvir = 4 mf = scf.RHF(mol) nmo = nocc + nvir numpy.random.seed(1) eri = (numpy.random.random((nmo, nmo, nmo, nmo)) + numpy.random.random( (nmo, nmo, nmo, nmo)) * 1j - (.5 + .5j)) eri = eri + eri.transpose(1, 0, 3, 2).conj() eri = eri + eri.transpose(2, 3, 0, 1) eri *= .1 eris = lambda: None eris.ovov = eri[:nocc, nocc:, :nocc, nocc:].reshape(nocc * nvir, nocc * nvir) mo_energy = numpy.arange(nmo) mo_occ = numpy.zeros(nmo) mo_occ[:nocc] = 2 dm = numpy.diag(mo_occ) vhf = numpy.einsum('ijkl,lk->ij', eri, dm) vhf -= numpy.einsum('ijkl,jk->il', eri, dm) * .5 hcore = numpy.diag(mo_energy) - vhf mf.get_hcore = lambda *args: hcore mf.get_ovlp = lambda *args: numpy.eye(nmo) eris.mo_energy = mf.mo_energy = mo_energy mf.mo_coeff = numpy.eye(nmo) mf.mo_occ = mo_occ mf.e_tot = numpy.einsum('ij,ji', hcore, dm) + numpy.einsum('ij,ji', vhf, dm) * .5 mf.converged = True pt = mp.MP2(mf) pt.ao2mo = lambda *args, **kwargs: eris pt.kernel(eris=eris) dm1 = pt.make_rdm1() dm2 = pt.make_rdm2() e1 = numpy.einsum('ij,ji', hcore, dm1) e1 += numpy.einsum('ijkl,ijkl', eri, dm2) * .5 self.assertAlmostEqual(e1, pt.e_tot, 12) #self.assertAlmostEqual(abs(numpy.einsum('ijkk->ji', dm2)/(nocc*2-1) - dm1).max(), 0, 9) self.assertAlmostEqual( abs(dm2 - dm2.transpose(1, 0, 3, 2).conj()).max(), 0, 9) self.assertAlmostEqual( abs(dm2 - dm2.transpose(2, 3, 0, 1)).max(), 0, 9)
def setUp(self): geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))] basis = '6-31g' multiplicity = 1 charge = 0 self.molecule = PyscfMolecularData(geometry, basis, multiplicity, charge) mol = prepare_pyscf_molecule(self.molecule) mol.verbose = 0 self.molecule._pyscf_data['mol'] = mol self.molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run() self.molecule._pyscf_data['mp2'] = mp.MP2(mf).run() self.molecule._pyscf_data['cisd'] = ci.CISD(mf).run() self.molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run() self.molecule._pyscf_data['fci'] = fci.FCI(mf).run()
def test_ump2_dm(self): pt = mp.MP2(mf) emp2, t2 = pt.kernel() dm1 = pt.make_rdm1() dm2 = pt.make_rdm2() gpt = mp.GMP2(mf).run() dm1ref = gpt.make_rdm1() dm2ref = gpt.make_rdm2() ia = gpt._scf.mo_coeff.orbspin == 0 ib = gpt._scf.mo_coeff.orbspin == 1 mo_a, mo_b = mf.mo_coeff nmoa = mo_a.shape[1] nmob = mo_b.shape[1] nocca, noccb = mol.nelec self.assertTrue(numpy.allclose(dm1[0], dm1ref[ia][:, ia])) self.assertTrue(numpy.allclose(dm1[1], dm1ref[ib][:, ib])) self.assertTrue( numpy.allclose(dm2[0], dm2ref[ia][:, ia][:, :, ia][:, :, :, ia])) self.assertTrue( numpy.allclose(dm2[2], dm2ref[ib][:, ib][:, :, ib][:, :, :, ib])) self.assertTrue( numpy.allclose(dm2[1], dm2ref[ia][:, ia][:, :, ib][:, :, :, ib])) hcore = mf.get_hcore() eriaa = ao2mo.kernel(mf._eri, mo_a, compact=False).reshape([nmoa] * 4) eribb = ao2mo.kernel(mf._eri, mo_b, compact=False).reshape([nmob] * 4) eriab = ao2mo.kernel(mf._eri, (mo_a, mo_a, mo_b, mo_b), compact=False) eriab = eriab.reshape([nmoa, nmoa, nmob, nmob]) h1a = reduce(numpy.dot, (mo_a.T.conj(), hcore, mo_a)) h1b = reduce(numpy.dot, (mo_b.T.conj(), hcore, mo_b)) e1 = numpy.einsum('ij,ji', h1a, dm1[0]) e1 += numpy.einsum('ij,ji', h1b, dm1[1]) e1 += numpy.einsum('ijkl,ijkl', eriaa, dm2[0]) * .5 e1 += numpy.einsum('ijkl,ijkl', eriab, dm2[1]) e1 += numpy.einsum('ijkl,ijkl', eribb, dm2[2]) * .5 e1 += mol.energy_nuc() self.assertAlmostEqual(e1, pt.e_tot, 9) vhf = mf.get_veff(mol, mf.make_rdm1()) h1a = reduce(numpy.dot, (mo_a.T, hcore + vhf[0], mo_a)) h1b = reduce(numpy.dot, (mo_b.T, hcore + vhf[1], mo_b)) dm1[0][numpy.diag_indices(nocca)] -= 1 dm1[1][numpy.diag_indices(noccb)] -= 1 e = numpy.einsum('pq,qp', h1a, dm1[0]) e += numpy.einsum('pq,qp', h1b, dm1[1]) self.assertAlmostEqual(e, -emp2, 9)
def pyscf_mp2_amplitude_calculator(domain): """ Calculates MP2 amplitudes in the domain. Args: domain (Domain): a domain to calculate at; Returns: MP2 amplitudes. """ mf = scf.RHF(domain.mol) mf.build(domain.mol) mf.mo_coeff = domain.psi mf.mo_energy = domain.e mf.mo_occ = domain.occupations domain_mp2 = mp.MP2(mf) domain_mp2.kernel() return None, domain_mp2.t2.swapaxes(1, 2)
def kernel(self, h1, h2, norb, nelec, ci0=None, ecore=0, **kwargs): fakemol = gto.M(verbose=0) fakemol.nelectron = sum(nelec) # Build a mean-field object fake_hf without SCF iterations fake_hf = scf.RHF(fakemol) fake_hf._eri = h2 fake_hf.get_hcore = lambda *args: h1 fake_hf.get_ovlp = lambda *args: numpy.eye(norb) fake_hf.mo_coeff = numpy.eye(norb) fake_hf.mo_occ = numpy.zeros(norb) fake_hf.mo_occ[:fakemol.nelectron // 2] = 2 self.mp2 = mp.MP2(fake_hf) e_corr, t2 = self.mp2.kernel() e_tot = self.mp2.e_tot + ecore return e_tot, t2
def get_potential_energy(self, atoms=None, force_consistent=False): if self.method == 'HF': #energy = self.hf_scanner(gto.M(atom=ase_atoms_to_pyscf(atoms), basis=self.basis)) mf = scf.RHF( gto.M(atom=ase_atoms_to_pyscf(atoms), basis=self.basis, charge=0, verbose=0)) energy = mf.kernel() energy *= convert_energy self.results['energy'] = energy return energy elif self.method == "DFT": mf = dft.RKS( gto.M(atom=ase_atoms_to_pyscf(atoms), basis=self.basis, charge=0, verbose=0)) mf.xc = self.xc energy = mf.kernel() energy *= convert_energy self.results['energy'] = energy return energy elif self.method == "MP2": #energy = self.mp2_scanner(gto.M(atom=ase_atoms_to_pyscf(atoms), basis=self.basis)) mf = scf.RHF( gto.M(atom=ase_atoms_to_pyscf(atoms), basis=self.basis, charge=0, verbose=0)) e_hf = mf.kernel() mp2 = mp.MP2(mf) e_mp = mp2.kernel()[0] energy = e_hf + e_mp energy *= convert_energy self.results['energy'] = energy return energy
def test_mp2_with_df(self): pt = mp.MP2(mf.density_fit('weigend')) pt.frozen = [1] e = pt.kernel(with_t2=False)[0] self.assertAlmostEqual(e, -0.14708846352674113, 9) pt = mp.dfmp2.DFMP2(mf.density_fit('weigend')) e = pt.kernel(mf.mo_energy, mf.mo_coeff)[0] self.assertAlmostEqual(e, -0.20425449198334983, 9) pt.frozen = [1] e = pt.kernel()[0] self.assertAlmostEqual(e, -0.14708846352674113, 9) pt = mp.dfmp2.DFMP2(mf) pt.frozen = [1] pt.with_df = mf.density_fit('weigend').with_df e = pt.kernel()[0] self.assertAlmostEqual(e, -0.14708846352674113, 9)
def test_check_mp2_high_cost(self): mol = gto.Mole() mol.atom = [ ['C', (0.0, 0.0, 0.0)], ['O', (0.0, r_CO, 0.0)], ['H', (0.0, -x, y)], ['H', (0.0, -x, -y)], ] mol.basis = { 'H': 'aug-cc-pVQZ', 'C': 'aug-cc-pVQZ', 'O': 'aug-cc-pVQZ', } mol.verbose = 7 mol.output = '/dev/null' mol.build() mf = scf.RHF(mol) mf.conv_tol = 1e-12 mf.kernel() # Ensure phase mf.mo_coeff[:, mf.mo_coeff.sum(axis=0) < 0] *= -1 mp2 = mp.MP2(mf) e_mp2 = mp2.kernel()[0] myadc = adc.ADC(mf) myadc.max_memory = 20 e_adc_mp2, t_amp1, t_amp2 = myadc.kernel_gs() diff_mp2 = e_adc_mp2 - e_mp2 self.assertAlmostEqual(diff_mp2, 0.0000000000000, 6) t_amp1_n = numpy.linalg.norm(t_amp1[0]) t_amp2_n = numpy.linalg.norm(t_amp2[0]) self.assertAlmostEqual(t_amp1_n, 0.0456504320024, 6) self.assertAlmostEqual(t_amp2_n, 0.2977897530749, 6) self.assertAlmostEqual(lib.fp(t_amp1[0]), -0.008983054536, 6) self.assertAlmostEqual(lib.fp(t_amp2[0]), -0.639727653133, 6)