-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Code snippet
from pymatgen.ext.matproj import MPRester
import warnings
warnings.simplefilter("error")
with MPRester() as mpr:
entries = mpr.get_entry_by_material_id("mp-1000")What happened?
Note: The MWE shows the error/warnings obtained using pymatgen.ext.matproj which of course is separate to mp-api, but I believe the issue applies to both implementations (being related to the loading of MP JSONs with recently deprecated pymatgen code). I'm not entirely sure which repo is best to raise this in, so let me know if it should be moved elsewhere!
Running the code without setting warnings to 'error' runs fine, without a warning appearing, however this code will eventually break once the deprecation is enforced in 2027.1, and also causes issues with tests that track warnings.
Caused by the MP jsons using the old code structure (pymatgen.entries.computed_entries, pymatgen.entries.compatibility etc.). Can these be replaced to match the new code structure?
Version
Latest
Which OS?
- MacOS
- Windows
- Linux
Log output
---------------------------------------------------------------------------
DeprecationWarning Traceback (most recent call last)
File ~/Packages/pymatgen/src/pymatgen/ext/matproj.py:184, in MPRester.request(self, sub_url, payload, method, mp_decode, timeout)
183 if response.status_code in {200, 400}:
--> 184 data = json.loads(response.text, cls=MontyDecoder) if mp_decode else orjson.loads(response.text)
185 else:
File ~/miniconda3/lib/python3.13/json/__init__.py:359, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
358 kw['parse_constant'] = parse_constant
--> 359 return cls(**kw).decode(s)
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:900, in MontyDecoder.decode(self, s)
899 d = json.loads(s)
--> 900 return self.process_decoded(d)
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:879, in MontyDecoder.process_decoded(self, d)
876 return bson.objectid.ObjectId(d["oid"])
878 return {
--> 879 self.process_decoded(k): self.process_decoded(v) for k, v in d.items()
880 }
882 if isinstance(d, list):
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:883, in MontyDecoder.process_decoded(self, d)
882 if isinstance(d, list):
--> 883 return [self.process_decoded(x) for x in d]
885 return d
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:879, in MontyDecoder.process_decoded(self, d)
876 return bson.objectid.ObjectId(d["oid"])
878 return {
--> 879 self.process_decoded(k): self.process_decoded(v) for k, v in d.items()
880 }
882 if isinstance(d, list):
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:879, in MontyDecoder.process_decoded(self, d)
876 return bson.objectid.ObjectId(d["oid"])
878 return {
--> 879 self.process_decoded(k): self.process_decoded(v) for k, v in d.items()
880 }
882 if isinstance(d, list):
File ~/miniconda3/lib/python3.13/site-packages/monty/json.py:790, in MontyDecoder.process_decoded(self, d)
788 return Path(d["string"])
--> 790 mod = __import__(modname, globals(), locals(), [classname], 0)
791 if hasattr(mod, classname):
File ~/Packages/pymatgen/src/pymatgen/entries/__init__.py:22
20 import warnings
---> 22 warnings.warn(
23 "Entry, ComputedEntry and ComputedStructureEntry have been moved to pymatgen.core.entries module. "
24 "This stub will be removed v2027.1.",
25 DeprecationWarning,
26 stacklevel=2,
27 )
DeprecationWarning: Entry, ComputedEntry and ComputedStructureEntry have been moved to pymatgen.core.entries module. This stub will be removed v2027.1.
During handling of the above exception, another exception occurred:
MPRestError Traceback (most recent call last)
Cell In[2], line 6
4 warnings.simplefilter("error")
5 with MPRester() as mpr:
----> 6 entries = mpr.get_entry_by_material_id("mp-1000")
File ~/Packages/pymatgen/src/pymatgen/ext/matproj.py:457, in MPRester.get_entry_by_material_id(self, material_id, *args, **kwargs)
445 def get_entry_by_material_id(self, material_id: str, *args, **kwargs) -> AnyComputedEntry:
446 r"""Get a ComputedEntry corresponding to a material_id.
447
448 Args:
(...) 455 ComputedStructureEntry object.
456 """
--> 457 return self.get_entries(material_id, *args, **kwargs)[0]
File ~/Packages/pymatgen/src/pymatgen/ext/matproj.py:414, in MPRester.get_entries(self, criteria, compatible_only, property_data, summary_data, **kwargs)
412 entries: list = []
413 fields = ["entries", *property_data] if property_data is not None else ["entries"]
--> 414 response = self.request(f"materials/thermo/?_fields={','.join(fields)}&{query}")
415 for dct in response:
416 for entry in dct["entries"].values():
File ~/Packages/pymatgen/src/pymatgen/ext/matproj.py:193, in MPRester.request(self, sub_url, payload, method, mp_decode, timeout)
191 except Exception as ex:
192 msg = f"{ex}. Content: {response.content}" if hasattr(response, "content") else str(ex)
--> 193 raise MPRestError(msg)
194 return all_data
MPRestError: Entry, ComputedEntry and ComputedStructureEntry have been moved to pymatgen.core.entries module. This stub will be removed v2027.1.. Content: b'{"data":[{"entries":{"GGA":{"@module":"pymatgen.entries.computed_entries","@class":"ComputedStructureEntry","energy":-8.64743015,"composition":{"Ba":1.0,"Te":1.0},"entry_id":"mp-1000-GGA","correction":-0.422,"energy_adjustments":[{"@module":"pymatgen.entries.computed_entries","@class":"CompositionEnergyAdjustment","@version":null,"adj_per_atom":-0.422,"n_atoms":1.0,"uncertainty_per_atom":0.0262,"name":"MP2020 anion correction (Te)","cls":{"@module":"pymatgen.entries.compatibility","@class":"MaterialsProject2020Compatibility","@version":null},"description":"Composition-based energy adjustment"}],"parameters":{"potcar_spec":[{"titel":"PAW_PBE Ba_sv 06Sep2000","hash":"c0477913afb63dfae3439f3534fbf0ed","summary_stats":null},{"titel":"PAW_PBE Te 08Apr2002","hash":"72719856e22fb1d3032df6f96d98a0f2","summary_stats":null}],"run_type":"GGA","is_hubbard":false,"hubbards":null},"data":{"oxide_type":"None","aspherical":true,"last_updated":"2024-11-21 20:16:15.215275+00:00","task_id":"mp-2299050","material_id":"mp-1000","oxidation_states":{"Ba":2.0,"Te":-2.0},"license":"BY-C","run_type":"GGA"},"structure":{"@module":"pymatgen.core.structure","@class":"Structure","charge":0,"lattice":{"matrix":[[-3.544879,-3.544879,0.0],[-3.544879,0.0,-3.544879],[0.0,-3.544879,-3.544879]],"pbc":[true,true,true],"a":5.013215958771575,"b":5.013215958771575,"c":5.013215958771575,"alpha":60.00000000000001,"beta":60.00000000000001,"gamma":60.00000000000001,"volume":89.09108390126052},"properties":{},"sites":[{"species":[{"element":"Ba","occu":1}],"abc":[0.0,0.0,0.0],"properties":{},"label":"Ba","xyz":[0.0,0.0,0.0]},{"species":[{"element":"Te","occu":1}],"abc":[0.5,0.5,0.5],"properties":{},"label":"Te","xyz":[-3.544879,-3.544879,-3.544879]}]}}}},{"entries":{"r2SCAN":{"@module":"pymatgen.entries.computed_entries","@class":"ComputedStructureEntry","energy":-56.02996258,"composition":{"Ba":1.0,"Te":1.0},"entry_id":"mp-1000-r2SCAN","correction":46.96053243,"energy_adjustments":[{"@module":"pymatgen.entries.computed_entries","@class":"ConstantEnergyAdjustment","@version":null,"value":46.96053243,"uncertainty":0.0,"name":"MP GGA(+U)/r2SCAN mixing adjustment","cls":{"@module":"pymatgen.entries.mixing_scheme","@class":"MaterialsProjectDFTMixingScheme","@version":null,"structure_matcher":{"version":"1.0","@module":"pymatgen.analysis.structure_matcher","@class":"StructureMatcher","comparator":{"version":"1.0","@module":"pymatgen.analysis.structure_matcher","@class":"SpeciesComparator"},"stol":0.30000000000000004,"ltol":0.2,"angle_tol":5,"primitive_cell":true,"scale":true,"attempt_supercell":false,"allow_subset":false,"supercell_size":"num_sites","ignored_species":[]},"run_type_1":"GGA(+U)","run_type_2":"r2SCAN","compat_1":{"@module":"pymatgen.entries.compatibility","@class":"MaterialsProject2020Compatibility","@version":null},"compat_2":null,"fuzzy_matching":false,"check_potcar":true},"description":"Place r2SCAN energy onto the GGA(+U) hull"}],"parameters":{"potcar_spec":[{"titel":"PAW_PBE Ba_sv 06Sep2000","hash":"f5e095059d44e59d56e740eec161fb74","summary_stats":null},{"titel":"PAW_PBE Te 08Apr2002","hash":"11ac22d05d08fb6be6beb8cf78b0127c","summary_stats":null}],"run_type":"r2SCAN","is_hubbard":false,"hubbards":null},"data":{"oxide_type":"None","aspherical":true,"last_updated":"2024-11-21 20:16:15.201095+00:00","task_id":"mp-1947896","material_id":"mp-1000","oxidation_states":{"Ba":2.0,"Te":-2.0},"license":"BY-C","run_type":"R2SCAN"},"structure":{"@module":"pymatgen.core.structure","@class":"Structure","charge":0,"lattice":{"matrix":[[4.34162192,0.0,2.50663673],[1.44720731,4.09332126,2.50663673],[0.0,0.0,5.01327346]],"pbc":[true,true,true],"a":5.013273241347371,"b":5.013273943429635,"c":5.01327346,"alpha":60.000003189876224,"beta":59.99999855723588,"gamma":60.00000363270144,"volume":89.09415786940792},"properties":{},"sites":[{"species":[{"element":"Ba","occu":1}],"abc":[-0.0,-0.0,-0.0],"properties":{},"label":"Ba","xyz":[0.0,0.0,0.0]},{"species":[{"element":"Te","occu":1}],"abc":[0.5,0.5,0.5],"properties":{},"label":"Te","xyz":[2.894414614999999,2.04666063,5.01327346]}]}}}},{"entries":{"r2SCAN":{"@module":"pymatgen.entries.computed_entries","@class":"ComputedStructureEntry","energy":-56.02996258,"composition":{"Ba":1.0,"Te":1.0},"entry_id":"mp-1000-r2SCAN","correction":0.0,"energy_adjustments":[],"parameters":{"potcar_spec":[{"titel":"PAW_PBE Ba_sv 06Sep2000","hash":"f5e095059d44e59d56e740eec161fb74","summary_stats":null},{"titel":"PAW_PBE Te 08Apr2002","hash":"11ac22d05d08fb6be6beb8cf78b0127c","summary_stats":null}],"run_type":"r2SCAN","is_hubbard":false,"hubbards":null},"data":{"oxide_type":"None","aspherical":true,"last_updated":"2024-11-21 20:16:15.201095+00:00","task_id":"mp-1947896","material_id":"mp-1000","oxidation_states":{"Ba":2.0,"Te":-2.0},"license":"BY-C","run_type":"R2SCAN"},"structure":{"@module":"pymatgen.core.structure","@class":"Structure","charge":0,"lattice":{"matrix":[[4.34162192,0.0,2.50663673],[1.44720731,4.09332126,2.50663673],[0.0,0.0,5.01327346]],"pbc":[true,true,true],"a":5.013273241347371,"b":5.013273943429635,"c":5.01327346,"alpha":60.000003189876224,"beta":59.99999855723588,"gamma":60.00000363270144,"volume":89.09415786940792},"properties":{},"sites":[{"species":[{"element":"Ba","occu":1}],"abc":[-0.0,-0.0,-0.0],"properties":{},"label":"Ba","xyz":[0.0,0.0,0.0]},{"species":[{"element":"Te","occu":1}],"abc":[0.5,0.5,0.5],"properties":{},"label":"Te","xyz":[2.894414614999999,2.04666063,5.01327346]}]}}}}],"meta":{"api_version":"0.86.4.dev10+g324115fa4","time_stamp":"2026-03-24T19:29:44.384628+00:00","total_doc":3,"facet":null,"max_limit":1000,"default_fields":["thermo_id","material_id","last_updated"]}}'