Skip to content

Commit

Permalink
Merge pull request #364 from materialsproject/alloys
Browse files Browse the repository at this point in the history
Alloys integration
  • Loading branch information
mkhorton committed Jul 14, 2022
2 parents fdf96ef + 22a87d6 commit a216c1d
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 36 deletions.
82 changes: 47 additions & 35 deletions emmet-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,206 +13,218 @@
db_suffix = os.environ.get("MAPI_DB_NAME_SUFFIX", db_version)
debug = default_settings.DEBUG

# allow db_uri to be set with a different protocol scheme
# but prepend with mongodb+srv:// if not otherwise specified
if not urlparse(db_uri).scheme:
db_uri = "mongodb+srv://" + db_uri

if db_uri:

materials_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="materials",
)

bonds_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="bonds",
)

formula_autocomplete_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="_id",
collection_name="formula_autocomplete",
)

task_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="tasks",
)

thermo_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="thermo",
)

phase_diagram_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="chemsys",
collection_name="phase_diagram",
)

dielectric_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="dielectric",
)

piezoelectric_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="piezoelectric",
)

magnetism_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="magnetism",
)

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

eos_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="eos",
)

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

xas_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="spectrum_id",
collection_name="xas",
)

gb_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="grain_boundaries",
)

fermi_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="fermi_surface",
)

elasticity_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="elasticity",
)

doi_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="dois",
)

substrates_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="film_id",
collection_name="substrates",
)

surface_props_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="surface_properties",
)

robo_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="robocrys",
)

synth_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="_id",
collection_name="synth_descriptions",
)

insertion_electrodes_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="battery_id",
collection_name="insertion_electrodes",
)

molecules_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="task_id",
collection_name="molecules",
)

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

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

alloy_pairs_store = MongoURIStore(
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="summary",
)

summary_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database=f"mp_core_{db_suffix}",
key="material_id",
collection_name="summary",
)

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

s3_bs_index = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="s3_bandstructure_index",
)

s3_dos_index = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="s3_dos_index",
Expand All @@ -237,7 +249,7 @@
)

s3_chgcar_index = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="atomate_chgcar_fs_index",
Expand All @@ -254,34 +266,34 @@
)

chgcar_url = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_core",
key="fs_id",
collection_name="chgcar_s3_urls",
)

mpcomplete_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_consumers",
key="submission_id",
collection_name="mpcomplete",
)

consumer_settings_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_consumers",
key="consumer_id",
collection_name="settings",
)

general_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
uri=db_uri,
database="mp_consumers",
key="submission_id",
collection_name="general_store",
)
else:
raise RuntimeError("Must specify MongoDB Atlas URI")
raise RuntimeError("Must specify MongoDB URI containing inputs.")

# Materials
from emmet.api.routes.materials.resources import (
Expand Down
Empty file.
63 changes: 63 additions & 0 deletions emmet-api/emmet/api/routes/alloys/query_operators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import Optional
from fastapi import Query
from maggma.api.query_operator import QueryOperator
from maggma.api.utils import STORE_PARAMS

from collections import defaultdict


class MaterialIDsSearchQuery(QueryOperator):
"""
Method to generate a query on search docs using multiple material_id values
"""

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

crit = {}

if material_ids:

terminal_search = {
"_search.id": {
"$in": [material_id.strip() for material_id in material_ids.split(",")]
}
}

member_search = {
"_search.member_ids": {
"$in": [material_id.strip() for material_id in material_ids.split(",")]
}
}

crit.update({"$or": [terminal_search, member_search]})

return {"criteria": crit}


class FormulaSearchQuery(QueryOperator):

def query(
self,
formulae: Optional[str] = Query(
None, description="Comma-separated list of end-point formulas to query."
),
) -> STORE_PARAMS:

crit = {}

if formulae:

formula_search = {
"_search.formula": {
"$in": [formula.strip() for formula in formulae.split(",")]
}
}

crit.update(formula_search)

return {"criteria": crit}
28 changes: 28 additions & 0 deletions emmet-api/emmet/api/routes/alloys/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from maggma.api.resource import ReadOnlyResource

from maggma.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery

from emmet.core.alloys import AlloyPairDoc, AlloySystemDoc

from mp_api.routes.alloys.query_operators import (
MaterialIDsSearchQuery,
FormulaSearchQuery,
)


def alloys_resource(alloys_store):
resource = ReadOnlyResource(
alloy_pairs_store,
AlloyPairDoc,
query_operators=[
MaterialIDsSearchQuery(),
FormulaSearchQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(AlloyPairDoc, default_fields=["pair_id"],),
],
tags=["Alloys"],
disable_validation=True,
)

return resource
Empty file.

0 comments on commit a216c1d

Please sign in to comment.