Skip to content

Commit

Permalink
Add sorting back to summary (#997)
Browse files Browse the repository at this point in the history
* Add sorting back to summary

* Linting
  • Loading branch information
munrojm authored Apr 30, 2024
1 parent 498a968 commit 9381cc2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
42 changes: 41 additions & 1 deletion emmet-api/emmet/api/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal, Optional
from typing import Literal, Optional, List
from pydantic import Field
from emmet.api import __file__ as root_dir
import os
Expand All @@ -24,6 +24,46 @@ class MAPISettings(BaseSettings):
None, description="Database name suffix. Either blue or green."
)

SORT_FIELDS: List[str] = Field(
[
"nsites",
"nelements",
"formula_pretty",
"formula_anonymous",
"chemsys",
"volume",
"density",
"density_atomic",
"material_id",
"uncorrected_energy_per_atom",
"energy_per_atom",
"formation_energy_per_atom",
"energy_above_hull",
"band_gap",
"cbm",
"vbm",
"efermi",
"ordering",
"total_magnetization",
"total_magnetization_normalized_vol",
"total_magnetization_normalized_formula_units",
"num_magnetic_sites",
"num_unique_magnetic_sites",
"universal_anistropy",
"homogeneous_poisson",
"e_total",
"e_ionic",
"e_electronic",
"n",
"e_ij_max",
"weighted_surface_energy_EV_PER_ANG2",
"weighted_surface_energy",
"weighted_work_function",
"surface_anisotropy",
"shape_factor",
],
description="List of fields that support sorting",
)
TIMEOUT: int = Field(
30,
description="Number of seconds to wait for pymongo operations before raising a timeout error.",
Expand Down
6 changes: 5 additions & 1 deletion emmet-api/emmet/api/routes/materials/summary/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
PaginationQuery,
SparseFieldsQuery,
NumericQuery,
SortQuery,
)
from maggma.api.resource import ReadOnlyResource, AggregationResource
from emmet.api.routes.materials.materials.query_operators import (
Expand Down Expand Up @@ -37,7 +38,9 @@
from emmet.api.core.global_header import GlobalHeaderProcessor
from emmet.api.core.settings import MAPISettings

timeout = MAPISettings().TIMEOUT
settings = MAPISettings() # type: ignore
timeout = settings.TIMEOUT
sort_fields = settings.SORT_FIELDS


def summary_resource(summary_store):
Expand All @@ -64,6 +67,7 @@ def summary_resource(summary_store):
PaginationQuery(),
SparseFieldsQuery(SummaryDoc, default_fields=["material_id"]),
LicenseQuery(),
SortQuery(fields=sort_fields, max_num=1),
],
hint_scheme=SummaryHintScheme(),
header_processor=GlobalHeaderProcessor(),
Expand Down

0 comments on commit 9381cc2

Please sign in to comment.