-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from materialsproject/alloys
Alloys integration
- Loading branch information
Showing
9 changed files
with
544 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.