30
30
EnergyAdjustment ,
31
31
TemperatureEnergyAdjustment ,
32
32
)
33
- from pymatgen .io .vasp .sets import MITRelaxSet , MPRelaxSet
33
+ from pymatgen .io .vasp .sets import MITRelaxSet , MPRelaxSet , VaspInputSet
34
34
from pymatgen .util .due import Doi , due
35
35
36
36
__author__ = "Amanda Wang, Ryan Kingsbury, Shyue Ping Ong, Anubhav Jain, Stephen Dacek, Sai Jayaraman"
@@ -119,48 +119,55 @@ class PotcarCorrection(Correction):
119
119
'PAW_PBE O 08Apr2002'].
120
120
"""
121
121
122
- def __init__ (self , input_set , check_hash = False ):
122
+ def __init__ (self , input_set : type [ VaspInputSet ], check_potcar : bool = True , check_hash : bool = False ) -> None :
123
123
"""
124
124
Args:
125
- input_set: InputSet object used to generate the runs (used to check
125
+ input_set ( InputSet): object used to generate the runs (used to check
126
126
for correct potcar symbols).
127
-
128
- check_hash (bool): If true, uses the potcar hash to check for valid
129
- potcars. If false, uses the potcar symbol (Less reliable).
130
- Defaults to True
127
+ check_potcar (bool): If False, bypass the POTCAR check altogether. Defaults to True
128
+ check_hash (bool): If True, uses the potcar hash to check for valid
129
+ potcars. If false, uses the potcar symbol (less reliable). Defaults to False.
131
130
132
131
Raises:
133
- ValueError if entry do not contain "potcar_symbols" key.
134
- CompatibilityError if wrong potcar symbols
132
+ ValueError: if check_potcar=True and entry does not contain "potcar_symbols" key.
135
133
"""
136
134
potcar_settings = input_set .CONFIG ["POTCAR" ]
137
135
if isinstance (list (potcar_settings .values ())[- 1 ], dict ):
138
- if check_hash :
139
- self .valid_potcars = {k : d ["hash" ] for k , d in potcar_settings .items ()}
140
- else :
141
- self .valid_potcars = {k : d ["symbol" ] for k , d in potcar_settings .items ()}
136
+ self .valid_potcars = {
137
+ key : dct .get ("hash" if check_hash else "symbol" ) for key , dct in potcar_settings .items ()
138
+ }
142
139
else :
143
140
if check_hash :
144
141
raise ValueError ("Cannot check hashes of potcars, since hashes are not included in the entry." )
145
142
self .valid_potcars = potcar_settings
146
143
147
144
self .input_set = input_set
148
145
self .check_hash = check_hash
146
+ self .check_potcar = check_potcar
149
147
150
148
def get_correction (self , entry : AnyComputedEntry ) -> ufloat :
151
149
"""
152
- :param entry: A ComputedEntry/ComputedStructureEntry
153
- :return: Correction, Uncertainty.
150
+ Args:
151
+ entry (AnyComputedEntry): ComputedEntry or ComputedStructureEntry.
152
+
153
+ Raises:
154
+ ValueError: If entry does not contain "potcar_symbols" key.
155
+ CompatibilityError: If entry has wrong potcar hash/symbols.
156
+
157
+ Returns:
158
+ ufloat: 0.0 +/- 0.0 (from uncertainties package)
154
159
"""
155
- if SETTINGS .get ("PMG_DISABLE_POTCAR_CHECKS" , False ):
160
+ if SETTINGS .get ("PMG_DISABLE_POTCAR_CHECKS" , False ) or not self . check_potcar :
156
161
return ufloat (0.0 , 0.0 )
162
+
163
+ potcar_spec = entry .parameters .get ("potcar_spec" )
157
164
if self .check_hash :
158
- if entry . parameters . get ( " potcar_spec" ) :
159
- psp_settings = {d .get ("hash" ) for d in entry . parameters [ " potcar_spec" ] if d }
165
+ if potcar_spec :
166
+ psp_settings = {dct .get ("hash" ) for dct in potcar_spec if dct }
160
167
else :
161
168
raise ValueError ("Cannot check hash without potcar_spec field" )
162
- elif entry . parameters . get ( " potcar_spec" ) :
163
- psp_settings = {d .get ("titel" ).split ()[1 ] for d in entry . parameters [ " potcar_spec" ] if d }
169
+ elif potcar_spec :
170
+ psp_settings = {dct .get ("titel" ).split ()[1 ] for dct in potcar_spec if dct }
164
171
else :
165
172
psp_settings = {sym .split ()[1 ] for sym in entry .parameters ["potcar_symbols" ] if sym }
166
173
@@ -840,6 +847,7 @@ def __init__(
840
847
self ,
841
848
compat_type : str = "Advanced" ,
842
849
correct_peroxide : bool = True ,
850
+ check_potcar : bool = True ,
843
851
check_potcar_hash : bool = False ,
844
852
config_file : str | None = None ,
845
853
) -> None :
@@ -867,6 +875,9 @@ def __init__(
867
875
correct_peroxide: Specify whether peroxide/superoxide/ozonide
868
876
corrections are to be applied or not. If false, all oxygen-containing
869
877
compounds are assigned the 'oxide' correction. (Default: True)
878
+ check_potcar (bool): Check that the POTCARs used in the calculation
879
+ are consistent with the Materials Project parameters. False bypasses this
880
+ check altogether. (Default: True)
870
881
check_potcar_hash (bool): Use potcar hash to verify POTCAR settings are
871
882
consistent with MPRelaxSet. If False, only the POTCAR symbols will
872
883
be used. (Default: False)
@@ -888,6 +899,7 @@ def __init__(
888
899
889
900
self .compat_type = compat_type
890
901
self .correct_peroxide = correct_peroxide
902
+ self .check_potcar = check_potcar
891
903
self .check_potcar_hash = check_potcar_hash
892
904
893
905
# load corrections and uncertainties
@@ -940,7 +952,7 @@ def get_adjustments(self, entry: AnyComputedEntry) -> list[EnergyAdjustment]:
940
952
# check the POTCAR symbols
941
953
# this should return ufloat(0, 0) or raise a CompatibilityError or ValueError
942
954
if entry .parameters .get ("software" , "vasp" ) == "vasp" :
943
- pc = PotcarCorrection (MPRelaxSet , check_hash = self .check_potcar_hash )
955
+ pc = PotcarCorrection (MPRelaxSet , check_hash = self .check_potcar_hash , check_potcar = self . check_potcar )
944
956
pc .get_correction (entry )
945
957
946
958
# apply energy adjustments
0 commit comments