Skip to content

Commit 2a96b2f

Browse files
committed
Updated changelog and docs.
1 parent 402385a commit 2a96b2f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

docs/CHANGES.md

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pymatgen/ext/matproj.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
import warnings
1919
from collections import namedtuple
20-
from functools import partial
20+
from functools import lru_cache, partial
2121
from typing import TYPE_CHECKING, NamedTuple
2222

2323
import requests
@@ -42,15 +42,16 @@
4242

4343
class MPRester:
4444
"""
45-
This is pymatgen's implementation of MPRester.
45+
Pymatgen's implementation of MPRester. Unlike mp-api, this implementation mirrors the exact MP-API end points
46+
without modification. You just need to refer to https://api.materialsproject.org/docs and use the field names
47+
exactly. No need to deal with strange renames of various fields. Featurity parity is close to 100% with mp-api.
4648
47-
We have decided to drop support for the mp-api package and directly implement most of the relevant functionality
48-
within pymatgen. This implementation mirrors the actual MP API REST fields, rather than having strange renamed
49-
variables.
49+
Furthermore, we support both the mp-api as well as a simplified syntax. E.g., to query for a summary, you can use
50+
mpr.summary.search(material_ids="mp-1234") or mpr.materials.summary.search(material_ids="mp-1234").
5051
51-
If you are a power user, feel free to install the mp-api package. All issues regarding that implementation should
52-
be directed to the maintainers of that repository and not pymatgen. We will support only issues with regards to
53-
our implementation only.
52+
If you are a power user that requires some esoteric feature not covered, feel free to install the mp-api package.
53+
All issues regarding that implementation should be directed to the maintainers of that repository and not
54+
pymatgen. We will support only issues pertaining to our implementation only.
5455
"""
5556

5657
def __init__(self, api_key: str | None = None, include_user_agent: bool = True) -> None:
@@ -121,6 +122,7 @@ class Search(NamedTuple):
121122
for doc in docs:
122123
setattr(self, doc, Search(partial(self.search, doc)))
123124

125+
# This hacks make the syntax similar to mp-api's MPRester.materials.search...
124126
Materials = namedtuple("Materials", " ".join(docs)) # noqa: PYI024
125127

126128
self.materials = Materials(*[getattr(self, doc) for doc in docs])
@@ -167,6 +169,7 @@ def request(self, sub_url, payload=None, method="GET", mp_decode=True):
167169
raise MPRestError(msg)
168170
return all_data
169171

172+
@lru_cache(maxsize=100) # noqa:B019
170173
def search(self, doc, **kwargs) -> list[dict]:
171174
"""
172175
Queries a Materials PI end point doc. A notable difference with the mp-api's implementation is that this uses

tests/ext/test_matproj.py

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ def test_api_parity(self):
162162
# We should have Al2O3 data for these properties.
163163
data = self.rester.materials.__getattribute__(doc).search(material_ids="mp-1143")
164164
assert len(data) > 0, f"No Al2O3 data returned for {doc}"
165+
data = self.rester.__getattribute__(doc).search(material_ids="mp-1143")
166+
assert len(data) > 0, f"No Al2O3 data returned for {doc}"
165167

166168
docs = ["surface_properties"]
167169

0 commit comments

Comments
 (0)