Skip to content

Commit

Permalink
[WIP] MPRester updates (#303)
Browse files Browse the repository at this point in the history
* Post resource bug fix in core rester class

* Fixes and tests for materials methods in MPRester

* ES related updates in MPRester and tests

* Thermo MPrester method tests added

* Cleanup MPRester test file

* MPRest error in get document by id

* Linting

* README codecov url fix

* Flake8 linting

* Find structure test change

* Fix deprecated tasks query

* Ignore resources in codecov

* Initial commit of oxi states endpoint

* Assign some MPRester class methods directly

* Fix charge density functions in MPRester

* Enable band structure tests

* Chgcar calc details test enabled

* Fix deprecation query op

* Some materials query op tests added

* Linting

* Multi task_id query op list  change

* Multi material_id query op list change

* Remaining tests added for materials query ops

* Rename materials query op test file

* Single element test in formula auto complete

* Consumer query operator tests

* Charge density query list change

* Charge density query operator test

* Add missing serialization tests

* Dielectric query op tests

* Elasticity query op tests and bug fixes

* Electrodes query op tests and bug fixes

* Electronic structure query op tests and fixes

* Linting

* Grain boundary query operator tests and fixes

* Magnetism query operator tests and fixes

* Molecules query operator tests and fixes

* MPComplete query operator tests and fixes

* MPComplete query operator bug fix

* Phonon image query operator test and update

* Piezo query operators tests and fixes

* Robocrys test added

* Dlesh out robocrys query op test

* Update agg pipeline in robocrys tests

* Linting

* Search query operator tests and updates

* Substrates query operator test and changes

* Surface property query operator test and fix

* Synthesis query operator test and fix

* Tasks query operator tests and fixes

* Thermo query operator test and update

* Rename xas query operators file

* XAS query operator tests and updates

* Oxi state query operator test and update

* MAPI tests

* Exclude ensure_indexes from codecov

* Linting

* Add models to codecov ignore

* Fix  client import statements

* Exclude consumer client from tests

* Temporary removal of oxi state client from test

* Fix exclusion of oxidation state client test

* Core client tests added

* Linting

* Fix some core client tests

* Openapi test for MAPI

* Surface and GB MPrester updates and fixes

* GB test update

* Mark GB test as xfail temporarily

* General search method added to search client

* Magnetism and surface prop client fixes

* Fix thermo type hinting on client

* Thermo client docstring fix

* Add specific client search tests

* Fix electrode query op test

* Linting

* Remove stray prints
  • Loading branch information
munrojm committed Jul 1, 2021
1 parent 9ff5f69 commit 3e19048
Show file tree
Hide file tree
Showing 112 changed files with 4,316 additions and 534 deletions.
7 changes: 6 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[run]
omit = *test*
omit =
*test*
*/resources.py
*/models.py
*/models/*

14 changes: 14 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"INSERTION_ELECTRODES_STORE", "insertion_electrodes_store.json"
)
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")
search_store_json = os.environ.get("SEARCH_STORE", "search_store.json")

es_store_json = os.environ.get("ES_STORE", "es_store.json")
Expand Down Expand Up @@ -226,6 +227,13 @@
collection_name="molecules",
)

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

search_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
Expand Down Expand Up @@ -324,6 +332,7 @@
synth_store = loadfn(synth_store_json)
insertion_electrodes_store = loadfn(insertion_electrodes_store_json)
molecules_store = loadfn(molecules_store_json)
oxi_states_store = loadfn(oxi_states_store_json)
search_store = loadfn(search_store_json)

es_store = loadfn(es_store_json)
Expand Down Expand Up @@ -485,6 +494,11 @@

resources.update({"molecules": [molecules_resource(molecules_store)]})

# Oxidation States
from mp_api.routes.oxidation_states.resources import oxi_states_resource

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

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

Expand Down
13 changes: 7 additions & 6 deletions src/mp_api/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import warnings

import requests
from monty.json import MontyEncoder, MontyDecoder
from monty.json import MontyDecoder
from requests.exceptions import RequestException
from pydantic import BaseModel
from tqdm import tqdm

from emmet.core.utils import jsanitize
from maggma.api.utils import api_sanitize

try:
Expand Down Expand Up @@ -147,15 +148,15 @@ def _post_resource(
available.
"""

payload = json.dumps(body, cls=MontyEncoder)
payload = jsanitize(body)

try:
url = self.endpoint
if suburl:
url = urljoin(self.endpoint, suburl)
if not url.endswith("/"):
url += "/"
response = self.session.post(url, data=payload, verify=True, params=params)
response = self.session.post(url, json=payload, verify=True, params=params)

if response.status_code == 200:

Expand Down Expand Up @@ -474,7 +475,7 @@ def _get_all_documents(

return all_results

def query_by_task_id(self, *args, **kwargs):
def query_by_task_id(self, *args, **kwargs): # pragma: ignore
print(
"query_by_task_id has been renamed to get_document_by_id to be more general"
)
Expand Down Expand Up @@ -504,10 +505,10 @@ def available_fields(self) -> List[str]:
return ["Unknown fields."]
return list(self.document_model.schema()["properties"].keys()) # type: ignore

def __repr__(self):
def __repr__(self): # pragma: ignore
return f"<{self.__class__.__name__} {self.endpoint}>"

def __str__(self):
def __str__(self): # pragma: ignore
if self.document_model is None:
return self.__repr__()
return (
Expand Down
Loading

0 comments on commit 3e19048

Please sign in to comment.