@@ -125,11 +125,11 @@ def __init__(
125125 endpoint : str | None = None ,
126126 notify_db_version : bool = False ,
127127 include_user_agent : bool = True ,
128- monty_decode : bool = True ,
129128 use_document_model : bool = True ,
130129 session : Session | None = None ,
131130 headers : dict | None = None ,
132131 mute_progress_bars : bool = _MAPI_SETTINGS .MUTE_PROGRESS_BARS ,
132+ ** kwargs ,
133133 ):
134134 """Initialize the MPRester.
135135
@@ -157,14 +157,13 @@ def __init__(
157157 making the API request. This helps MP support pymatgen users, and
158158 is similar to what most web browsers send with each page request.
159159 Set to False to disable the user agent.
160- monty_decode: Decode the data using monty into python objects
161160 use_document_model: If False, skip the creating the document model and return data
162161 as a dictionary. This can be simpler to work with but bypasses data validation
163162 and will not give auto-complete for available fields.
164163 session: Session object to use. By default (None), the client will create one.
165164 headers: Custom headers for localhost connections.
166165 mute_progress_bars: Whether to mute progress bars.
167-
166+ **kwargs: access to legacy kwargs that may be in the process of being deprecated
168167 """
169168 # SETTINGS tries to read API key from ~/.config/.pmgrc.yaml
170169 api_key = api_key or os .getenv ("MP_API_KEY" ) or SETTINGS .get ("PMG_MAPI_KEY" )
@@ -187,7 +186,6 @@ def __init__(
187186 headers = self .headers ,
188187 )
189188 self .use_document_model = use_document_model
190- self .monty_decode = monty_decode
191189 self .mute_progress_bars = mute_progress_bars
192190 self ._contribs = None
193191
@@ -224,6 +222,12 @@ def __init__(
224222 if not self .endpoint .endswith ("/" ):
225223 self .endpoint += "/"
226224
225+ if "monty_decode" in kwargs :
226+ warnings .warn (
227+ "Ignoring `monty_decode`, as it is no longer a supported option in `mp_api`."
228+ "The client by default returns results consistent with `monty_decode=True`."
229+ )
230+
227231 # Check if emmet version of server is compatible
228232 emmet_version = MPRester .get_emmet_version (self .endpoint )
229233
@@ -260,7 +264,6 @@ def __init__(
260264 endpoint = self .endpoint ,
261265 include_user_agent = include_user_agent ,
262266 session = self .session ,
263- monty_decode = self .monty_decode ,
264267 use_document_model = self .use_document_model ,
265268 headers = self .headers ,
266269 mute_progress_bars = self .mute_progress_bars ,
@@ -278,15 +281,11 @@ def __init__(
278281 suffix_split = cls .suffix .split ("/" )
279282
280283 if len (suffix_split ) == 1 :
281- # Disable monty decode on nested data which may give errors
282- monty_disable = cls in [TaskRester , ProvenanceRester ]
283- monty_decode = False if monty_disable else self .monty_decode
284284 rester = cls (
285285 api_key = api_key ,
286286 endpoint = self .endpoint ,
287287 include_user_agent = include_user_agent ,
288288 session = self .session ,
289- monty_decode = monty_decode ,
290289 use_document_model = self .use_document_model ,
291290 headers = self .headers ,
292291 mute_progress_bars = self .mute_progress_bars ,
@@ -309,14 +308,11 @@ def __init__(
309308 def __core_custom_getattr (_self , _attr , _rester_map ):
310309 if _attr in _rester_map :
311310 cls = _rester_map [_attr ]
312- monty_disable = cls in [TaskRester , ProvenanceRester ]
313- monty_decode = False if monty_disable else self .monty_decode
314311 rester = cls (
315312 api_key = api_key ,
316313 endpoint = self .endpoint ,
317314 include_user_agent = include_user_agent ,
318315 session = self .session ,
319- monty_decode = monty_decode ,
320316 use_document_model = self .use_document_model ,
321317 headers = self .headers ,
322318 mute_progress_bars = self .mute_progress_bars ,
@@ -752,7 +748,7 @@ def get_entries(
752748 # Need to store object to permit de-duplication
753749 entries .add (ComputedStructureEntry .from_dict (entry_dict ))
754750
755- return [ e if self . monty_decode else e . as_dict () for e in entries ]
751+ return list ( entries )
756752
757753 def get_pourbaix_entries (
758754 self ,
@@ -1190,18 +1186,12 @@ def get_entries_in_chemsys(
11901186 )
11911187 )
11921188
1193- if not self .monty_decode :
1194- entries = [ComputedStructureEntry .from_dict (entry ) for entry in entries ]
1195-
11961189 if use_gibbs :
11971190 # replace the entries with GibbsComputedStructureEntry
11981191 from pymatgen .entries .computed_entries import GibbsComputedStructureEntry
11991192
12001193 entries = GibbsComputedStructureEntry .from_entries (entries , temp = use_gibbs )
12011194
1202- if not self .monty_decode :
1203- entries = [entry .as_dict () for entry in entries ]
1204-
12051195 return entries
12061196
12071197 def get_bandstructure_by_material_id (
@@ -1312,7 +1302,7 @@ def get_charge_density_from_task_id(
13121302 kwargs = dict (
13131303 bucket = "materialsproject-parsed" ,
13141304 key = f"chgcars/{ validate_ids ([task_id ])[0 ]} .json.gz" ,
1315- decoder = lambda x : load_json (x , deser = self . monty_decode ),
1305+ decoder = lambda x : load_json (x , deser = True ),
13161306 )
13171307 chgcar = self .materials .tasks ._query_open_data (** kwargs )[0 ]
13181308 if not chgcar :
@@ -1493,17 +1483,11 @@ def get_cohesive_energy(
14931483 conventional_unit_cell = False ,
14941484 )
14951485 for entry in entries :
1496- # Ensure that this works with monty_decode = False and True
1497- if not self .monty_decode :
1498- entry ["uncorrected_energy_per_atom" ] = entry ["energy" ] / sum (
1499- entry ["composition" ].values ()
1500- )
1501- else :
1502- entry = {
1503- "data" : entry .data ,
1504- "uncorrected_energy_per_atom" : entry .uncorrected_energy_per_atom ,
1505- "composition" : entry .composition ,
1506- }
1486+ entry = {
1487+ "data" : entry .data ,
1488+ "uncorrected_energy_per_atom" : entry .uncorrected_energy_per_atom ,
1489+ "composition" : entry .composition ,
1490+ }
15071491
15081492 mp_id = entry ["data" ]["material_id" ]
15091493 if (run_type := entry ["data" ]["run_type" ]) not in energies [mp_id ]:
0 commit comments