|
52 | 52 | "mp_api.client.routes.materials.materials.MaterialsRester" |
53 | 53 | ), |
54 | 54 | **{f"materials/{k}": v for k, v in MATERIALS_RESTERS.items() if k not in {"doi"}}, |
55 | | - "doi": MATERIALS_RESTERS["doi"], |
56 | 55 | **{f"molecules/{k}": v for k, v in MOLECULES_RESTERS.items()}, |
| 56 | +} |
| 57 | +GENERIC_RESTERS = { |
| 58 | + "doi": MATERIALS_RESTERS["doi"], |
57 | 59 | **GENERIC_RESTERS, |
58 | 60 | } |
59 | 61 |
|
| 62 | +TOP_LEVEL_RESTERS = [ |
| 63 | + "molecules/core", |
| 64 | + "materials/core", |
| 65 | + "_general_store", |
| 66 | + "_messages", |
| 67 | + "_user_settings", |
| 68 | + "doi", |
| 69 | +] |
| 70 | + |
60 | 71 |
|
61 | 72 | class MPRester: |
62 | 73 | """Access the new Materials Project API.""" |
@@ -179,27 +190,23 @@ def __init__( |
179 | 190 | # Nested rested are then setup to be loaded dynamically with custom __getattr__ functions. |
180 | 191 | self._all_resters = list(RESTER_LAYOUT.values()) |
181 | 192 |
|
182 | | - # Instantiate top level molecules and materials resters and set them as attributes |
183 | | - core_suffix = ["molecules/core", "materials/core"] |
184 | | - |
185 | | - core_resters = { |
186 | | - rest_name.split("/")[0]: lazy_rester( |
187 | | - api_key=self.api_key, |
188 | | - endpoint=self.endpoint, |
189 | | - include_user_agent=self._include_user_agent, |
190 | | - session=self.session, |
191 | | - use_document_model=self.use_document_model, |
192 | | - headers=self.headers, |
193 | | - mute_progress_bars=self.mute_progress_bars, |
194 | | - ) |
195 | | - for rest_name, lazy_rester in RESTER_LAYOUT.items() |
196 | | - if rest_name in core_suffix |
197 | | - } |
198 | | - |
199 | | - # Set remaining top level resters, or get an attribute-class name mapping |
200 | | - |
201 | | - for attr, rester in core_resters.items(): |
202 | | - setattr(self, attr, rester) |
| 193 | + # Instantiate top level core molecules, materials, and DOI resters, as well |
| 194 | + # as the sunder resters to allow the web server to work. |
| 195 | + for rest_name, lazy_rester in (RESTER_LAYOUT | GENERIC_RESTERS).items(): |
| 196 | + if rest_name in TOP_LEVEL_RESTERS: |
| 197 | + setattr( |
| 198 | + self, |
| 199 | + rest_name.split("/")[0], |
| 200 | + lazy_rester( |
| 201 | + api_key=self.api_key, |
| 202 | + endpoint=self.endpoint, |
| 203 | + include_user_agent=self._include_user_agent, |
| 204 | + session=self.session, |
| 205 | + use_document_model=self.use_document_model, |
| 206 | + headers=self.headers, |
| 207 | + mute_progress_bars=self.mute_progress_bars, |
| 208 | + ), |
| 209 | + ) |
203 | 210 |
|
204 | 211 | @property |
205 | 212 | def contribs(self): |
@@ -249,7 +256,11 @@ def __getattr__(self, attr): |
249 | 256 | ) |
250 | 257 |
|
251 | 258 | def __dir__(self): |
252 | | - return dir(MPRester) + self._deprecated_attributes + ["materials", "molecules"] |
| 259 | + return ( |
| 260 | + dir(MPRester) |
| 261 | + + self._deprecated_attributes |
| 262 | + + [r.split("/", 1)[0] for r in TOP_LEVEL_RESTERS if not r.startswith("_")] |
| 263 | + ) |
253 | 264 |
|
254 | 265 | def get_task_ids_associated_with_material_id( |
255 | 266 | self, material_id: str, calc_types: list[CalcType] | None = None |
|
0 commit comments