Skip to content

Commit 4b2171c

Browse files
authored
Fix MaterialsProjectCompatibility run type handling for GGA+U (#3540)
* MP legacy compat: move raise stmt to get_adjustment * Update compatibility.py * CorrectionsList: add run_types kwarg
1 parent db45f4b commit 4b2171c

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

pymatgen/entries/compatibility.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,8 @@ def get_correction(self, entry) -> ufloat:
200200
Correction.
201201
"""
202202
comp = entry.composition
203-
204-
correction = ufloat(0.0, 0.0)
205-
206203
# set error to 0 because old MPCompatibility doesn't have errors
207-
208-
# only correct GGA or GGA+U entries
209-
if entry.parameters.get("run_type") not in ("GGA", "GGA+U"):
210-
return ufloat(0.0, 0.0)
204+
correction = ufloat(0.0, 0.0)
211205

212206
rform = entry.composition.reduced_formula
213207
if rform in self.cpd_energies:
@@ -252,10 +246,6 @@ def get_correction(self, entry) -> ufloat:
252246

253247
correction = ufloat(0.0, 0.0)
254248

255-
# only correct GGA or GGA+U entries
256-
if entry.parameters.get("run_type") not in ("GGA", "GGA+U"):
257-
return ufloat(0.0, 0.0)
258-
259249
# Check for sulfide corrections
260250
if Element("S") in comp:
261251
sf_type = "sulfide"
@@ -351,10 +341,6 @@ def get_correction(self, entry) -> ufloat:
351341
rform = comp.reduced_formula
352342
cpd_energies = self.cpd_energies
353343

354-
# only correct GGA or GGA+U entries
355-
if entry.parameters.get("run_type") not in ("GGA", "GGA+U"):
356-
return ufloat(0.0, 0.0)
357-
358344
correction = ufloat(0.0, 0.0)
359345

360346
if rform in cpd_energies:
@@ -465,22 +451,13 @@ def get_correction(self, entry) -> ufloat:
465451
Returns:
466452
Correction, Uncertainty.
467453
"""
468-
if entry.parameters.get("run_type") not in ("GGA", "GGA+U"):
469-
raise CompatibilityError(
470-
f"Entry {entry.entry_id} has invalid run type {entry.parameters.get('run_type')}. Discarding."
471-
)
472-
473454
calc_u = entry.parameters.get("hubbards") or defaultdict(int)
474455
comp = entry.composition
475456

476457
elements = sorted((el for el in comp.elements if comp[el] > 0), key=lambda el: el.X)
477458
most_electroneg = elements[-1].symbol
478459
correction = ufloat(0.0, 0.0)
479460

480-
# only correct GGA or GGA+U entries
481-
if entry.parameters.get("run_type") not in ("GGA", "GGA+U"):
482-
return ufloat(0.0, 0.0)
483-
484461
u_corr = self.u_corrections.get(most_electroneg, {})
485462
u_settings = self.u_settings.get(most_electroneg, {})
486463
u_errors = self.u_errors.get(most_electroneg, defaultdict(float))
@@ -653,17 +630,30 @@ class CorrectionsList(Compatibility):
653630
MITCompatibility subclasses instead.
654631
"""
655632

656-
def __init__(self, corrections: Sequence[Correction]):
633+
def __init__(self, corrections: Sequence[Correction], run_types: list[str] | None = None):
657634
"""
658635
Args:
659636
corrections (list[Correction]): Correction objects to apply.
637+
run_types: Valid DFT run_types for this correction scheme. Entries with run_type
638+
other than those in this list will be excluded from the list returned
639+
by process_entries. The default value captures both GGA and GGA+U run types
640+
historically used by the Materials Project, for example in.
660641
"""
642+
if run_types is None:
643+
run_types = ["GGA", "GGA+U", "PBE", "PBE+U"]
661644
self.corrections = corrections
645+
self.run_types = run_types
662646
super().__init__()
663647

664648
def get_adjustments(self, entry: AnyComputedEntry) -> list[EnergyAdjustment]:
665649
"""Get the list of energy adjustments to be applied to an entry."""
666650
adjustment_list = []
651+
if entry.parameters.get("run_type") not in self.run_types:
652+
raise CompatibilityError(
653+
f"Entry {entry.entry_id} has invalid run type {entry.parameters.get('run_type')}. "
654+
f"Must be GGA or GGA+U. Discarding."
655+
)
656+
667657
corrections, uncertainties = self.get_corrections_dict(entry)
668658

669659
for k, v in corrections.items():

0 commit comments

Comments
 (0)