@@ -16,10 +16,11 @@ class AbsorptionRester(BaseRester):
1616 def search (
1717 self ,
1818 material_ids : str | list [str ] | None = None ,
19- chemsys : str | list [str ] | None = None ,
20- elements : list [str ] | None = None ,
21- exclude_elements : list [str ] | None = None ,
22- formula : list [str ] | None = None ,
19+ num_sites : int | tuple [int , int ] | None = None ,
20+ num_elements : int | tuple [int , int ] | None = None ,
21+ volume : float | tuple [float , float ] | None = None ,
22+ density : float | tuple [float , float ] | None = None ,
23+ band_gap : float | tuple [float , float ] | None = None ,
2324 num_chunks : int | None = None ,
2425 chunk_size : int = 1000 ,
2526 all_fields : bool = True ,
@@ -28,14 +29,26 @@ def search(
2829 """Query for optical absorption spectra data.
2930
3031 Arguments:
31- material_ids (str, List[str]): Search for optical absorption data associated with the specified Material IDs
32- chemsys (str, List[str]): A chemical system or list of chemical systems
33- (e.g., Li-Fe-O, Si-*, [Si-O, Li-Fe-P]).
34- elements (List[str]): A list of elements.
35- exclude_elements (List[str]): A list of elements to exclude.
36- formula (str, List[str]): A formula including anonymized formula
37- or wild cards (e.g., Fe2O3, ABO3, Si*). A list of chemical formulas can also be passed
38- (e.g., [Fe2O3, ABO3]).
32+ material_ids (str, List[str]):
33+ Search for optical absorption data associated with the
34+ specified Material ID(s)
35+ num_sites (int, tuple[int, int]):
36+ Search with a single number or a range of number of sites
37+ in the structure.
38+ num_elements (int, tuple[int, int]):
39+ Search with a single number or a range of number of distinct
40+ elements in the structure.
41+ volume (float, tuple[float, float]):
42+ Search with a single number or a range of structural
43+ (lattice) volumes in ų.
44+ If a single number, an uncertainty of ±0.01 is automatically used.
45+ density (float, tuple[float, float]):
46+ Search with a single number or a range of structural
47+ (lattice) densities, in g/cm³.
48+ If a single number, an uncertainty of ±0.01 is automatically used.
49+ band_gap (float, tuple[float, float]):
50+ Search with a single number or a range of band gaps in eV.
51+ If a single number, an uncertainty of ±0.01 is automatically used.
3952 num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
4053 chunk_size (int): Number of data entries per chunk.
4154 all_fields (bool): Whether to return all fields in the document. Defaults to True.
@@ -46,23 +59,27 @@ def search(
4659 """
4760 query_params = defaultdict (dict ) # type: dict
4861
49- if formula :
50- if isinstance (formula , str ):
51- formula = [formula ]
52-
53- query_params .update ({"formula" : "," .join (formula )})
54-
55- if chemsys :
56- if isinstance (chemsys , str ):
57- chemsys = [chemsys ]
58-
59- query_params .update ({"chemsys" : "," .join (chemsys )})
60-
61- if elements :
62- query_params .update ({"elements" : "," .join (elements )})
63-
64- if exclude_elements :
65- query_params .update ({"exclude_elements" : "," .join (exclude_elements )})
62+ aliased = {
63+ "num_sites" : "nsites" ,
64+ "num_elements" : "nelements" ,
65+ "band_gap" : "bandgap" ,
66+ }
67+ user_query = locals ()
68+ for k in ("num_sites" , "num_elements" , "volume" , "density" , "band_gap" ):
69+ if (value := user_query .get (k )) is not None :
70+ if k in ("num_sites" , "num_elements" ) and isinstance (value , int ):
71+ value = (value , value )
72+ elif k in ("volume" , "density" , "band_gap" ) and isinstance (
73+ value , int | float
74+ ):
75+ value = (value - 1e-2 , value + 1e-2 )
76+
77+ query_params .update (
78+ {
79+ f"{ aliased .get (k ,k )} _min" : value [0 ],
80+ f"{ aliased .get (k ,k )} _max" : value [1 ],
81+ }
82+ )
6683
6784 if material_ids :
6885 if isinstance (material_ids , str ):
@@ -77,7 +94,6 @@ def search(
7794 }
7895
7996 return super ()._search (
80- formulae = formula ,
8197 num_chunks = num_chunks ,
8298 chunk_size = chunk_size ,
8399 all_fields = all_fields ,
0 commit comments