Validity of GGA(+U)/r2SCAN Mixing in Pymatgen Pourbaix Tools

I have recently been using the Pourbaix tools in Pymatgen and the Materials Project API to generate Pourbaix diagrams and compute decomposition energies for various chemical systems. It seems to me that the Pymatgen code can, quite easily, be adapted to make use of the GGA(+U)/r2SCAN mixing scheme implemented in the MaterialsProjectDFTMixingScheme class. However, I’ve noticed that the API does not currently support this mixing scheme directly, and the Pourbaix app on the Materials Project website also does not use it (https://next-gen.materialsproject.org/pourbaix).

My question is therefore: is it valid to use the GGA(+U)/r2SCAN mixing scheme in the Pourbaix tools with the ionic reference data (ionic fits)?

The method of correcting the DFT energies via the experimental data seems to me to be entirely valid to use in combination with the GGA(+U)/r2SCAN mixing:
https://journals.aps.org/prb/abstract/10.1103/PhysRevB.85.235438

I came across a similar question in a previous discussion (r2SCAN data for constructing Pourbaix diagram), but it appears that the answer there was more focused on phase diagrams specifically, rather than Pourbaix diagrams.


from pymatgen.entries.compatibility import Compatibility
from pymatgen.entries.compatibility import MaterialsProject2020Compatibility, MaterialsProjectAqueousCompatibility
from pymatgen.entries.mixing_scheme import MaterialsProjectDFTMixingScheme
from pymatgen.analysis.structure_matcher import StructureMatcher
from pymatgen.core.ion import Ion

from mp_api.client import MPRester
import itertools

class SafeCompatibilityWrapper(Compatibility):
    def __init__(self, compat):
        self.compat = compat

    def process_entries(self, entries, clean=True, inplace=True, **kwargs):
        return self.compat.process_entries(entries, clean=clean, inplace=inplace)
    
    def get_adjustments(self, entries, clean=True, inplace=True, **kwargs):
        return self.compat.get_adjustments(entries, clean=clean, inplace=inplace)
    

mpr = MPRester('MY_API_KEY')
chemsys = 'relevant chemsys'

ion_data = mpr.get_ion_reference_data_for_chemsys(chemsys)
ion_ref_comps = [
    Ion.from_formula(d["data"]["RefSolid"]).composition for d in ion_data
]
ion_ref_elts = set(
    itertools.chain.from_iterable(i.elements for i in ion_ref_comps)
    )

gga_entries = mpr.get_entries_in_chemsys(
    list([str(e) for e in ion_ref_elts] + ["O", "H"])
    )
r2scan_entries = mpr.get_entries_in_chemsys(
    list([str(e) for e in ion_ref_elts] + ["O", "H"]),
    additional_criteria = {"thermo_types": ["R2SCAN"]}
    )
all_entries = gga_entries + r2scan_entries

structure_matcher = StructureMatcher()
compat2020 = MaterialsProject2020Compatibility(check_potcar=False)
compat = SafeCompatibilityWrapper( 
    MaterialsProjectDFTMixingScheme(
    structure_matcher = structure_matcher,
    run_type_1 = "GGA(+U)",
    run_type_2 = "r2SCAN",
    compat_1 = compat2020,
    compat_2 = None,
    fuzzy_matching = True,
    check_potcar = False
    )
)

aq_compat = MaterialsProjectAqueousCompatibility(solid_compat=compat)

processed_all_entries = aq_compat.process_entries(all_entries)

# Convert to pbx_entries
# make PourbaixDiagrams etc.

Hi @Matminator it should be valid provided you follow the method for referencing energies at T>0 to T=0 DFT energies

You’d likely also need to extend / refit the aqueous corrections for r2SCAN.That’s the primary reason we don’t use r2SCAN data in the Pourbaix app. If you don’t refit these corrections, you may want to omit them for the GGA/+U data, i.e., only use MaterialsProjectDFTMixingScheme to correct computed entries

Another alternative is only using (uncorrected) r2SCAN data in building the Pourbaix diagram

Hi Aaron,

Thanks for your reply!

Are the corrections and fits implemented in the pymatgen and mprester tools only valid for GGA/GGA(+U)?

It seems to me the MaterialsProjectAqueousCompatibility only implements the H₂/O₂/H₂O reference fits and entry corrections as described by Persson - so shouldn’t this approach also hold for mixed GGA/GGA(+U)/r²SCAN or even pure r²SCAN data? Further, fitting of the ions and solids seems to be handled in the get_ion_entries which is also used in line 915 in the get_pourbaix_entries method in the mprester class. Are these fits not the ones needed for to make the ion energies correct in an GGA(+U)/r²SCAN or pure r²SCAN space?

Any further clarification on whether I can use r²SCAN data with the pymatgen compatibility classes (MaterialsProjectAqueousCompatibility etc.) would be very helpful.

Thanks in advance

Hi you’re right on the aqueous compatibility corrections, my bad! Since these just shift the DFT energies to match experimental references, regardless of the functional used, these should be safe with either the MP mixed data or r2SCAN data alone. See this paper for an example of a group using the same idea with SCAN (the earlier, more computationally complex version of r2SCAN)