Skip to content

Commit 2af2749

Browse files
author
Jason Munro
authored
Remove sort parameters from resters (#864)
* Remove sort params from resters * Remove 404 from client error * Linting
1 parent d5240c5 commit 2af2749

33 files changed

+6
-207
lines changed

mp_api/client/core/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def _submit_request_and_process(
817817
f"REST query timed out on URL {url}. Try again with a smaller request."
818818
)
819819

820-
if response.status_code in [400, 404]:
820+
if response.status_code in [400]:
821821
warnings.warn(
822822
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."
823823
)

mp_api/client/core/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class MAPIClientSettings(BaseSettings):
4949
"condition_mixing_media",
5050
"condition_heating_atmosphere",
5151
"operations",
52-
"_sort_fields",
5352
"_fields",
5453
],
5554
description="List API query parameters that do not support parallel requests.",

mp_api/client/mprester.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ def get_entries(
657657
inc_structure: bool = None,
658658
property_data: list[str] = None,
659659
conventional_unit_cell: bool = False,
660-
sort_by_e_above_hull: bool = False,
661660
additional_criteria: dict = None,
662661
) -> list[ComputedStructureEntry]:
663662
"""Get a list of ComputedEntries or ComputedStructureEntries corresponding
@@ -688,8 +687,6 @@ def get_entries(
688687
input parameters in the 'MPRester.thermo.available_fields' list.
689688
conventional_unit_cell (bool): Whether to get the standard
690689
conventional unit cell
691-
sort_by_e_above_hull (bool): Whether to sort the list of entries by
692-
e_above_hull in ascending order.
693690
additional_criteria (dict): Any additional criteria to pass. The keys and values should
694691
correspond to proper function inputs to `MPRester.thermo.search`. For instance,
695692
if you are only interested in entries on the convex hull, you could pass
@@ -726,19 +723,11 @@ def get_entries(
726723
else ["entries", "thermo_type"] + property_data
727724
)
728725

729-
if sort_by_e_above_hull:
730-
docs = self.thermo.search(
731-
**input_params, # type: ignore
732-
all_fields=False,
733-
fields=fields,
734-
sort_fields=["energy_above_hull"],
735-
)
736-
else:
737-
docs = self.thermo.search(
738-
**input_params,
739-
all_fields=False,
740-
fields=fields, # type: ignore
741-
)
726+
docs = self.thermo.search(
727+
**input_params,
728+
all_fields=False,
729+
fields=fields, # type: ignore
730+
)
742731

743732
for doc in docs:
744733
entry_list = (

mp_api/client/routes/_messages.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def set_message(
4242
def get_messages(
4343
self,
4444
last_updated: datetime,
45-
sort_fields: list[str] | None = None,
4645
num_chunks: int | None = None,
4746
chunk_size: int = 1000,
4847
all_fields: bool = True,
@@ -52,7 +51,6 @@ def get_messages(
5251
5352
Args:
5453
last_updated (datetime): Datetime to use to query for newer messages
55-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
5654
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
5755
chunk_size (int): Number of data entries per chunk.
5856
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -67,11 +65,6 @@ def get_messages(
6765
"""
6866
query_params = {}
6967

