Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: MPRester(use_docment_model=False).get_prop_by_material_id() does not work when use_document_model=False (prop = ['bandstructure', 'dos']) #923

Open
1 of 3 tasks
AntObi opened this issue Jul 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AntObi
Copy link

AntObi commented Jul 25, 2024

Code snippet

from mp_api.client import MPRester
with MPRester(use_document_model=False) as mpr:
    bs = mpr.get_bandstructure_by_material_id("mp-23")

What happened?

I am attempting to get the bandstructure of a material using the convenience method get_bandstructure_by_material_id. When I pass use_document_model=False, I get the following error: TypeError: 'MPDataDoc' object is not subscriptable

When I run the same search but with use_document_model=True, the bandstructure is returned with no errors.

This issue is also present with other properties:

  • get_dos_by_material_id
  • get_bandstructure_by_material_id

I have no issues when trying to obtain phonon properties through either get_phonon_dos_by_material_id or get_phonon_bandstructure_by_material_id, which may mean the issue is related to the electronic_structure route.

Version

0.41.2

Which OS?

  • MacOS
  • Windows
  • Linux

Log output

{
	"name": "TypeError",
	"message": "'MPDataDoc' object is not subscriptable",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[51], line 2
      1 with MPRester(use_document_model=False) as mpr:
----> 2     bsdoc = mpr.get_bandstructure_by_material_id(\"mp-23\")

File ~/miniforge3/envs/smact_dev/lib/python3.10/site-packages/mp_api/client/mprester.py:1233, in MPRester.get_bandstructure_by_material_id(self, material_id, path_type, line_mode)
   1217 def get_bandstructure_by_material_id(
   1218     self,
   1219     material_id: str,
   1220     path_type: BSPathType = BSPathType.setyawan_curtarolo,
   1221     line_mode=True,
   1222 ):
   1223     \"\"\"Get the band structure pymatgen object associated with a Materials Project ID.
   1224 
   1225     Arguments:
   (...)
   1231         bandstructure (Union[BandStructure, BandStructureSymmLine]): BandStructure or BandStructureSymmLine object
   1232     \"\"\"
-> 1233     return self.electronic_structure_bandstructure.get_bandstructure_from_material_id(  # type: ignore
   1234         material_id=material_id, path_type=path_type, line_mode=line_mode
   1235     )

File ~/miniforge3/envs/smact_dev/lib/python3.10/site-packages/mp_api/client/routes/materials/electronic_structure.py:280, in BandStructureRester.get_bandstructure_from_material_id(self, material_id, path_type, line_mode)
    274 if not bs_doc:
    275     raise MPRestError(\"No electronic structure data found.\")
    277 bs_data = (
    278     bs_doc[0].bandstructure  # type: ignore
    279     if self.use_document_model
--> 280     else bs_doc[0][\"bandstructure\"]  # type: ignore
    281 )
    283 if bs_data is None:
    284     raise MPRestError(
    285         f\"No {path_type.value} band structure data found for {material_id}\"
    286     )

TypeError: 'MPDataDoc' object is not subscriptable"
}
@AntObi AntObi added the bug Something isn't working label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant