Skip to content

Commit 9aa4b1f

Browse files
committed
make ExplicitDispersionModel.xc_partner_ref stable, add tests
1 parent e66175a commit 9aa4b1f

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/nomad_simulations/schema_packages/model_method.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ class ExplicitDispersionModel(BaseModelMethod):
236236
• S. Grimme et al., J. Chem. Phys. 136, 154105 (2012) - DFT-D3(BJ)
237237
• A. Tkatchenko, M. Scheffler, Phys. Rev. Lett. 102, 073005 (2009) - TS
238238
• A. Tkatchenko et al., Phys. Rev. Lett. 108, 236402 (2012) - MBD
239-
• O. A. Vydrov, T. Van Voorhis, J. Chem. Phys. 133, 244103 (2010) - VV10
240239
• C. Steinmann, WIREs Comput. Mol. Sci. 10, e1438 (2020) - overview
241240
"""
242241

@@ -274,15 +273,6 @@ class ExplicitDispersionModel(BaseModelMethod):
274273
""",
275274
)
276275

277-
# Deprecated compatibility field. Prefer `xc_partner_ref`.
278-
xc_partner = Quantity(
279-
type=str,
280-
description="""
281-
Deprecated string label for the baseline XC partner
282-
(e.g. 'PBE', 'SCAN', 'B3LYP'). Prefer `xc_partner_ref`.
283-
""",
284-
)
285-
286276

287277
class RelativityModel(BaseModelMethod):
288278
"""
@@ -391,15 +381,6 @@ class NonlocalCorrelation(BaseModelMethod):
391381
""",
392382
)
393383

394-
# Deprecated compatibility field. Prefer `xc_partner_ref`.
395-
xc_partner = Quantity(
396-
type=str,
397-
description="""
398-
Deprecated string label for the baseline XC partner
399-
(e.g. 'PBE', 'SCAN', 'B3LYP'). Prefer `xc_partner_ref`.
400-
""",
401-
)
402-
403384

404385
class OrbitalLocalization(BaseModelMethod):
405386
"""Transforming canonical MOs into a localized representation.
@@ -671,7 +652,14 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
671652

672653
if base_xc_key:
673654
existing_nonlocal.xc_partner_ref = self.xc
674-
existing_nonlocal.xc_partner = base_xc_key
655+
656+
if base_xc_key:
657+
for contribution in self.contributions or []:
658+
if (
659+
isinstance(contribution, ExplicitDispersionModel)
660+
and contribution.xc_partner_ref is None
661+
):
662+
contribution.xc_partner_ref = self.xc
675663

676664
# XC-specific normalization now handled by XCFunctional
677665
self.xc.normalize(archive, logger)

tests/test_model_method.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,17 @@ def test_solvation_derives_optical_eps_if_only_n_given():
684684
assert pytest.approx(ism.dielectric_constant_optical, rel=1e-12) == 1.50**2
685685

686686

687+
def test_dft_sets_explicit_dispersion_xc_partner_ref():
688+
dft = DFT()
689+
dft.xc = XCFunctional(functional_key='PBE')
690+
edm = ExplicitDispersionModel(model='D3BJ', damping_function='BJ')
691+
dft.m_add_sub_section(type(dft).contributions, edm)
692+
693+
dft.normalize(EntryArchive(), logger=logger)
694+
695+
assert edm.xc_partner_ref is dft.xc
696+
697+
687698
def test_dft_nonlocal_addon_creates_nonlocal_contribution_and_sets_partner():
688699
dft = DFT()
689700
dft.xc = XCFunctional(functional_key='SCAN + rVV10')
@@ -697,7 +708,6 @@ def test_dft_nonlocal_addon_creates_nonlocal_contribution_and_sets_partner():
697708
assert len(nonlocal_terms) == 1
698709
assert nonlocal_terms[0].type == 'rVV10'
699710
assert nonlocal_terms[0].xc_partner_ref is dft.xc
700-
assert nonlocal_terms[0].xc_partner == 'SCAN'
701711

702712

703713
def test_dft_nonlocal_addon_reuses_existing_matching_nonlocal_contribution():
@@ -715,7 +725,6 @@ def test_dft_nonlocal_addon_reuses_existing_matching_nonlocal_contribution():
715725
assert nonlocal_terms[0] is existing_nonlocal
716726
assert nonlocal_terms[0].type == 'VV10'
717727
assert nonlocal_terms[0].xc_partner_ref is dft.xc
718-
assert nonlocal_terms[0].xc_partner == 'PBE'
719728

720729

721730
def test_dft_nonlocal_addon_fills_empty_existing_nonlocal_type():
@@ -733,7 +742,6 @@ def test_dft_nonlocal_addon_fills_empty_existing_nonlocal_type():
733742
assert nonlocal_terms[0] is existing_nonlocal
734743
assert nonlocal_terms[0].type == 'VV10'
735744
assert nonlocal_terms[0].xc_partner_ref is dft.xc
736-
assert nonlocal_terms[0].xc_partner == 'r2SCAN'
737745

738746

739747
_COMMON_XC_CASES = [

0 commit comments

Comments
 (0)