Skip to content

Commit

Permalink
Update thermo builder and API (#561)
Browse files Browse the repository at this point in the history
* Update thermo and phase diagram endpoints

* Fix phase diagram bucket name

* Fix store tuple

* Fix index name

* Build only SCAN thermo data if available

* Entries typo

* Missing return statement

* Fix small typos

* Fix pair production

* Remove debug statement

* Fix building only scan entries

* Linting
  • Loading branch information
munrojm committed Oct 17, 2022
1 parent f4ee267 commit 6e3ee61
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 105 deletions.
84 changes: 27 additions & 57 deletions emmet-api/app.py
Expand Up @@ -42,24 +42,30 @@
)

task_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="tasks",
uri=db_uri, database="mp_core", key="task_id", collection_name="tasks",
)

thermo_store = MongoURIStore(
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
key="thermo_id",
collection_name="thermo",
)

phase_diagram_store = MongoURIStore(
s3_phase_diagram_index = MongoURIStore(
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="chemsys",
collection_name="phase_diagram",
database="mp_core",
key="phase_diagram_id",
collection_name="s3_phase_diagram_index",
)

phase_diagram_store = S3Store(
index=s3_phase_diagram_index,
bucket="mp-phase-diagrams",
s3_workers=24,
key="phase_diagram_id",
searchable_fields=["chemsys", "thermo_type", "phase_diagram_id"],
compress=True,
)

dielectric_store = MongoURIStore(
Expand All @@ -84,31 +90,19 @@
)

phonon_bs_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="material_id",
collection_name="pmg_ph_bs",
uri=db_uri, database="mp_core", key="material_id", collection_name="pmg_ph_bs",
)

eos_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="eos",
uri=db_uri, database="mp_core", key="task_id", collection_name="eos",
)

similarity_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="material_id",
collection_name="similarity",
uri=db_uri, database="mp_core", key="material_id", collection_name="similarity",
)

xas_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="spectrum_id",
collection_name="xas",
uri=db_uri, database="mp_core", key="spectrum_id", collection_name="xas",
)

gb_store = MongoURIStore(
Expand All @@ -119,31 +113,19 @@
)

fermi_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="fermi_surface",
uri=db_uri, database="mp_core", key="task_id", collection_name="fermi_surface",
)

elasticity_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="elasticity",
uri=db_uri, database="mp_core", key="task_id", collection_name="elasticity",
)

doi_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="dois",
uri=db_uri, database="mp_core", key="task_id", collection_name="dois",
)

substrates_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="film_id",
collection_name="substrates",
uri=db_uri, database="mp_core", key="film_id", collection_name="substrates",
)

surface_props_store = MongoURIStore(
Expand All @@ -161,10 +143,7 @@
)

synth_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="_id",
collection_name="synth_descriptions",
uri=db_uri, database="mp_core", key="_id", collection_name="synth_descriptions",
)

insertion_electrodes_store = MongoURIStore(
Expand All @@ -175,10 +154,7 @@
)

molecules_store = MongoURIStore(
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="molecules",
uri=db_uri, database="mp_core", key="task_id", collection_name="molecules",
)

oxi_states_store = MongoURIStore(
Expand Down Expand Up @@ -224,10 +200,7 @@
)

s3_dos_index = MongoURIStore(
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="s3_dos_index",
uri=db_uri, database="mp_core", key="fs_id", collection_name="s3_dos_index",
)

s3_bs = S3Store(
Expand Down Expand Up @@ -266,10 +239,7 @@
)

chgcar_url = MongoURIStore(
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="chgcar_s3_urls",
uri=db_uri, database="mp_core", key="fs_id", collection_name="chgcar_s3_urls",
)

mpcomplete_store = MongoURIStore(
Expand Down
55 changes: 55 additions & 0 deletions emmet-api/emmet/api/routes/thermo/query_operators.py
@@ -1,5 +1,6 @@
from typing import Optional
from fastapi import Query
from maggma.api.utils import STORE_PARAMS
from maggma.api.query_operator import QueryOperator


Expand All @@ -25,3 +26,57 @@ def query(
def ensure_indexes(self): # pragma: no cover
keys = self._keys_from_query()
return [(key, False) for key in keys]


class MultiThermoIDQuery(QueryOperator):
"""
Method to generate a query for different root-level thermo_id values
"""

def query(
self,
thermo_ids: Optional[str] = Query(
None, description="Comma-separated list of thermo_id values to query on"
),
) -> STORE_PARAMS:

crit = {} # type: dict

if thermo_ids:

thermo_id_list = [thermo_id.strip() for thermo_id in thermo_ids.split(",")]

if len(thermo_id_list) == 1:
crit.update({"thermo_id": thermo_id_list[0]})
else:
crit.update({"thermo_id": {"$in": thermo_id_list}})

return {"criteria": crit}


class MultiThermoTypeQuery(QueryOperator):
"""
Method to generate a query for different root-level thermo_type values
"""

def query(
self,
thermo_types: Optional[str] = Query(
None, description="Comma-separated list of thermo_type values to query on"
),
) -> STORE_PARAMS:

crit = {} # type: dict

if thermo_types:

thermo_type_list = [
thermo_type.strip() for thermo_type in thermo_types.split(",")
]

if len(thermo_type_list) == 1:
crit.update({"thermo_type": thermo_type_list[0]})
else:
crit.update({"thermo_type": {"$in": thermo_type_list}})

return {"criteria": crit}
12 changes: 9 additions & 3 deletions emmet-api/emmet/api/routes/thermo/resources.py
Expand Up @@ -8,7 +8,11 @@
SortQuery,
SparseFieldsQuery,
)
from emmet.api.routes.thermo.query_operators import IsStableQuery
from emmet.api.routes.thermo.query_operators import (
IsStableQuery,
MultiThermoIDQuery,
MultiThermoTypeQuery,
)
from emmet.api.core.global_header import GlobalHeaderProcessor
from emmet.api.routes.materials.query_operators import (
MultiMaterialIDQuery,
Expand Down Expand Up @@ -37,21 +41,23 @@ def thermo_resource(thermo_store):
thermo_store,
ThermoDoc,
query_operators=[
MultiThermoIDQuery(),
MultiMaterialIDQuery(),
MultiThermoTypeQuery(),
FormulaQuery(),
ChemsysQuery(),
IsStableQuery(),
NumericQuery(model=ThermoDoc),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(
ThermoDoc, default_fields=["material_id", "last_updated"]
ThermoDoc, default_fields=["thermo_id", "material_id", "last_updated"]
),
],
header_processor=GlobalHeaderProcessor(),
tags=["Thermo"],
disable_validation=True,
timeout=MAPISettings().TIMEOUT
timeout=MAPISettings().TIMEOUT,
)

return resource

0 comments on commit 6e3ee61

Please sign in to comment.