Skip to content

Commit

Permalink
Merge 618e6dc into 962b1dd
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Mar 25, 2021
2 parents 962b1dd + 618e6dc commit a018027
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 99 deletions.
114 changes: 57 additions & 57 deletions pymatgen/entries/MP2020Compatibility.yaml
Expand Up @@ -6,75 +6,75 @@ Corrections:
# and fluorides to make GGA and GGA+U energies compatible
# when compat_type = "Advanced" (default)
O:
V: -1.602
Cr: -1.893
Mn: -1.588
Fe: -2.182
Co: -1.535
Ni: -2.504
W: -4.57
Mo: -3.058
V: -1.666
Cr: -1.967
Mn: -1.635
Fe: -2.224
Co: -1.556
Ni: -2.545
W: -4.647
Mo: -3.098
F:
V: -1.602
Cr: -1.893
Mn: -1.588
Fe: -2.182
Co: -1.535
Ni: -2.504
W: -4.57
Mo: -3.058
V: -1.666
Cr: -1.967
Mn: -1.635
Fe: -2.224
Co: -1.556
Ni: -2.545
W: -4.647
Mo: -3.098
CompositionCorrections:
# Composition-based corrections applied to any compound containing
# these species as anions
oxide: -0.74
peroxide: -0.466
superoxide: -0.16
S: -0.639
F: -0.485
Cl: -0.593
Br: -0.538
I: -0.377
N: -0.344
Se: -0.473
Si: -0.406
oxide: -0.706
peroxide: -0.464
superoxide: -0.168
S: -0.592
F: -0.404
Cl: -0.55
Br: -0.473
I: -0.275
N: -0.408
Se: -0.472
Si: -0.225
Sb: -0.192
Te: -0.419
H: -0.178
Te: -0.406
H: -0.144
ozonide: 0
Uncertainties:
# Uncertainties corresponding to each energy correction (eV/atom)
GGAUMixingCorrections:
O:
V: 0.006
Cr: 0.0093
Mn: 0.0051
Fe: 0.009
Co: 0.0059
Ni: 0.0105
W: 0.0181
Mo: 0.0085
V: 0.0141
Cr: 0.0113
Mn: 0.0057
Fe: 0.0106
Co: 0.0163
Ni: 0.0106
W: 0.0188
Mo: 0.0202
F:
V: 0.006
Cr: 0.0093
Mn: 0.0051
Fe: 0.009
Co: 0.0059
Ni: 0.0105
W: 0.0181
Mo: 0.0085
V: 0.0141
Cr: 0.0113
Mn: 0.0057
Fe: 0.0106
Co: 0.0163
Ni: 0.0106
W: 0.0188
Mo: 0.0202
CompositionCorrections:
oxide: 0.0017
peroxide: 0.0186
superoxide: 0.0075
S: 0.0121
F: 0.0025
Cl: 0.0016
Br: 0.0022
I: 0.0059
N: 0.0084
oxide: 0.0025
peroxide: 0.0198
superoxide: 0.0096
S: 0.0113
F: 0.0049
Cl: 0.0055
Br: 0.0044
I: 0.0108
N: 0.0217
Se: 0.0341
Si: 0.0621
Si: 0.0435
Sb: 0.0089
Te: 0.024
H: 0.0013
Te: 0.0276
H: 0.002
ozonide: 0
Binary file modified pymatgen/entries/calc_compounds.json.gz
Binary file not shown.
27 changes: 18 additions & 9 deletions pymatgen/entries/compatibility.py
Expand Up @@ -10,7 +10,7 @@
import os
import warnings
from collections import defaultdict
from typing import List, Optional, Sequence, Union
from typing import Optional, Sequence, Union, List, Type

import numpy as np
from monty.design_patterns import cached_class
Expand Down Expand Up @@ -176,7 +176,7 @@ class GasCorrection(Correction):
"""
Correct gas energies to obtain the right formation energies. Note that
this depends on calculations being run within the same input set.
For old MaterialsProjectCompatibility and MITCompatibility.
Used by legacy MaterialsProjectCompatibility and MITCompatibility.
"""

