Skip to content

Commit

Permalink
Materials client update
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 11, 2021
1 parent 8cea734 commit e5a1c6f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/mp_api/routes/materials/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def search_material_docs(
deprecated: Optional[bool] = False,
num_chunks: Optional[int] = None,
chunk_size: int = 100,
all_fields: bool = True,
fields: Optional[List[str]] = None,
):
"""
Expand All @@ -67,6 +68,7 @@ def search_material_docs(
deprecated (bool): Whether the material is tagged as deprecated.
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.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
fields (List[str]): List of fields in MaterialsCoreDoc to return data for.
Default is material_id, last_updated, and formula_pretty.
Expand Down Expand Up @@ -103,23 +105,19 @@ def search_material_docs(
if density:
query_params.update({"density_min": density[0], "density_max": density[1]})

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})

return self._get_all_documents(
query_params,
fields=fields,
version=version,
chunk_size=chunk_size,
return super().search(
version=self.version,
num_chunks=num_chunks,
chunk_size=chunk_size,
all_fields=all_fields,
fields=fields,
**query_params
)

def get_database_versions(self):
Expand Down

0 comments on commit e5a1c6f

Please sign in to comment.