Skip to content

Commit

Permalink
Added RIRPA tests on solids.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcscott committed Aug 8, 2023
1 parent 825e965 commit 2cdb2f1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vayesta/rpa/rirpa/RIdRRPA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 215 in vayesta/rpa/rirpa/RIdRRPA.py

View check run for this annotation

Codecov / codecov/patch

vayesta/rpa/rirpa/RIdRRPA.py#L210-L215

Added lines #L210 - L215 were not covered by tests
Expand Down
62 changes: 62 additions & 0 deletions vayesta/tests/rpa/test_rirpa_solids.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions vayesta/tests/testsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2cdb2f1

Please sign in to comment.