Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions emmet-api/emmet/api/query_operator/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from emmet.api.query_operator import QueryOperator
from emmet.api.utils import STORE_PARAMS

DEFAULT_LIMIT: int = 100
MAX_LIMIT: int = 1000


class AtlasPaginationQuery(QueryOperator):
"""Query operators to provides pagination for Atlas Search queries."""

def __init__(self, default_limit: int = 100, max_limit: int = 1000):
def __init__(self, default_limit: int = DEFAULT_LIMIT, max_limit: int = MAX_LIMIT):
"""
Args:
default_limit: the default number of documents to return
Expand Down Expand Up @@ -71,7 +74,7 @@ def meta(self) -> dict:
class PaginationQuery(QueryOperator):
"""Query operators to provides Pagination."""

def __init__(self, default_limit: int = 100, max_limit: int = 1000):
def __init__(self, default_limit: int = DEFAULT_LIMIT, max_limit: int = MAX_LIMIT):
"""
Args:
default_limit: the default number of documents to return
Expand Down
10 changes: 9 additions & 1 deletion emmet-api/emmet/api/routes/legacy/jcesr/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from emmet.api.resource import ReadOnlyResource
from emmet.core.molecules_jcesr import MoleculesDoc

from emmet.api.query_operator import PaginationQuery, SparseFieldsQuery
from emmet.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from emmet.api.routes.legacy.jcesr.query_operators import (
MoleculeBaseQuery,
MoleculeElementsQuery,
Expand All @@ -11,6 +11,13 @@
from emmet.api.core.global_header import GlobalHeaderProcessor
from emmet.api.core.settings import MAPISettings

JCESR_SORT_FIELDS = [
"task_id",
"EA",
"IE",
"charge",
]


def jcesr_resource(molecules_store):
resource = ReadOnlyResource(
Expand All @@ -22,6 +29,7 @@ def jcesr_resource(molecules_store):
MoleculeFormulaQuery(),
MultipleTaskIDsQuery(),
PaginationQuery(),
SortQuery(fields=JCESR_SORT_FIELDS, max_num=1),
SparseFieldsQuery(MoleculesDoc, default_fields=["task_id"]),
],
header_processor=GlobalHeaderProcessor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from emmet.api.query_operator.dynamic import NumericQuery
from emmet.api.query_operator import (
NumericQuery,
PaginationQuery,
SortQuery,
SparseFieldsQuery,
)
from emmet.api.resource import ReadOnlyResource
from emmet.core.electrode import InsertionElectrodeDoc
from emmet.api.core.global_header import GlobalHeaderProcessor

from emmet.api.query_operator import PaginationQuery, SparseFieldsQuery
from emmet.api.routes.materials.insertion_electrodes.query_operators import (
ElectrodeFormulaQuery,
ElectrodeElementsQuery,
Expand All @@ -14,6 +18,18 @@

from emmet.api.core.settings import MAPISettings

sort_fields = [
"battery_id",
"max_delta_volume",
"average_voltage",
"capacity_grav",
"capacity_vol",
"energy_grav",
"energy_vol",
"stability_charge",
"stability_discharge",
]


def insertion_electrodes_resource(insertion_electrodes_store):
resource = ReadOnlyResource(
Expand All @@ -31,6 +47,7 @@ def insertion_electrodes_resource(insertion_electrodes_store):
InsertionElectrodeDoc,
default_fields=["battery_id", "last_updated"],
),
SortQuery(fields=sort_fields, max_num=1),
],
header_processor=GlobalHeaderProcessor(),
tags=["Materials Electrodes"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def electrodes_formula_to_criteria(formulas: str) -> dict:
"""
Santizes formula into a dictionary to search with wild cards
Sanitizes formula into a dictionary to search with wild cards
over electrodes data

Arguments:
Expand Down Expand Up @@ -116,7 +116,7 @@ def electrodes_formula_to_criteria(formulas: str) -> dict:

def electrodes_chemsys_to_criteria(chemsys: str) -> dict:
"""
Santizes chemsys into a dictionary to search with wild cards
Sanitizes chemsys into a dictionary to search with wild cards
over electrodes data

Arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class SymmetryQuery(QueryOperator):
Method to generate a query on symmetry information.
"""

MAX_SPACE_GROUPS: int = 115
MAX_CRYSTAL_SYSTEMS: int = 3

def query(
self,
crystal_system: str | None = Query(
Expand Down Expand Up @@ -188,6 +191,13 @@ def query(
else {"$in": crystal_systems}
)

crystal_systems = sorted(set(crystal_systems))
if len(crystal_systems) > self.MAX_CRYSTAL_SYSTEMS:
raise ValueError(
f"You have queried for {len(crystal_systems)} crystal systems, "
f"however {self.MAX_CRYSTAL_SYSTEMS} can be queried at most."
)

spacegroup_numbers: list[int] = []
if isinstance(spacegroup_number, str | int):
spacegroup_numbers += (
Expand Down Expand Up @@ -227,8 +237,14 @@ def query(
)
spacegroup_numbers += new_sgn

spacegroup_numbers = sorted(set(spacegroup_numbers))
if len(spacegroup_numbers) > self.MAX_SPACE_GROUPS:
raise ValueError(
f"You have queried for {len(spacegroup_numbers)} space groups, "
f"however {self.MAX_SPACE_GROUPS} can be queried at most."
)

if len(spacegroup_numbers) > 0:
spacegroup_numbers = sorted(set(spacegroup_numbers))
crit["symmetry.number"] = (
spacegroup_numbers[0]
if len(spacegroup_numbers) == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class RoboTextSearchQuery(QueryOperator):
"""
Method to generate a robocrystallographer text search query
Method to generate a robocrystallographer text search query.
"""

def query(
Expand All @@ -32,7 +32,7 @@ def query(
"path": "description",
"allowAnalyzedField": True,
},
"sort": {"score": {"$meta": "searchScore"}, "description": 1},
"sort": {"score": {"$meta": "searchScore"}, "material_id": 1},
"count": {"type": "total"},
}
},
Expand Down
11 changes: 10 additions & 1 deletion emmet-api/emmet/api/routes/materials/xas/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from emmet.api.resource import ReadOnlyResource
from emmet.core.xas import XASDoc

from emmet.api.query_operator import PaginationQuery, SparseFieldsQuery
from emmet.api.query_operator import PaginationQuery, SortQuery, SparseFieldsQuery
from emmet.api.routes.materials.materials.query_operators import MultiMaterialIDQuery
from emmet.api.routes.materials.materials.query_operators import (
ElementsQuery,
Expand All @@ -12,6 +12,14 @@
from emmet.api.routes.materials.xas.query_operators import XASQuery, XASIDQuery
from emmet.api.core.settings import MAPISettings

XAS_SORT_FIELDS = [
"material_id",
"absorbing_element",
"edge",
"spectrum_type",
"spectrum_id",
]


def xas_resource(xas_store):
resource = ReadOnlyResource(
Expand All @@ -37,6 +45,7 @@ def xas_resource(xas_store):
"last_updated",
],
),
SortQuery(fields=XAS_SORT_FIELDS, max_num=1),
],
header_processor=GlobalHeaderProcessor(),
tags=["Materials XAS"],
Expand Down
12 changes: 11 additions & 1 deletion emmet-api/emmet/api/routes/molecules/summary/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from emmet.api.query_operator import (
PaginationQuery,
SparseFieldsQuery,
NumericQuery,
SortQuery,
SparseFieldsQuery,
)
from emmet.api.resource import ReadOnlyResource
from emmet.api.routes.molecules.molecules.query_operators import (
Expand All @@ -22,6 +23,14 @@

timeout = MAPISettings().TIMEOUT

MOLECULES_SUMMARY_SORT_FIELDS = [
"molecule_id",
"redox.NONE.electron_affinity",
"redox.NONE.ionization_energy",
"charge",
"spin_multiplicity",
]


def summary_resource(summary_store):
resource = ReadOnlyResource(
Expand All @@ -43,6 +52,7 @@ def summary_resource(summary_store):
"nelements",
],
),
SortQuery(fields=MOLECULES_SUMMARY_SORT_FIELDS, max_num=1),
SparseFieldsQuery(MoleculeSummaryDoc, default_fields=["molecule_id"]),
],
hint_scheme=SummaryHintScheme(),
Expand Down
Loading
Loading