11from __future__ import annotations
22
3+ import warnings
34from typing import TYPE_CHECKING
45
56from emmet .core .xas import XASDoc , validate_xas_spectrum_id
67from pymatgen .core .periodic_table import Element
78
8- from mp_api .client .core import BaseRester
9+ from mp_api .client .core import BaseRester , MPRestWarning
910from mp_api .client .core .exceptions import MPRestError
1011
1112if TYPE_CHECKING :
1718class XASRester (BaseRester ):
1819 suffix = "materials/xas"
1920 document_model = XASDoc # type: ignore
20- primary_key = "material_id "
21+ primary_key = "task_id "
2122 delta_backed = False
2223
2324 def search (
@@ -27,7 +28,7 @@ def search(
2728 formula : str | None = None ,
2829 chemsys : str | list [str ] | None = None ,
2930 elements : list [str ] | None = None ,
30- material_ids : list [str ] | None = None ,
31+ task_ids : list [str ] | None = None ,
3132 spectrum_type : XasType | None = None ,
3233 spectrum_ids : str | list [str ] | None = None ,
3334 num_chunks : int | None = None ,
@@ -36,6 +37,7 @@ def search(
3637 fields : list [str ] | None = None ,
3738 _page : int | None = None ,
3839 _sort_fields : str | None = None ,
40+ ** kwargs ,
3941 ):
4042 """Query core XAS docs using a variety of search criteria.
4143
@@ -47,7 +49,7 @@ def search(
4749 chemsys (str, List[str]): A chemical system or list of chemical systems
4850 (e.g., Li-Fe-O, Si-*, [Si-O, Li-Fe-P]).
4951 elements (List[str]): A list of elements.
50- material_ids (str, List[str]): A single Material ID string or list of strings
52+ task_ids (str, List[str]): A single Task ID string or list of strings
5153 (e.g., mp-149, [mp-149, mp-13]).
5254 spectrum_type (XasType): Spectrum type (e.g. EXAFS, XAFS, or XANES).
5355 spectrum_ids (str, List[str]): A single Spectrum ID string or list of strings
@@ -59,10 +61,26 @@ def search(
5961 Default is material_id, last_updated, and formula_pretty if all_fields is False.
6062 _page (int or None) : Page of the results to skip to.
6163 _sort_fields (str or None) : Field to sort on. Including a leading "-" sign will reverse sort order.
64+ **kwargs : used for handling deprecated kwargs
6265
6366 Returns:
6467 ([MaterialsDoc]) List of material documents
6568 """
69+ if "material_ids" in kwargs :
70+ if task_ids :
71+ raise MPRestError (
72+ "You have specified both `task_ids` and the deprecated `material_ids` tag. "
73+ "Please specify only `task_ids`."
74+ )
75+ task_ids = kwargs .pop ("material_ids" )
76+ warnings .warn (
77+ "`material_id` has been replaced by `task_id` in the xas endpoint. "
78+ "Please migrate to using the newer field name and the `task_ids` kwarg "
79+ "for searching." ,
80+ stacklevel = 2 ,
81+ category = MPRestWarning ,
82+ )
83+
6684 _locals = locals ()
6785 query_params : dict [str , Any ] = {
6886 k : _locals [k ]
@@ -80,7 +98,7 @@ def search(
8098 )
8199 }
82100 )
83- for k in ("chemsys" , "elements" , "material_ids " , "spectrum_ids" ):
101+ for k in ("chemsys" , "elements" , "task_ids " , "spectrum_ids" ):
84102 if (v := _locals .get (k )) is not None :
85103 _v = [v ] if isinstance (v , str ) else v
86104 if k == "spectrum_ids" :
0 commit comments