Skip to content

Commit

Permalink
Provenance endpoint and test bug fixes (#346)
Browse files Browse the repository at this point in the history
* Initial commit of prevenance endpoint

* Provenance client suffix fix

* Disable validation on provenance endpoint

* xas, and oxi test fixes

* Remove phonon_img endpoint from tests

* Fix provenance client stub

* Get references method added to MPRester

* Mark appropriate provenance test  xfail
  • Loading branch information
Jason Munro authored Jul 28, 2021
1 parent 1047518 commit 6b5f2b1
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 10 deletions.
14 changes: 14 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)
molecules_store_json = os.environ.get("MOLECULES_STORE", "molecules_store.json")
oxi_states_store_json = os.environ.get("OXI_STATES_STORE", "oxi_states_store.json")
provenance_store_json = os.environ.get("PROVENANCE_STORE", "provenance_store.json")
summary_store_json = os.environ.get("SUMMARY_STORE", "summary_store.json")

es_store_json = os.environ.get("ES_STORE", "es_store.json")
Expand Down Expand Up @@ -222,6 +223,13 @@
collection_name="oxi_states",
)

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

summary_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
Expand Down Expand Up @@ -320,6 +328,7 @@
insertion_electrodes_store = loadfn(insertion_electrodes_store_json)
molecules_store = loadfn(molecules_store_json)
oxi_states_store = loadfn(oxi_states_store_json)
provenance_store = loadfn(provenance_store_json)
ssummary_store = loadfn(summary_store_json)

es_store = loadfn(es_store_json)
Expand Down Expand Up @@ -479,6 +488,11 @@

resources.update({"oxidation_states": [oxi_states_resource(oxi_states_store)]})

# Provenance
from mp_api.routes.provenance.resources import provenance_resource

resources.update({"provenance": [provenance_resource(provenance_store)]})

# Charge Density
from mp_api.routes.charge_density.resources import charge_density_resource

Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/matproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_materials_id_references(self, material_id):
Returns:
BibTeX (str)
"""
raise NotImplementedError
return self.provenance.get_document_by_id(material_id).references

def get_materials_ids(self, chemsys_formula):
"""
Expand Down
1 change: 1 addition & 0 deletions src/mp_api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
DosRester,
)
from mp_api.routes.oxidation_states.client import OxidationStatesRester
from mp_api.routes.provenance.client import ProvenanceRester
Empty file.
9 changes: 9 additions & 0 deletions src/mp_api/routes/provenance/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from mp_api.core.client import BaseRester
from emmet.core.provenance import ProvenanceDoc


class ProvenanceRester(BaseRester):

suffix = "provenance"
document_model = ProvenanceDoc # type: ignore
primary_key = "material_id"
12 changes: 12 additions & 0 deletions src/mp_api/routes/provenance/client.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import List, Optional
from emmet.core.provenance import ProvenanceDoc


class ProvenanceRester:

def get_document_by_id(
self,
document_id: str,
fields: Optional[List[str]] = None,
monty_decode: bool = True,
) -> ProvenanceDoc: ...
17 changes: 17 additions & 0 deletions src/mp_api/routes/provenance/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from maggma.api.resource import ReadOnlyResource
from maggma.api.query_operator import PaginationQuery

from emmet.core.provenance import ProvenanceDoc


def provenance_resource(provenance_store):
resource = ReadOnlyResource(
provenance_store,
ProvenanceDoc,
query_operators=[PaginationQuery()],
tags=["Provenance"],
disable_validation=True,
enable_default_search=False,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/xas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class XASRester(BaseRester):

suffix = "xas"
document_model = XASDoc # type: ignore
primary_key = "xas_id"
primary_key = "spectrum_id"

def get_available_elements(
# TODO implement actual check
Expand Down
5 changes: 1 addition & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

key_only_resters = {
"phonon": "mp-11703",
"phonon_img": "mp-11703",
"similarity": "mp-149",
"doi": "mp-149",
"wulff": "mp-149",
Expand All @@ -20,15 +19,13 @@
"electronic_structure_dos",
"substrates",
"synthesis",
"xas", # Temp
]

special_resters = [
"phonon_img",
"charge_density",
]

ignore_generic = ["oxidation_states"]
ignore_generic = ["provenance"] # temp


mpr = MPRester()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def test_get_database_version(self, mpr):
def test_get_materials_id_from_task_id(self, mpr):
assert mpr.get_materials_id_from_task_id("mp-540081") == "mp-19017"

# TODO: add method to MPRester
# def test_get_materials_id_references(self, mpr):
# data = mpr.get_materials_id_references("mp-123")
# assert len(data) > 1000
@pytest.mark.xfail
def test_get_materials_id_references(self, mpr):
data = mpr.get_materials_id_references("mp-123")
assert len(data) > 5

def test_get_materials_ids_doc(self, mpr):
mpids = mpr.get_materials_ids("Al2O3")
Expand Down

0 comments on commit 6b5f2b1

Please sign in to comment.