diff --git a/vayesta/rpa/rirpa/RIdRRPA.py b/vayesta/rpa/rirpa/RIdRRPA.py index 4866803b7..0aff47c7d 100644 --- a/vayesta/rpa/rirpa/RIdRRPA.py +++ b/vayesta/rpa/rirpa/RIdRRPA.py @@ -209,7 +209,7 @@ def kernel_energy(self, npoints=48, ainit=10, correction="linear"): # Note that eri contribution to A and B is equal, so can get trace over one by dividing by two e3 = 2 * (sum(self.eps) + np.tensordot(cderi, cderi, ((0, 1), (0, 1)))) if cderi_neg is not None: - e3 -= np.tensordot(cderi_neg, cderi_neg, ((0, 1), (0, 1))) + e3 -= 2 * np.tensordot(cderi_neg, cderi_neg, ((0, 1), (0, 1))) err /= 2 self.e_corr_ss = 0.5 * (e1 + e2 - e3) self.log.info( diff --git a/vayesta/tests/rpa/test_rirpa_solids.py b/vayesta/tests/rpa/test_rirpa_solids.py new file mode 100644 index 000000000..d82672a88 --- /dev/null +++ b/vayesta/tests/rpa/test_rirpa_solids.py @@ -0,0 +1,62 @@ +import pytest + +from vayesta import rpa +from vayesta.tests.common import TestCase +from vayesta.tests import testsystems + + +class DiamondRIRPATest(TestCase): + PLACES = 8 + + @classmethod + def setUpClass(cls): + cls.sys = testsystems.diamond_sto3g_s211 + cls.known_results = dict(e_tot=-149.51936410641733, e_corr=-0.19193623440986585) + + def _test_energy(self, myrpa): + """Test the RPA energy. + """ + self.assertAlmostEqual(myrpa.e_corr, self.known_results["e_corr"], self.PLACES) + self.assertAlmostEqual(myrpa.e_tot, self.known_results["e_tot"], self.PLACES) + + @pytest.mark.slow + def test_energy_rhf_opt(self): + """Tests for diamond with optimised RHF dRPA code. + """ + + rirpa = rpa.rirpa.ssRIdRRPA(self.sys.rhf()) + rirpa.kernel_energy() + self._test_energy(rirpa) + + @pytest.mark.fast + def test_energy_rhf_generic(self): + """Tests for diamond with generic RHF RIRPA code. + """ + + rirpa = rpa.rirpa.ssRIRRPA(self.sys.rhf()) + rirpa.kernel_energy() + self._test_energy(rirpa) + + @pytest.mark.slow + def test_energy_uhf(self): + """Tests for diamond with generic UHF RIRPA code. + """ + + rirpa = rpa.rirpa.ssRIURPA(self.sys.uhf()) + rirpa.kernel_energy() + self._test_energy(rirpa) + + @pytest.mark.fast + def test_rhf_moments(self): + gen_rirpa = rpa.rirpa.ssRIRRPA(self.sys.rhf()) + opt_rirpa = rpa.rirpa.ssRIdRRPA(self.sys.rhf()) + mom0_gen = gen_rirpa.kernel_moms(0)[0] + mom0_opt = opt_rirpa.kernel_moms(0)[0] + self.assertAllclose(mom0_gen, mom0_opt, self.PLACES) + +@pytest.mark.slow +class GrapheneRIRPATest(DiamondRIRPATest): + @classmethod + def setUpClass(cls): + cls.sys = testsystems.graphene_sto3g_s211 + cls.known_results = dict(e_tot=-150.15057360171875, e_corr=-0.17724246753903117) \ No newline at end of file diff --git a/vayesta/tests/testsystems.py b/vayesta/tests/testsystems.py index 34b6f14af..73c916267 100644 --- a/vayesta/tests/testsystems.py +++ b/vayesta/tests/testsystems.py @@ -446,6 +446,12 @@ def uhf(self): he_k321 = TestSolid(a, atom="He 0 0 0", basis="def2-svp", auxbasis="def2-svp-ri", kmesh=(3, 2, 1)) he_s321 = TestSolid(a, atom="He 0 0 0", basis="def2-svp", auxbasis="def2-svp-ri", supercell=(3, 2, 1)) +a, atom = solids.graphene() +opts = dict(basis='sto3g', auxbasis='sto3g', exp_to_discard=0.1, dimension=2) +mesh = (2,1,1) +graphene_sto3g_k211 = TestSolid(a=a, atom=atom, kmesh=mesh, **opts) +graphene_sto3g_s211 = TestSolid(a=a, atom=atom, supercell=mesh, **opts) + # Lattices