Skip to content

Commit

Permalink
New electronic_structure endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed Apr 30, 2021
1 parent f3a29e9 commit 9c3fc34
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app.py
Expand Up @@ -44,6 +44,8 @@
molecules_store_json = os.environ.get("MOLECULES_STORE", "molecules_store.json")
search_store_json = os.environ.get("SEARCH_STORE", "search_store.json")

es_store_json = os.environ.get("ES_STORE", "es_store.json")

bs_store_json = os.environ.get("BS_STORE", "bs_store.json")
dos_store_json = os.environ.get("DOS_STORE", "dos_store.json")

Expand Down Expand Up @@ -227,6 +229,13 @@
collection_name="search",
)

es_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
key="material_id",
collection_name="electronic_structure",
)

bs_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
Expand Down Expand Up @@ -315,6 +324,8 @@
molecules_store = loadfn(molecules_store_json)
search_store = loadfn(search_store_json)

es_store = loadfn(es_store_json)

bs_store = loadfn(bs_store_json)
dos_store = loadfn(dos_store_json)
s3_bs_index = loadfn(s3_bs_index_json)
Expand Down Expand Up @@ -458,15 +469,10 @@

resources.update({"search": search_resource(search_store)})

# Band Structure
from mp_api.routes.bandstructure.resources import bs_resource

resources.update({"bs": bs_resource(bs_store, s3_bs)})

# DOS
from mp_api.routes.dos.resources import dos_resource
# Electronic Structure
from mp_api.routes.electronic_structure.resources import es_resource

resources.update({"dos": dos_resource(dos_store, s3_dos)})
resources.update({"electronic_structure": es_resource(es_store)})

# MPComplete
from mp_api.routes.mpcomplete.resources import mpcomplete_resource
Expand Down
Empty file.
35 changes: 35 additions & 0 deletions src/mp_api/routes/electronic_structure/resources.py
@@ -0,0 +1,35 @@
from mp_api.core.resource import GetResource
from emmet.core.electronic_structure import ElectronicStructureDoc

from fastapi.param_functions import Query

from mp_api.core.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from mp_api.routes.materials.query_operators import (
ElementsQuery,
FormulaQuery,
MinMaxQuery,
)
from mp_api.routes.dos.query_operators import DOSDataQuery

from mp_api.core.utils import STORE_PARAMS
from fastapi import HTTPException, Depends


def es_resource(es_store):
resource = GetResource(
es_store,
ElectronicStructureDoc,
query_operators=[
FormulaQuery(),
ElementsQuery(),
MinMaxQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(
ElectronicStructureDoc, default_fields=["material_id", "last_updated"]
),
],
tags=["Electronic Structure"],
)

return resource

0 comments on commit 9c3fc34

Please sign in to comment.