Skip to content

Commit 2664fcd

Browse files
committed
get access controlled batch ids from heartbeat
1 parent 33b787f commit 2664fcd

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

mp_api/client/core/client.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def __init__(
154154
self.local_dataset_cache = local_dataset_cache
155155
self.force_renew = force_renew
156156
self.db_version = BaseRester._get_database_version(self.endpoint)
157+
self.access_controlled_batch_ids = BaseRester._get_access_restricted_batch_ids(
158+
self.endpoint
159+
)
157160

158161
if self.suffix:
159162
self.endpoint = urljoin(self.endpoint, self.suffix)
@@ -243,6 +246,25 @@ def _get_database_version(endpoint):
243246
"""
244247
return requests.get(url=endpoint + "heartbeat").json()["db_version"]
245248

249+
@staticmethod
250+
@cache
251+
def _get_access_restricted_batch_ids(endpoint):
252+
"""Certain contributions to the Materials Project have access
253+
control restrictions that require explicit agreement to the
254+
Terms of Use for the respective datasets prior to access being
255+
granted.
256+
257+
A full list of the Terms of Use for all contributions in the
258+
Materials Project are available at:
259+
260+
https://next-gen.materialsproject.org/about/terms
261+
262+
Returns: a list of strings
263+
"""
264+
return requests.get(url=endpoint + "heartbeat").json()[
265+
"access_controlled_batch_ids"
266+
]
267+
246268
def _post_resource(
247269
self,
248270
body: dict | None = None,
@@ -583,13 +605,10 @@ def _query_resource(
583605
builder.execute("SELECT COUNT(*) FROM tbl").read_all()
584606
)[0][0].as_py()
585607

586-
# TODO: Update tasks (+ others?) resource to have emmet-api BatchIdQuery operator
587-
# -> need to modify BatchIdQuery operator to handle root level
588-
# batch_id, not only builder_meta.batch_id
589-
# if not has_gnome_access:
590-
# num_docs_needed = self.count(
591-
# {"batch_id_neq_any": SETTINGS.ACCESS_CONTROLLED_BATCH_IDS}
592-
# )
608+
if not has_gnome_access:
609+
num_docs_needed = self.count(
610+
{"batch_id_neq_any": self.access_controlled_batch_ids}
611+
)
593612

594613
pbar = (
595614
tqdm(

mp_api/client/core/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,4 @@ class MAPIClientSettings(BaseSettings):
9797
description="Threshold number of rows to accumulate in memory before flushing dataset to disk",
9898
)
9999

100-
ACCESS_CONTROLLED_BATCH_IDS: list[str] = Field(
101-
["gnome_r2scan_statics"], description="Batch ids with access restrictions"
102-
)
103-
104100
model_config = SettingsConfigDict(env_prefix="MPRESTER_")

0 commit comments

Comments
 (0)