Skip to content

Commit

Permalink
Fermi client update
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 11, 2021
1 parent f9a519e commit 28391cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 47 deletions.
47 changes: 0 additions & 47 deletions src/mp_api/routes/fermi/client.py
Expand Up @@ -10,50 +10,3 @@ class FermiRester(BaseRester):

suffix = "fermi"
document_model = FermiDoc # type: ignore

def search_fermi_docs(
self,
num_chunks: Optional[int] = None,
chunk_size: int = 100,
fields: Optional[List[str]] = None,
):
"""
Query fermi docs using a variety of search criteria.
Arguments:
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
fields (List[str]): List of fields in FermiDoc to return data for.
Default is material_id and last_updated only.
Yields:
([dict]) List of dictionaries containing data for entries defined in 'fields'.
Defaults to Materials Project IDs only.
"""

query_params = defaultdict(dict) # type: dict

if chunk_size <= 0 or chunk_size > 100:
warnings.warn("Improper chunk size given. Setting value to 100.")
chunk_size = 100

if fields:
query_params.update({"fields": ",".join(fields)})

query_params = {
entry: query_params[entry]
for entry in query_params
if query_params[entry] is not None
}

query_params.update({"limit": chunk_size, "skip": 0})
count = 0
while True:
query_params["skip"] = count * chunk_size
results = self.query(query_params).get("data", [])

if not any(results) or (num_chunks is not None and count == num_chunks):
break

count += 1
yield results
13 changes: 13 additions & 0 deletions src/mp_api/routes/fermi/client.pyi
@@ -0,0 +1,13 @@
from typing import List, Optional
from mp_api.routes.fermi.models import FermiDoc


class FermiRester:

def get_document_by_id(
self,
document_id: str,
fields: Optional[List[str]] = None,
monty_decode: bool = True,
version: Optional[str] = None,
) -> FermiDoc: ...

0 comments on commit 28391cf

Please sign in to comment.