def __init__(self, config_file):
Expand Down Expand Up @@ -215,7 +215,7 @@ class AnionCorrection(Correction):
Correct anion energies to obtain the right formation energies. Note that
this depends on calculations being run within the same input set.
For old MaterialsProjectCompatibility and MITCompatibility.
Used by legacy MaterialsProjectCompatibility and MITCompatibility.
"""

def __init__(self, config_file, correct_peroxide=True):
Expand Down Expand Up @@ -306,6 +306,8 @@ class AqueousCorrection(Correction):
"""
This class implements aqueous phase compound corrections for elements
and H2O.
Used only by MITAqueousCompatibility.
"""

def __init__(self, config_file, error_file=None):
Expand Down Expand Up @@ -820,6 +822,7 @@ def __init__(
compat_type="Advanced",
correct_peroxide=True,
check_potcar_hash=False,
config_file=None,
):
"""
Args:
Expand Down Expand Up @@ -848,6 +851,9 @@ def __init__(
check_potcar_hash (bool): Use potcar hash to verify POTCAR settings are
consistent with MPRelaxSet. If False, only the POTCAR symbols will
be used. (Default: False)
config_file (Path): Path to the selected compatibility.yaml config file.
If None, defaults to `MP2020Compatibility.yaml` distributed with
pymatgen.
References:
Wang, A., et al. A framework for quantifying uncertainty in DFT energy corrections.
Expand All @@ -864,7 +870,10 @@ def __init__(
self.check_potcar_hash = check_potcar_hash

# load corrections and uncertainties
self.config_file = os.path.join(MODULE_DIR, "MP2020Compatibility.yaml")
if config_file:
self.config_file = config_file
else:
self.config_file = os.path.join(MODULE_DIR, "MP2020Compatibility.yaml")
c = loadfn(self.config_file)
self.name = c["Name"]
self.comp_correction = c["Corrections"].get("CompositionCorrections", defaultdict(float))
Expand Down Expand Up @@ -1158,7 +1167,7 @@ class MaterialsProjectAqueousCompatibility(Compatibility):

def __init__(
self,
solid_compat: Optional[Compatibility] = MaterialsProjectCompatibility,
solid_compat: Optional[Type[Compatibility]] = MaterialsProjectCompatibility,
o2_energy: Optional[float] = None,
h2o_energy: Optional[float] = None,
h2o_adjustments: Optional[float] = None,
Expand Down Expand Up @@ -1186,10 +1195,10 @@ def __init__(
If not set, this value will be determined from any H2O entries passed to process_entries.
Default: None
"""
self.solid_compat = solid_compat
if self.solid_compat:
if not isinstance(self.solid_compat, Compatibility): # check whether solid_compat has been instantiated
self.solid_compat = solid_compat()
self.solid_compat = None
# check whether solid_compat has been instantiated
if solid_compat and not isinstance(solid_compat, Compatibility):
self.solid_compat = solid_compat()

self.o2_energy = o2_energy
self.h2o_energy = h2o_energy
Expand Down
29 changes: 19 additions & 10 deletions pymatgen/entries/correction_calculator.py
Expand Up @@ -3,9 +3,10 @@
entries given to the CorrectionCalculator constructor.
"""

import os
import warnings
from collections import OrderedDict
from typing import Dict, List, Tuple, Union, Sequence
from typing import Dict, List, Tuple, Union, Sequence, Optional

try:
import ruamel.yaml as yaml
Expand Down Expand Up @@ -306,6 +307,11 @@ def compute_corrections(self, exp_entries: list, calc_entries: dict) -> dict:
round(self.corrections[i], 3),
round(self.corrections_std_error[i], 4),
)

# set ozonide correction to 0 so that this species does not recieve a correction
# while other oxide types do
self.corrections_dict["ozonide"] = (0, 0)

return self.corrections_dict

def graph_residual_error(self) -> go.Figure:
Expand Down Expand Up @@ -414,14 +420,16 @@ def graph_residual_error_per_species(self, specie: str) -> go.Figure:

return fig

def make_yaml(self, name: str = "MP2020") -> None:
def make_yaml(self, name: str = "MP2020", dir: Optional[str] = None) -> None:
"""
Creates the _name_Compatibility.yaml that stores corrections as well as _name_CompatibilityUncertainties.yaml
for correction uncertainties.
Args:
name: str, alternate name for the created .yaml file.
Default: "MP2020"
Default: "MP2020"
dir: str, directory in which to save the file. Pass None (default) to
save the file in the current working directory.
"""

if len(self.corrections) == 0:
Expand All @@ -438,7 +446,7 @@ def make_yaml(self, name: str = "MP2020") -> None:
o_error: "OrderedDict[str, float]" = OrderedDict()
f_error: "OrderedDict[str, float]" = OrderedDict()

for specie in self.species:
for specie in list(self.species) + ["ozonide"]:
if specie in ggaucorrection_species:
o[specie] = self.corrections_dict[specie][0]
f[specie] = self.corrections_dict[specie][0]
Expand All @@ -450,9 +458,6 @@ def make_yaml(self, name: str = "MP2020") -> None:
comp_corr[specie] = self.corrections_dict[specie][0]
comp_corr_error[specie] = self.corrections_dict[specie][1]

comp_corr["ozonide"] = 0 # do i need this??
comp_corr_error["ozonide"] = 0

outline = """\
Name:
Corrections:
Expand All @@ -466,9 +471,13 @@ def make_yaml(self, name: str = "MP2020") -> None:
F:
CompositionCorrections:
"""

fn = name + "Compatibility.yaml"
file = open(fn, "w")
if dir:
path = os.path.join(dir, fn)
else:
path = fn

file = open(path, "w")
yml = yaml.YAML()
yml.Representer.add_representer(OrderedDict, yml.Representer.represent_dict)
yml.default_flow_style = False
Expand Down Expand Up @@ -498,5 +507,5 @@ def make_yaml(self, name: str = "MP2020") -> None:
"Uncertainties corresponding to each energy correction (eV/atom)", indent=2
)

yaml.dump(contents, file)
yml.dump(contents, file)
file.close()

0 comments on commit a018027

Please sign in to comment.