materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.48k stars 850 forks source link

OPTIMADE Rester cannot find structures #2313

Open oarcelus opened 2 years ago

oarcelus commented 2 years ago

I am trying to use the OPTIMADE Rester. But when running the following lines

`from pymatgen.ext.optimade import OptimadeRester

opt = OptimadeRester('mp')

data = opt.get_structures(elements=['Li','Mn','O'], nelements=[1,3])`

I get the following error messages

Failed to extract required information from https://optimade.materialsproject.org\v1/info: 'meta' Could not retrieve required information from provider mp and url https://optimade.materialsproject.org\v1/structures?filter=(elements HAS ALL "Li", "Mn", "O") AND (nelements>=1 AND nelements<=3)&response_fields=lattice_vectors,cartesian_site_positions,species,species_at_sites: 'data' {}

Process finished with exit code 0

Searching for this same URL's, both for the 'info' and 'structures' endpoints I get the expected responses, so I assume this is a bug of some kind. Is this the case?

JPBergsma commented 2 years ago

I just tried the query you specified and for me it works. I ran it from the binder page of the Optimade tutorial. The pymatgen version I used is 2022.0.16

Perhaps there was a problem with the internet connexion to the server, or there was another reason the server could not respond at the time. Could you retry the query to see if the issue is still there?

oarcelus commented 2 years ago

The only way I made it work was to use string operations to build the url's instead of the join function.

url = resource + f"/v1/structures?filter={optimade_filter}&{fields}"
#url = join(resource, f"v1/structures?filter={optimade_filter}&{fields}")

And

#url = join(provider_url, "v1/info")
url = provider_url + "/v1/info"

This builds strings like 'https://optimade.materialsproject.org/v1/info' instead of 'https://optimade.materialsproject.org\v1/info'

mkhorton commented 2 years ago

Thanks for reporting this @oarcelus and following up @JPBergsma.

I can't replicate the issue with the example on my local laptop (macOS), so I suspect it may be a platform-dependent issue related to the behaviour of join?

mkhorton commented 2 years ago

Perhaps urljoin is the better function to call.

oarcelus commented 2 years ago

Thanks for the inputs @mkhorton, indeed urljoin solves the problem in my case.

For the record, I am using Python 3.9 in Windows 10, and executing the string from PyCharm Community Edition 2021.2.2.