Skip to content

Commit

Permalink
allow strings for has_props (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume authored Aug 19, 2024
1 parent 8197ba3 commit 56bf699
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions mp_api/client/routes/materials/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from emmet.core.symmetry import CrystalSystem
from pymatgen.analysis.magnetism import Ordering

from mp_api.client.core import BaseRester
from mp_api.client.core import BaseRester, MPRestError
from mp_api.client.core.utils import validate_ids


Expand Down Expand Up @@ -36,7 +36,7 @@ def search(
g_reuss: tuple[float, float] | None = None,
g_voigt: tuple[float, float] | None = None,
g_vrh: tuple[float, float] | None = None,
has_props: list[HasProps] | None = None,
has_props: list[HasProps] | list[str] | None = None,
has_reconstructed: bool | None = None,
is_gap_direct: bool | None = None,
is_metal: bool | None = None,
Expand Down Expand Up @@ -101,7 +101,7 @@ def search(
of the shear modulus.
g_vrh (Tuple[float,float]): Minimum and maximum value in GPa to consider for the Voigt-Reuss-Hill
average of the shear modulus.
has_props: (List[HasProps]): The calculated properties available for the material.
has_props: (List[HasProps], List[str]): The calculated properties available for the material.
has_reconstructed (bool): Whether the entry has any reconstructed surfaces.
is_gap_direct (bool): Whether the material has a direct band gap.
is_metal (bool): Whether the material is considered a metal.
Expand Down Expand Up @@ -253,7 +253,14 @@ def search(
query_params.update({"has_reconstructed": has_reconstructed})

if has_props:
query_params.update({"has_props": ",".join([i.value for i in has_props])})
has_props_clean = []
for prop in has_props:
try:
has_props_clean.append(HasProps(prop).value)
except ValueError:
raise MPRestError(f"'{prop}' is not a valid property.")

query_params.update({"has_props": ",".join(has_props_clean)})

if theoretical is not None:
query_params.update({"theoretical": theoretical})
Expand Down

0 comments on commit 56bf699

Please sign in to comment.