Skip to content

Commit

Permalink
Remove sort parameters from resters (#864)
Browse files Browse the repository at this point in the history
* Remove sort params from resters

* Remove 404 from client error

* Linting
  • Loading branch information
munrojm committed Nov 21, 2023
1 parent d5240c5 commit 2af2749
Show file tree
Hide file tree
Showing 33 changed files with 6 additions and 207 deletions.
2 changes: 1 addition & 1 deletion mp_api/client/core/client.py
Expand Up @@ -817,7 +817,7 @@ def _submit_request_and_process(
f"REST query timed out on URL {url}. Try again with a smaller request."
)

if response.status_code in [400, 404]:
if response.status_code in [400]:
warnings.warn(
f"The server does not support the request made to {response.url}. This may be due to an outdated mp-api package, or a problem with the query."
)
Expand Down
1 change: 0 additions & 1 deletion mp_api/client/core/settings.py
Expand Up @@ -49,7 +49,6 @@ class MAPIClientSettings(BaseSettings):
"condition_mixing_media",
"condition_heating_atmosphere",
"operations",
"_sort_fields",
"_fields",
],
description="List API query parameters that do not support parallel requests.",
Expand Down
21 changes: 5 additions & 16 deletions mp_api/client/mprester.py
Expand Up @@ -657,7 +657,6 @@ def get_entries(
inc_structure: bool = None,
property_data: list[str] = None,
conventional_unit_cell: bool = False,
sort_by_e_above_hull: bool = False,
additional_criteria: dict = None,
) -> list[ComputedStructureEntry]:
"""Get a list of ComputedEntries or ComputedStructureEntries corresponding
Expand Down Expand Up @@ -688,8 +687,6 @@ def get_entries(
input parameters in the 'MPRester.thermo.available_fields' list.
conventional_unit_cell (bool): Whether to get the standard
conventional unit cell
sort_by_e_above_hull (bool): Whether to sort the list of entries by
e_above_hull in ascending order.
additional_criteria (dict): Any additional criteria to pass. The keys and values should
correspond to proper function inputs to `MPRester.thermo.search`. For instance,
if you are only interested in entries on the convex hull, you could pass
Expand Down Expand Up @@ -726,19 +723,11 @@ def get_entries(
else ["entries", "thermo_type"] + property_data
)

if sort_by_e_above_hull:
docs = self.thermo.search(
**input_params, # type: ignore
all_fields=False,
fields=fields,
sort_fields=["energy_above_hull"],
)
else:
docs = self.thermo.search(
**input_params,
all_fields=False,
fields=fields, # type: ignore
)
docs = self.thermo.search(
**input_params,
all_fields=False,
fields=fields, # type: ignore
)

for doc in docs:
entry_list = (
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/_messages.py
Expand Up @@ -42,7 +42,6 @@ def set_message(
def get_messages(
self,
last_updated: datetime,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -52,7 +51,6 @@ def get_messages(
Args:
last_updated (datetime): Datetime to use to query for newer messages
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand All @@ -67,11 +65,6 @@ def get_messages(
"""
query_params = {}

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

