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

MPRester #18

Open
AugustinLu opened this issue Nov 20, 2024 · 4 comments
Open

MPRester #18

AugustinLu opened this issue Nov 20, 2024 · 4 comments

Comments

@AugustinLu
Copy link

Hello,

I am currently learning how to use Vise by following the tutorial at https://kumagai-group.github.io/vise/.

It seems that the MPRester module has changed location in recent pymatgen versions, leading to an error.

vise gp -m mp-2857


  File "[...]/lib/python3.10/site-packages/vise/cli/main_functions.py", line 9, in <module>
    from mp_api.client import MPRester
ModuleNotFoundError: No module named 'mp_api'

This output is from pytmatgen 2024.11.13.

Replacing this import statement by from pymatgen.ext.matproj import MPRester may partially solve this error. However, simply replacing it yields another error:

   INFO: -- Settings from vise.yaml:
   INFO: 
Traceback (most recent call last):
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/pymatgen/ext/matproj.py", line 131, in request
    all_data.extend(data["data"])
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "[...]/anaconda3/envs/vise/bin/vise", line 8, in <module>
    sys.exit(main())
  File "[...]/anaconda3/envs/vise/lib/python3.10/site-packages/vise/cli/main.py", line 316, in main
    args.func(args)
  File "[...]/anaconda3/envs/vise/lib/python3.10/site-packages/vise/cli/main_functions.py", line 124, in get_poscar_from_mp
    query = MPRester().summary.search(material_ids=[args.mpid],
  File "[...]/anaconda3/envs/vise/lib/python3.10/site-packages/pymatgen/ext/matproj.py", line 157, in summary_search
    return self.request(f"materials/summary/?{get}", payload=criteria)
  File "[...]/anaconda3/envs/vise/lib/python3.10/site-packages/pymatgen/ext/matproj.py", line 137, in request
    raise MPRestError(msg)
pymatgen.ext.matproj.MPRestError: 'data'. Content: b'{"detail":"Request contains query parameters which cannot be used: fields"}'

This may be a very basic question, although I could not figure out how to proceed further so far.
I would appreciate if someone could tell me how to solve this issue.

Thank you very much.

@yuuukuma
Copy link
Collaborator

Hi,

We might need to make corrections to adapt the revised mpi of pymatgen.
Please wait for a while.

@yuuukuma
Copy link
Collaborator

yuuukuma commented Nov 22, 2024

I don't have the same error.

Could you please install mp-api with the following command, which would solve the first issue?
pip install mp-api

@AugustinLu
Copy link
Author

Thank you for your reply.

I have install mp-api via pip install mp-api. While the original error has disappeared, another one occured.
Is there any limitation on the version mp-api compatible with vise?

vise gp -m mp-2857
   INFO: -- Settings from vise.yaml:
   INFO: 
Traceback (most recent call last):
  File "/home/augustin/anaconda3/envs/vise/bin/vise", line 8, in <module>
    sys.exit(main())
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/vise/cli/main.py", line 316, in main
    args.func(args)
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/vise/cli/main_functions.py", line 122, in get_poscar_from_mp
    s = MPRester().get_structure_by_material_id(args.mpid)
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/mprester.py", line 464, in get_structure_by_material_id
    structure_data = self.materials.get_structure_by_material_id(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/routes/materials/materials.py", line 124, in get_structure_by_material_id
    response = self.search(material_ids=material_id, fields=[field])
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/routes/materials/materials.py", line 245, in search
    return super()._search(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 1185, in _search
    return self._get_all_documents(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 1258, in _get_all_documents
    results = self._query_resource(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 569, in _query_resource
    data = self._submit_requests(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 716, in _submit_requests
    initial_data_tuples = self._multi_thread(
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 938, in _multi_thread
    data, subtotal = future.result()
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 1010, in _submit_request_and_process
    data["data"] = self._convert_to_model(data["data"])
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 1049, in _convert_to_model
    data_model, set_fields, _ = self._generate_returned_model(raw_doc_list[0])
  File "/home/augustin/anaconda3/envs/vise/lib/python3.10/site-packages/mp_api/client/core/client.py", line 1075, in _generate_returned_model
    data_model.model_fields = {
AttributeError: can't set attribute 'model_fields'

@yuuukuma
Copy link
Collaborator

yuuukuma commented Nov 22, 2024

Before testing, I upgraded pymatgen and mp-api.

If the following script doesn't work, the issue is not related to vise.
You should ask the developer of mp-api.

from mp_api.client import MPRester

structure = MPRester().get_structure_by_material_id("mp-2857")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants