Skip to content

Commit

Permalink
Surface properties now uses numeric query op
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 28, 2021
1 parent d572c09 commit 470c613
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 65 deletions.
63 changes: 3 additions & 60 deletions src/mp_api/routes/surface_properties/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,6 @@
from maggma.api.query_operator import QueryOperator
from maggma.api.utils import STORE_PARAMS

from collections import defaultdict


class SurfaceMinMaxQuery(QueryOperator):
"""
Method to generate a query for ranges of surface energy, anisotropy, and shape factor.
"""

def query(
self,
weighted_surface_energy_max: Optional[float] = Query(
None, description="Maximum value for the weighted surface energy in J/m².",
),
weighted_surface_energy_min: Optional[float] = Query(
None, description="Minimum value for the weighted surface energy in J/m².",
),
weighted_work_function_max: Optional[float] = Query(
None, description="Maximum value for the weighted work function in eV.",
),
weighted_work_function_min: Optional[float] = Query(
None, description="Minimum value for the weighted work function in eV.",
),
surface_anisotropy_max: Optional[float] = Query(
None, description="Maximum value for the surface energy anisotropy.",
),
surface_anisotropy_min: Optional[float] = Query(
None, description="Minimum value for the surface energy anisotropy.",
),
shape_factor_max: Optional[float] = Query(None, description="Maximum value for the shape factor.",),
shape_factor_min: Optional[float] = Query(None, description="Minimum value for the shape factor.",),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict

d = {
"weighted_surface_energy": [weighted_surface_energy_min, weighted_surface_energy_max,],
"weighted_work_function": [weighted_work_function_min, weighted_work_function_max,],
"surface_anisotropy": [surface_anisotropy_min, surface_anisotropy_max],
"shape_factor": [shape_factor_min, shape_factor_max],
}

for entry in d:
if d[entry][0]:
crit[entry]["$gte"] = d[entry][0]

if d[entry][1]:
crit[entry]["$lte"] = d[entry][1]

return {"criteria": crit}

def ensure_indexes(self):
keys = [
"weighted_surface_energy",
"weighted_work_function",
"surface_anisotropy",
"shape_factor",
]
return [(key, False) for key in keys]


class ReconstructedQuery(QueryOperator):
"""
Expand All @@ -71,7 +12,9 @@ class ReconstructedQuery(QueryOperator):

def query(
self,
has_reconstructed: Optional[bool] = Query(None, description="Whether the entry has a reconstructed surface.",),
has_reconstructed: Optional[bool] = Query(
None, description="Whether the entry has a reconstructed surface.",
),
) -> STORE_PARAMS:

crit = {}
Expand Down
8 changes: 3 additions & 5 deletions src/mp_api/routes/surface_properties/resources.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from maggma.api.query_operator.dynamic import NumericQuery
from maggma.api.resource import ReadOnlyResource
from mp_api.routes.surface_properties.models import SurfacePropDoc

from maggma.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from mp_api.routes.surface_properties.query_operators import (
SurfaceMinMaxQuery,
ReconstructedQuery,
)
from mp_api.routes.surface_properties.query_operators import ReconstructedQuery


def surface_props_resource(surface_prop_store):
resource = ReadOnlyResource(
surface_prop_store,
SurfacePropDoc,
query_operators=[
SurfaceMinMaxQuery(),
NumericQuery(model=SurfacePropDoc),
ReconstructedQuery(),
SortQuery(),
PaginationQuery(),
Expand Down

0 comments on commit 470c613

Please sign in to comment.