return self._search(
last_updated=last_updated,
num_chunks=num_chunks,
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/absorption.py
Expand Up @@ -20,7 +20,6 @@ def search(
elements: list[str] | None = None,
exclude_elements: list[str] | None = None,
formula: list[str] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -37,7 +36,6 @@ def search(
formula (str, List[str]): A formula including anonymized formula
or wild cards (e.g., Fe2O3, ABO3, Si*). A list of chemical formulas can also be passed
(e.g., [Fe2O3, ABO3]).
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -72,11 +70,6 @@ def search(

query_params.update({"material_ids": ",".join(validate_ids(material_ids))})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/alloys.py
Expand Up @@ -17,7 +17,6 @@ def search(
self,
material_ids: str | list[str] | None = None,
formulae: list[str] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -33,7 +32,6 @@ def search(
Arguments:
material_ids (str, List[str]): Search for alloys containing the specified Material IDs
formulae (List[str]): Search for alloys containing the specified formulae
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand All @@ -56,11 +54,6 @@ def search(

query_params.update({"material_ids": ",".join(validate_ids(material_ids))})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

return super()._search(
formulae=formulae,
num_chunks=num_chunks,
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/bonds.py
Expand Up @@ -32,7 +32,6 @@ def search(
max_bond_length: tuple[float, float] | None = None,
mean_bond_length: tuple[float, float] | None = None,
min_bond_length: tuple[float, float] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -51,7 +50,6 @@ def search(
in the structure to consider.
min_bond_length (Tuple[float,float]): Minimum and maximum value for the minimum bond length
in the structure to consider.
sort_fields (List[str]): Fields used to sort results. Prefixing with '-' will sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -101,11 +99,6 @@ def search(
{"coordination_envs_anonymous": ",".join(coordination_envs_anonymous)}
)

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/chemenv.py
Expand Up @@ -42,7 +42,6 @@ def search(
num_elements: tuple[int, int] | None = None,
num_sites: tuple[int, int] | None = None,
volume: tuple[float, float] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -68,7 +67,6 @@ def search(
num_elements (Tuple[int,int]): Minimum and maximum number of elements to consider.
num_sites (Tuple[int,int]): Minimum and maximum number of sites to consider.
volume (Tuple[float,float]): Minimum and maximum volume to consider.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -136,11 +134,6 @@ def search(

query_params.update({"species": ",".join(species)})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/dielectric.py
Expand Up @@ -31,7 +31,6 @@ def search(
e_ionic: tuple[float, float] | None = None,
e_electronic: tuple[float, float] | None = None,
n: tuple[float, float] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -46,7 +45,6 @@ def search(
e_ionic (Tuple[float,float]): Minimum and maximum ionic dielectric constant to consider.
e_electronic (Tuple[float,float]): Minimum and maximum electronic dielectric constant to consider.
n (Tuple[float,float]): Minimum and maximum refractive index to consider.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -81,11 +79,6 @@ def search(
if n:
query_params.update({"n_min": n[0], "n_max": n[1]})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/elasticity.py
Expand Up @@ -35,7 +35,6 @@ def search(
k_reuss: tuple[float, float] | None = None,
k_vrh: tuple[float, float] | None = None,
poisson_ratio: tuple[float, float] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -62,7 +61,6 @@ def search(
the Voigt-Reuss-Hill average of the bulk modulus.
poisson_ratio (Tuple[float,float]): Minimum and maximum value to consider for
Poisson's ratio.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -111,11 +109,6 @@ def search(
{"poisson_min": poisson_ratio[0], "poisson_max": poisson_ratio[1]}
)

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/electrodes.py
Expand Up @@ -46,7 +46,6 @@ def search( # pragma: ignore
stability_charge: tuple[float, float] | None = None,
stability_discharge: tuple[float, float] | None = None,
working_ion: Element | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand Down Expand Up @@ -86,7 +85,6 @@ def search( # pragma: ignore
stability_discharge (Tuple[float,float]): Minimum and maximum value of the energy above hull of the
discharged material.
working_ion (Element, List[Element]): Element or list of elements of the working ion.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -135,11 +133,6 @@ def search( # pragma: ignore
if exclude_elements:
query_params.update({"exclude_elements": ",".join(exclude_elements)})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

for param, value in locals().items():
if (
param
Expand Down
21 changes: 0 additions & 21 deletions mp_api/client/routes/materials/electronic_structure.py
Expand Up @@ -45,7 +45,6 @@ def search(
is_metal: bool = None,
magnetic_ordering: Ordering | None = None,
num_elements: tuple[int, int] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -69,7 +68,6 @@ def search(
is_metal (bool): Whether the material is considered a metal.
magnetic_ordering (Ordering): Magnetic ordering of the material.
num_elements (Tuple[int,int]): Minimum and maximum number of elements to consider.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -129,11 +127,6 @@ def search(
if is_metal is not None:
query_params.update({"is_metal": is_metal})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down Expand Up @@ -172,7 +165,6 @@ def search(
is_metal: bool = None,
magnetic_ordering: Ordering | None = None,
path_type: BSPathType = BSPathType.setyawan_curtarolo,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -187,7 +179,6 @@ def search(
is_metal (bool): Whether the material is considered a metal.
magnetic_ordering (Ordering): Magnetic ordering of the material.
path_type (BSPathType): k-path selection convention for the band structure.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -218,11 +209,6 @@ def search(
if is_metal is not None:
query_params.update({"is_metal": is_metal})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down Expand Up @@ -344,7 +330,6 @@ def search(
orbital: OrbitalType | None = None,
projection_type: DOSProjectionType = DOSProjectionType.total,
spin: Spin = Spin.up,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -360,7 +345,6 @@ def search(
orbital (OrbitalType): Orbital for orbital-projected dos data.
projection_type (DOSProjectionType): Projection type of dos data. Default is the total dos.
spin (Spin): Spin channel of dos data. If non spin-polarized data is stored in Spin.up
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand Down Expand Up @@ -392,11 +376,6 @@ def search(
if magnetic_ordering:
query_params.update({"magnetic_ordering": magnetic_ordering.value})

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down
7 changes: 0 additions & 7 deletions mp_api/client/routes/materials/eos.py
Expand Up @@ -28,7 +28,6 @@ def search(
self,
energies: tuple[float, float] | None = None,
volumes: tuple[float, float] | None = None,
sort_fields: list[str] | None = None,
num_chunks: int | None = None,
chunk_size: int = 1000,
all_fields: bool = True,
Expand All @@ -39,7 +38,6 @@ def search(
Arguments:
energies (Tuple[float,float]): Minimum and maximum energy in eV/atom to consider for EOS plot range.
volumes (Tuple[float,float]): Minimum and maximum volume in A³/atom to consider for EOS plot range.
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int): Number of data entries per chunk.
all_fields (bool): Whether to return all fields in the document. Defaults to True.
Expand All @@ -59,11 +57,6 @@ def search(
{"energies_min": energies[0], "energies_max": energies[1]}
)

if sort_fields:
query_params.update(
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
)

query_params = {
entry: query_params[entry]
for entry in query_params
Expand Down

0 comments on commit 2af2749

Please sign in to comment.