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

Refresh OPTIMADE aliases and update docstrings #3447

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pymatgen/ext/optimade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from pymatgen.util.due import Doi, due
from pymatgen.util.provenance import StructureNL

# from retrying import retry


# TODO: importing optimade-python-tool's data structures will make more sense
Provider = namedtuple("Provider", ["name", "base_url", "description", "homepage", "prefix"])

Expand Down Expand Up @@ -46,7 +43,9 @@ class OptimadeRester:
# these aliases are provided as a convenient shortcut for users of the OptimadeRester class
aliases = {
"aflow": "http://aflow.org/API/optimade/",
"alexandria": "https://alexandria.odbx.science",
"cod": "https://www.crystallography.net/cod/optimade",
"cmr": "https://cmr-optimade.fysik.dtu.dk",
"mcloud.mc3d": "https://aiida.materialscloud.org/mc3d/optimade",
"mcloud.mc2d": "https://aiida.materialscloud.org/mc2d/optimade",
"mcloud.2dtopo": "https://aiida.materialscloud.org/2dtopo/optimade",
Expand All @@ -58,6 +57,7 @@ class OptimadeRester:
"mcloud.tin-antimony-sulfoiodide": "https://aiida.materialscloud.org/tin-antimony-sulfoiodide/optimade",
"mcloud.optimade-sample": "https://aiida.materialscloud.org/optimade-sample/optimade",
"mp": "https://optimade.materialsproject.org",
"mpdd": "http://mpddoptimade.phaseslab.org",
"mpds": "https://api.mpds.io",
"nmd": "https://nomad-lab.eu/prod/rae/optimade/",
"odbx": "https://optimade.odbx.science",
Expand Down Expand Up @@ -154,11 +154,8 @@ def describe(self):
provider_text = "\n".join(map(str, (provider for provider in self._providers.values() if provider)))
return f"OptimadeRester connected to:\n{provider_text}"

# @retry(stop_max_attempt_number=3, wait_random_min=1000, wait_random_max=2000)
def _get_json(self, url):
"""Retrieves JSON, will attempt to (politely) try again on failure subject to a
random delay and a maximum number of attempts.
"""
"""Retrieves and returns JSON resource from given url."""
return self.session.get(url, timeout=self._timeout).json()

@staticmethod
Expand Down Expand Up @@ -215,8 +212,11 @@ def get_structures(
elements: List of elements
nelements: Number of elements, e.g. 4 or [2, 5] for the range >=2 and <=5
nsites: Number of sites, e.g. 4 or [2, 5] for the range >=2 and <=5
chemical_formula_anonymous: Anonymous chemical formula
chemical_formula_hill: Chemical formula following Hill convention
chemical_formula_anonymous: The desired chemical formula in OPTIMADE anonymous formula format
(NB. The ordering is reversed from the pymatgen format, e.g., pymatgen "ABC2" should become "A2BC").
chemical_formula_hill: The desired chemical formula in the OPTIMADE take on the Hill formula format.
(NB. Again, this is different from the pymatgen format, as the OPTIMADE version is a reduced chemical
formula simply using the IUPAC/Hill ordering.)

Returns:
dict[str, Structure]: keyed by that database provider's id system
Expand Down Expand Up @@ -253,8 +253,11 @@ def get_snls(
elements: List of elements
nelements: Number of elements, e.g. 4 or [2, 5] for the range >=2 and <=5
nsites: Number of sites, e.g. 4 or [2, 5] for the range >=2 and <=5
chemical_formula_anonymous: Anonymous chemical formula
chemical_formula_hill: Chemical formula following Hill convention
chemical_formula_anonymous: The desired chemical formula in OPTIMADE anonymous formula format
(NB. The ordering is reversed from the pymatgen format, e.g., pymatgen "ABC2" should become "A2BC").
chemical_formula_hill: The desired chemical formula in the OPTIMADE take on the Hill formula format.
(NB. Again, this is different from the pymatgen format, as the OPTIMADE version is a reduced chemical
formula simply using the IUPAC/Hill ordering.)
additional_response_fields: Any additional fields desired from the OPTIMADE API,
these will be stored under the `'_optimade'` key in each `StructureNL.data` dictionary.

Expand Down