@@ -89,8 +89,8 @@ def search(
8989 missing : list [str ] = []
9090 found_material_ids : set [str ] = set ()
9191 for doc in summary_docs :
92- mid = str (doc ["material_id" ])
93- phonon_ids_by_method = doc .get ("phonon_IDs" ) or {}
92+ mid = str (doc ["material_id" ]) # type: ignore[arg-type, index]
93+ phonon_ids_by_method = doc .get ("phonon_IDs" ) or {} # type: ignore[union-attr]
9494
9595 if phonon_method :
9696 method_ids = phonon_ids_by_method .get (phonon_method ) or []
@@ -215,13 +215,13 @@ def get_bandstructure_from_material_id(
215215 f"No phonon bandstructure data found for material ID { material_id } ."
216216 )
217217
218- if phonon_method not in summary_doc [0 ]["phonon_IDs" ]:
218+ if phonon_method not in summary_doc [0 ]["phonon_IDs" ]: # type: ignore[arg-type, index]
219219 raise MPRestError (
220220 f"No phonon bandstructure data found for material ID: { material_id } and phonon method: { phonon_method } ."
221221 )
222222
223223 return self .get_bandstructure_from_phonon_id (
224- summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method , pt
224+ summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method , pt # type: ignore[arg-type, index]
225225 )
226226
227227 def get_dos_from_phonon_id (
@@ -280,13 +280,13 @@ def get_dos_from_material_id(
280280 f"No phonon dos data found for material ID { material_id } ."
281281 )
282282
283- if phonon_method not in summary_doc [0 ]["phonon_IDs" ]:
283+ if phonon_method not in summary_doc [0 ]["phonon_IDs" ]: # type: ignore[arg-type, index]
284284 raise MPRestError (
285285 f"No phonon dos data found for material ID: { material_id } and phonon method: { phonon_method } ."
286286 )
287287
288288 return self .get_dos_from_phonon_id (
289- summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method
289+ summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method # type: ignore[arg-type, index]
290290 )
291291
292292 def get_forceconstants_from_phonon_id (
@@ -344,20 +344,20 @@ def get_forceconstants_from_material_id(
344344 f"No phonon force constants data found for material ID { material_id } ."
345345 )
346346
347- if phonon_method not in summary_doc [0 ]["phonon_IDs" ]:
347+ if phonon_method not in summary_doc [0 ]["phonon_IDs" ]: # type: ignore[arg-type, index]
348348 raise MPRestError (
349349 f"No phonon force constants data found for material ID: { material_id } and phonon method: { phonon_method } ."
350350 )
351351
352352 return self .get_forceconstants_from_phonon_id (
353- summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method
353+ summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ], phonon_method # type: ignore[arg-type, index]
354354 )
355355
356356 def compute_thermo_quantities (
357357 self ,
358- identifier : str | None = None ,
359358 material_id : str | None = None ,
360359 phonon_method : str | None = None ,
360+ identifier : str | None = None ,
361361 ):
362362 """Compute thermodynamical quantities for a given phonon ID or material ID and phonon_method.
363363
@@ -392,12 +392,21 @@ def compute_thermo_quantities(
392392 raise MPRestError (
393393 f"No phonon data found for material ID { material_id } ."
394394 )
395- if phonon_method not in summary_doc [0 ]["phonon_IDs" ]:
395+ if phonon_method not in summary_doc [0 ]["phonon_IDs" ]: # type: ignore[arg-type, index]
396396 raise MPRestError (
397397 f"No phonon data found for material ID: { material_id } and "
398398 f"phonon method: { phonon_method } ."
399399 )
400- identifier = summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ]
400+ identifier = summary_doc [0 ]["phonon_IDs" ][phonon_method ][0 ] # type: ignore[arg-type, index]
401+
402+ if identifier is None or phonon_method is None :
403+ suffix = (
404+ f" for { material_id = } " if material_id else f" for { identifier = } "
405+ )
406+ raise MPRestError (
407+ f"Could not resolve a phonon identifier or method{ suffix } "
408+ f"({ phonon_method = } )."
409+ )
401410
402411 ph_dos = self .get_dos_from_phonon_id (identifier , phonon_method )
403412 docs = self .search (identifiers = identifier , phonon_method = phonon_method )
@@ -406,7 +415,7 @@ def compute_thermo_quantities(
406415
407416 self .use_document_model = True
408417 docs [0 ]["phonon_dos" ] = ph_dos # type: ignore[index]
409- doc = PhononBSDOSDoc (** docs [0 ]) # type: ignore[arg-type]
418+ doc = PhononBSDOSDoc (** docs [0 ]) # type: ignore[arg-type, index ]
410419 finally :
411420 self .use_document_model = use_document_model
412421 # below: same as numpy.linspace(0,800,100) but written out for mypy
0 commit comments