70-
if sort_fields:
71-
query_params.update(
72-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
73-
)
74-
7568
return self._search(
7669
last_updated=last_updated,
7770
num_chunks=num_chunks,

mp_api/client/routes/materials/absorption.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def search(
2020
elements: list[str] | None = None,
2121
exclude_elements: list[str] | None = None,
2222
formula: list[str] | None = None,
23-
sort_fields: list[str] | None = None,
2423
num_chunks: int | None = None,
2524
chunk_size: int = 1000,
2625
all_fields: bool = True,
@@ -37,7 +36,6 @@ def search(
3736
formula (str, List[str]): A formula including anonymized formula
3837
or wild cards (e.g., Fe2O3, ABO3, Si*). A list of chemical formulas can also be passed
3938
(e.g., [Fe2O3, ABO3]).
40-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
4139
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
4240
chunk_size (int): Number of data entries per chunk.
4341
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -72,11 +70,6 @@ def search(
7270

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

75-
if sort_fields:
76-
query_params.update(
77-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
78-
)
79-
8073
query_params = {
8174
entry: query_params[entry]
8275
for entry in query_params

mp_api/client/routes/materials/alloys.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def search(
1717
self,
1818
material_ids: str | list[str] | None = None,
1919
formulae: list[str] | None = None,
20-
sort_fields: list[str] | None = None,
2120
num_chunks: int | None = None,
2221
chunk_size: int = 1000,
2322
all_fields: bool = True,
@@ -33,7 +32,6 @@ def search(
3332
Arguments:
3433
material_ids (str, List[str]): Search for alloys containing the specified Material IDs
3534
formulae (List[str]): Search for alloys containing the specified formulae
36-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
3735
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
3836
chunk_size (int): Number of data entries per chunk.
3937
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -56,11 +54,6 @@ def search(
5654

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

59-
if sort_fields:
60-
query_params.update(
61-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
62-
)
63-
6457
return super()._search(
6558
formulae=formulae,
6659
num_chunks=num_chunks,

mp_api/client/routes/materials/bonds.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def search(
3232
max_bond_length: tuple[float, float] | None = None,
3333
mean_bond_length: tuple[float, float] | None = None,
3434
min_bond_length: tuple[float, float] | None = None,
35-
sort_fields: list[str] | None = None,
3635
num_chunks: int | None = None,
3736
chunk_size: int = 1000,
3837
all_fields: bool = True,
@@ -51,7 +50,6 @@ def search(
5150
in the structure to consider.
5251
min_bond_length (Tuple[float,float]): Minimum and maximum value for the minimum bond length
5352
in the structure to consider.
54-
sort_fields (List[str]): Fields used to sort results. Prefixing with '-' will sort in descending order.
5553
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
5654
chunk_size (int): Number of data entries per chunk.
5755
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -101,11 +99,6 @@ def search(
10199
{"coordination_envs_anonymous": ",".join(coordination_envs_anonymous)}
102100
)
103101

104-
if sort_fields:
105-
query_params.update(
106-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
107-
)
108-
109102
query_params = {
110103
entry: query_params[entry]
111104
for entry in query_params

mp_api/client/routes/materials/chemenv.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def search(
4242
num_elements: tuple[int, int] | None = None,
4343
num_sites: tuple[int, int] | None = None,
4444
volume: tuple[float, float] | None = None,
45-
sort_fields: list[str] | None = None,
4645
num_chunks: int | None = None,
4746
chunk_size: int = 1000,
4847
all_fields: bool = True,
@@ -68,7 +67,6 @@ def search(
6867
num_elements (Tuple[int,int]): Minimum and maximum number of elements to consider.
6968
num_sites (Tuple[int,int]): Minimum and maximum number of sites to consider.
7069
volume (Tuple[float,float]): Minimum and maximum volume to consider.
71-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
7270
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
7371
chunk_size (int): Number of data entries per chunk.
7472
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -136,11 +134,6 @@ def search(
136134

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

139-
if sort_fields:
140-
query_params.update(
141-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
142-
)
143-
144137
query_params = {
145138
entry: query_params[entry]
146139
for entry in query_params

mp_api/client/routes/materials/dielectric.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def search(
3131
e_ionic: tuple[float, float] | None = None,
3232
e_electronic: tuple[float, float] | None = None,
3333
n: tuple[float, float] | None = None,
34-
sort_fields: list[str] | None = None,
3534
num_chunks: int | None = None,
3635
chunk_size: int = 1000,
3736
all_fields: bool = True,
@@ -46,7 +45,6 @@ def search(
4645
e_ionic (Tuple[float,float]): Minimum and maximum ionic dielectric constant to consider.
4746
e_electronic (Tuple[float,float]): Minimum and maximum electronic dielectric constant to consider.
4847
n (Tuple[float,float]): Minimum and maximum refractive index to consider.
49-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
5048
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
5149
chunk_size (int): Number of data entries per chunk.
5250
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -81,11 +79,6 @@ def search(
8179
if n:
8280
query_params.update({"n_min": n[0], "n_max": n[1]})
8381

84-
if sort_fields:
85-
query_params.update(
86-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
87-
)
88-
8982
query_params = {
9083
entry: query_params[entry]
9184
for entry in query_params

mp_api/client/routes/materials/elasticity.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def search(
3535
k_reuss: tuple[float, float] | None = None,
3636
k_vrh: tuple[float, float] | None = None,
3737
poisson_ratio: tuple[float, float] | None = None,
38-
sort_fields: list[str] | None = None,
3938
num_chunks: int | None = None,
4039
chunk_size: int = 1000,
4140
all_fields: bool = True,
@@ -62,7 +61,6 @@ def search(
6261
the Voigt-Reuss-Hill average of the bulk modulus.
6362
poisson_ratio (Tuple[float,float]): Minimum and maximum value to consider for
6463
Poisson's ratio.
65-
sort_fields (List[str]): Fields used to sort results. Prefix with '-' to sort in descending order.
6664
num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
6765
chunk_size (int): Number of data entries per chunk.
6866
all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -111,11 +109,6 @@ def search(
111109
{"poisson_min": poisson_ratio[0], "poisson_max": poisson_ratio[1]}
112110
)
113111

114-
if sort_fields:
115-
query_params.update(
116-
{"_sort_fields": ",".join([s.strip() for s in sort_fields])}
117-
)
118-
119112
query_params = {
120113
entry: query_params[entry]
121114
for entry in query_params

0 commit comments

Comments
 (0)