Skip to content

Commit

Permalink
Core query ops switched to maggma
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Munro committed May 25, 2021
1 parent 4542064 commit c259769
Show file tree
Hide file tree
Showing 41 changed files with 203 additions and 434 deletions.
2 changes: 1 addition & 1 deletion src/mp_api/core/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from mp_api.core.settings import MAPISettings

from mp_api.core.query_operator import (
from maggma.api.query_operator import (
QueryOperator,
PaginationQuery,
SparseFieldsQuery,
Expand Down
12 changes: 4 additions & 8 deletions src/mp_api/routes/_consumer/query_operator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from typing import Dict
from fastapi import Query, Body
from mp_api.core.utils import STORE_PARAMS
from mp_api.core.query_operator import QueryOperator
from maggma.api.utils import STORE_PARAMS
from maggma.api.query_operator import QueryOperator


class UserSettingsPostQuery(QueryOperator):
"""Query operators to provide user settings information to post"""

def query(
self,
consumer_id: str = Query(..., title="Consumer ID",),
settings: Dict = Body(..., title="User settings",),
self, consumer_id: str = Query(..., title="Consumer ID",), settings: Dict = Body(..., title="User settings",),
) -> STORE_PARAMS:

self.cid = consumer_id
Expand All @@ -30,9 +28,7 @@ def post_process(self, written):
class UserSettingsGetQuery(QueryOperator):
"""Query operators to provide user settings information"""

def query(
self, consumer_id: str = Query(..., title="Consumer ID",),
) -> STORE_PARAMS:
def query(self, consumer_id: str = Query(..., title="Consumer ID",),) -> STORE_PARAMS:

crit = {"consumer_id": consumer_id}

Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/charge_density/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from maggma.api.resource import ReadOnlyResource
from mp_api.core.models import Response
from mp_api.routes.charge_density.models import ChgcarDataDoc
from mp_api.core.query_operator import PaginationQuery, SparseFieldsQuery, SortQuery
from maggma.api.query_operator import PaginationQuery, SparseFieldsQuery, SortQuery
from mp_api.core.utils import STORE_PARAMS
from fastapi import HTTPException, Depends

Expand Down
35 changes: 10 additions & 25 deletions src/mp_api/routes/dielectric/query_operators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from fastapi import Query
from mp_api.core.query_operator import STORE_PARAMS, QueryOperator
from maggma.api.query_operator import QueryOperator
from maggma.api.utils import STORE_PARAMS

from collections import defaultdict

Expand All @@ -12,30 +13,14 @@ class DielectricQuery(QueryOperator):

def query(
self,
e_total_max: Optional[float] = Query(
None, description="Maximum value for the total dielectric constant.",
),
e_total_min: Optional[float] = Query(
None, description="Minimum value for the total dielectric constant.",
),
e_ionic_max: Optional[float] = Query(
None, description="Maximum value for the ionic dielectric constant.",
),
e_ionic_min: Optional[float] = Query(
None, description="Minimum value for the ionic dielectric constant.",
),
e_static_max: Optional[float] = Query(
None, description="Maximum value for the static dielectric constant.",
),
e_static_min: Optional[float] = Query(
None, description="Minimum value for the static dielectric constant.",
),
n_max: Optional[float] = Query(
None, description="Maximum value for the refractive index.",
),
n_min: Optional[float] = Query(
None, description="Minimum value for the refractive index.",
),
e_total_max: Optional[float] = Query(None, description="Maximum value for the total dielectric constant.",),
e_total_min: Optional[float] = Query(None, description="Minimum value for the total dielectric constant.",),
e_ionic_max: Optional[float] = Query(None, description="Maximum value for the ionic dielectric constant.",),
e_ionic_min: Optional[float] = Query(None, description="Minimum value for the ionic dielectric constant.",),
e_static_max: Optional[float] = Query(None, description="Maximum value for the static dielectric constant.",),
e_static_min: Optional[float] = Query(None, description="Minimum value for the static dielectric constant.",),
n_max: Optional[float] = Query(None, description="Maximum value for the refractive index.",),
n_min: Optional[float] = Query(None, description="Minimum value for the refractive index.",),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/dielectric/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from maggma.api.resource import ReadOnlyResource
from mp_api.routes.dielectric.models import DielectricDoc

from mp_api.core.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from maggma.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from mp_api.routes.dielectric.query_operators import DielectricQuery


Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/dois/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from maggma.api.resource import ReadOnlyResource
from mp_api.routes.dois.models import DOIDoc

from mp_api.core.query_operator import PaginationQuery, SparseFieldsQuery
from maggma.api.query_operator import PaginationQuery, SparseFieldsQuery


def dois_resource(dois_store):
Expand Down
70 changes: 20 additions & 50 deletions src/mp_api/routes/elasticity/query_operators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from fastapi import Query
from mp_api.core.query_operator import STORE_PARAMS, QueryOperator
from maggma.api.query_operator import QueryOperator
from maggma.api.utils import STORE_PARAMS

from collections import defaultdict

Expand All @@ -13,28 +14,22 @@ class BulkModulusQuery(QueryOperator):
def query(
self,
k_voigt_max: Optional[float] = Query(
None,
description="Maximum value for the Voigt average of the bulk modulus in GPa.",
None, description="Maximum value for the Voigt average of the bulk modulus in GPa.",
),
k_voigt_min: Optional[float] = Query(
None,
description="Minimum value for the Voigt average of the bulk modulus in GPa.",
None, description="Minimum value for the Voigt average of the bulk modulus in GPa.",
),
k_reuss_max: Optional[float] = Query(
None,
description="Maximum value for the Reuss average of the bulk modulus in GPa.",
None, description="Maximum value for the Reuss average of the bulk modulus in GPa.",
),
k_reuss_min: Optional[float] = Query(
None,
description="Minimum value for the Reuss average of the bulk modulus in GPa.",
None, description="Minimum value for the Reuss average of the bulk modulus in GPa.",
),
k_vrh_max: Optional[float] = Query(
None,
description="Maximum value for the Voigt-Reuss-Hill average of the bulk modulus in GPa.",
None, description="Maximum value for the Voigt-Reuss-Hill average of the bulk modulus in GPa.",
),
k_vrh_min: Optional[float] = Query(
None,
description="Minimum value for the Voigt-Reuss-Hill average of the bulk modulus in GPa.",
None, description="Minimum value for the Voigt-Reuss-Hill average of the bulk modulus in GPa.",
),
) -> STORE_PARAMS:

Expand Down Expand Up @@ -64,28 +59,22 @@ class ShearModulusQuery(QueryOperator):
def query(
self,
g_voigt_max: Optional[float] = Query(
None,
description="Maximum value for the Voigt average of the shear modulus in GPa.",
None, description="Maximum value for the Voigt average of the shear modulus in GPa.",
),
g_voigt_min: Optional[float] = Query(
None,
description="Minimum value for the Voigt average of the shear modulus in GPa.",
None, description="Minimum value for the Voigt average of the shear modulus in GPa.",
),
g_reuss_max: Optional[float] = Query(
None,
description="Maximum value for the Reuss average of the shear modulus in GPa.",
None, description="Maximum value for the Reuss average of the shear modulus in GPa.",
),
g_reuss_min: Optional[float] = Query(
None,
description="Minimum value for the Reuss average of the shear modulus in GPa.",
None, description="Minimum value for the Reuss average of the shear modulus in GPa.",
),
g_vrh_max: Optional[float] = Query(
None,
description="Maximum value for the Voigt-Reuss-Hill average of the shear modulus in GPa.",
None, description="Maximum value for the Voigt-Reuss-Hill average of the shear modulus in GPa.",
),
g_vrh_min: Optional[float] = Query(
None,
description="Minimum value for the Voigt-Reuss-Hill average of the shear modulus in GPa.",
None, description="Minimum value for the Voigt-Reuss-Hill average of the shear modulus in GPa.",
),
) -> STORE_PARAMS:

Expand Down Expand Up @@ -115,31 +104,16 @@ class PoissonQuery(QueryOperator):

def query(
self,
elastic_anisotropy_max: Optional[float] = Query(
None,
description="Maximum value for the elastic anisotropy.",
),
elastic_anisotropy_min: Optional[float] = Query(
None,
description="Maximum value for the elastic anisotropy.",
),
poisson_max: Optional[float] = Query(
None,
description="Maximum value for Poisson's ratio.",
),
poisson_min: Optional[float] = Query(
None,
description="Minimum value for Poisson's ratio.",
),
elastic_anisotropy_max: Optional[float] = Query(None, description="Maximum value for the elastic anisotropy.",),
elastic_anisotropy_min: Optional[float] = Query(None, description="Maximum value for the elastic anisotropy.",),
poisson_max: Optional[float] = Query(None, description="Maximum value for Poisson's ratio.",),
poisson_min: Optional[float] = Query(None, description="Minimum value for Poisson's ratio.",),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict

d = {
"elasticity.universal_anisotropy": [
elastic_anisotropy_min,
elastic_anisotropy_max,
],
"elasticity.universal_anisotropy": [elastic_anisotropy_min, elastic_anisotropy_max,],
"elasticity.homogeneous_poisson": [poisson_min, poisson_max],
}

Expand All @@ -159,11 +133,7 @@ class ChemsysQuery(QueryOperator):
"""

def query(
self,
chemsys: Optional[str] = Query(
None,
description="Dash-delimited list of elements in the material.",
),
self, chemsys: Optional[str] = Query(None, description="Dash-delimited list of elements in the material.",),
):

crit = {} # type: dict
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/elasticity/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from maggma.api.resource import ReadOnlyResource
from mp_api.routes.elasticity.models import ElasticityDoc

from mp_api.core.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from maggma.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from mp_api.routes.elasticity.query_operators import (
ChemsysQuery,
BulkModulusQuery,
Expand Down
Loading

0 comments on commit c259769

Please sign in to comment.