Skip to content

Commit

Permalink
Search endpoint query op updates
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 4, 2021
1 parent b867342 commit 6950477
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 94 deletions.
6 changes: 3 additions & 3 deletions src/mp_api/routes/electrodes/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
indexes.append(("max_delta_volume", False))
return indexes

Expand Down Expand Up @@ -205,7 +205,7 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
return indexes


Expand Down Expand Up @@ -265,5 +265,5 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
return indexes
2 changes: 1 addition & 1 deletion src/mp_api/routes/magnetism/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append(("magnetism." + key, False))
indexes.append(("magnetism." + key, False))
return indexes
2 changes: 1 addition & 1 deletion src/mp_api/routes/molecules/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
return indexes


Expand Down
87 changes: 1 addition & 86 deletions src/mp_api/routes/search/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,91 +43,6 @@ def query(
return {"criteria": crit}


class ThermoEnergySearchQuery(QueryOperator):
"""
Method to generate a query for ranges of thermo energy data in search docs
"""

def query(
self,
energy_max: Optional[float] = Query(
None, description="Maximum value for the total energy in eV.",
),
energy_min: Optional[float] = Query(
None, description="Minimum value for the total energy in eV.",
),
energy_per_atom_max: Optional[float] = Query(
None, description="Maximum value for the total energy in eV/atom.",
),
energy_per_atom_min: Optional[float] = Query(
None, description="Minimum value for the total energy in eV/atom.",
),
formation_energy_per_atom_max: Optional[float] = Query(
None, description="Maximum value for the formation energy in eV/atom.",
),
formation_energy_per_atom_min: Optional[float] = Query(
None, description="Minimum value for the formation energy in eV/atom.",
),
e_above_hull_max: Optional[float] = Query(
None, description="Maximum value for the energy above the hull in eV/atom.",
),
e_above_hull_min: Optional[float] = Query(
None, description="Minimum value for the energy above the hull in eV/atom.",
),
eq_reaction_max: Optional[float] = Query(
None,
description="Maximum value for the equilibrium reaction energy in eV/atom.",
),
eq_reaction_min: Optional[float] = Query(
None,
description="Minimum value for the equilibrium reaction energy in eV/atom.",
),
corrected_energy_max: Optional[float] = Query(
None, description="Maximum value for the corrected total energy in eV.",
),
corrected_energy_min: Optional[float] = Query(
None, description="Minimum value for the corrected total energy in eV.",
),
) -> STORE_PARAMS:

crit = defaultdict(dict) # type: dict

d = {
"energy": [energy_min, energy_max],
"energy_per_atom": [energy_per_atom_min, energy_per_atom_max],
"formation_energy_per_atom": [
formation_energy_per_atom_min,
formation_energy_per_atom_max,
],
"e_above_hull": [e_above_hull_min, e_above_hull_max],
"eq_reaction_e": [eq_reaction_min, eq_reaction_max],
"explanation.corrected_energy": [
corrected_energy_min,
corrected_energy_max,
],
}

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

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

return {"criteria": crit}

def ensure_indexes(self):
keys = [
"energy",
"energy_per_atom",
"formation_energy_per_atom",
"e_above_hull",
"eq_reaction_e",
"explanation.corrected_energy",
]
return [(key, False) for key in keys]


class SearchIsStableQuery(QueryOperator):
"""
Method to generate a query on whether a material is stable
Expand Down Expand Up @@ -253,7 +168,7 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
indexes.append(("universal_anisotropy", False))
indexes.append(("homogeneous_poisson", False))
return indexes
Expand Down
4 changes: 2 additions & 2 deletions src/mp_api/routes/search/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from mp_api.routes.search.models import SearchDoc, SearchStats
from mp_api.routes.search.query_operators import (
HasPropsQuery,
ThermoEnergySearchQuery,
SearchIsStableQuery,
SearchElasticityQuery,
SearchMagneticQuery,
Expand All @@ -27,6 +26,7 @@
)
from mp_api.routes.surface_properties.query_operators import SurfaceMinMaxQuery
from mp_api.routes.electronic_structure.query_operators import ESSummaryDataQuery
from mp_api.routes.thermo.query_operators import ThermoEnergyQuery


def search_resource(search_store):
Expand Down Expand Up @@ -133,7 +133,7 @@ async def generate_stats(
ElementsQuery(),
MinMaxQuery(),
SymmetryQuery(),
ThermoEnergySearchQuery(),
ThermoEnergyQuery(),
SearchIsStableQuery(),
SearchIsTheoreticalQuery(),
ESSummaryDataQuery(),
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/thermo/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ def ensure_indexes(self):
for key in keys:
if "_min" in key:
key = key.replace("_min", "")
indexes.append((key, False))
indexes.append((key, False))
return indexes

0 comments on commit 6950477

Please sign in to comment.