From bac5b280ec83c480bc746a8626b1f4b11d2f6cda Mon Sep 17 00:00:00 2001 From: Jason Munro Date: Mon, 29 Nov 2021 10:03:24 -0800 Subject: [PATCH] Convert to using HasProps enum for summary client (#445) * Convert to using HasProps enum for summary client * Emmet bump * Fix mprester has_props test --- requirements.txt | 2 +- src/mp_api/client.py | 5 +++-- src/mp_api/routes/summary/client.py | 8 ++++---- tests/test_mprester.py | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1f32ecfe..9ddcf468 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,6 @@ typing-extensions==4.0.0 maggma==0.32.2 requests==2.26.0 monty==2021.8.17 -emmet-core==0.17.0 +emmet-core==0.18.0 ratelimit==2.2.1 mpcontribs-client>=3.14.3 diff --git a/src/mp_api/client.py b/src/mp_api/client.py index b47dd50d..38d3822d 100644 --- a/src/mp_api/client.py +++ b/src/mp_api/client.py @@ -9,6 +9,7 @@ from emmet.core.settings import EmmetSettings from emmet.core.symmetry import CrystalSystem from emmet.core.vasp.calc_types import CalcType +from emmet.core.summary import HasProps from mpcontribs.client import Client from pymatgen.analysis.magnetism import Ordering from pymatgen.analysis.phase_diagram import PhaseDiagram @@ -845,7 +846,7 @@ def query( surface_energy_anisotropy: Optional[Tuple[float, float]] = None, shape_factor: Optional[Tuple[float, float]] = None, has_reconstructed: Optional[bool] = None, - has_props: Optional[List[str]] = None, + has_props: Optional[List[HasProps]] = None, theoretical: Optional[bool] = None, sort_fields: Optional[List[str]] = None, num_chunks: Optional[int] = None, @@ -918,7 +919,7 @@ def query( consider. shape_factor (Tuple[float,float]): Minimum and maximum shape factor values to consider. has_reconstructed (bool): Whether the entry has any reconstructed surfaces. - has_props: (List[str]): The calculated properties available for the material. + has_props: (List[HasProps]): The calculated properties available for the material. theoretical: (bool): Whether the material is theoretical. sort_fields (List[str]): Fields used to sort results. Prefixing with '-' will sort in descending order. num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible. diff --git a/src/mp_api/routes/summary/client.py b/src/mp_api/routes/summary/client.py index c613712b..1fad2d9b 100644 --- a/src/mp_api/routes/summary/client.py +++ b/src/mp_api/routes/summary/client.py @@ -2,7 +2,7 @@ from typing import List, Optional, Tuple from emmet.core.mpid import MPID -from emmet.core.summary import SummaryDoc +from emmet.core.summary import SummaryDoc, HasProps from emmet.core.symmetry import CrystalSystem from mp_api.core.client import BaseRester from pymatgen.analysis.magnetism import Ordering @@ -63,7 +63,7 @@ def search_summary_docs( surface_energy_anisotropy: Optional[Tuple[float, float]] = None, shape_factor: Optional[Tuple[float, float]] = None, has_reconstructed: Optional[bool] = None, - has_props: Optional[List[str]] = None, + has_props: Optional[List[HasProps]] = None, theoretical: Optional[bool] = None, sort_fields: Optional[List[str]] = None, num_chunks: Optional[int] = None, @@ -136,7 +136,7 @@ def search_summary_docs( consider. shape_factor (Tuple[float,float]): Minimum and maximum shape factor values to consider. has_reconstructed (bool): Whether the entry has any reconstructed surfaces. - has_props: (List[str]): The calculated properties available for the material. + has_props: (List[HasProps]): The calculated properties available for the material. theoretical: (bool): Whether the material is theoretical. sort_fields (List[str]): Fields used to sort results. Prefixing with '-' will sort in descending order. num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible. @@ -234,7 +234,7 @@ def search_summary_docs( query_params.update({"has_reconstructed": has_reconstructed}) if has_props: - query_params.update({"has_props": ",".join(has_props)}) + query_params.update({"has_props": ",".join([i.value for i in has_props])}) if theoretical is not None: query_params.update({"theoretical": theoretical}) diff --git a/tests/test_mprester.py b/tests/test_mprester.py index 974dffc4..68e92f70 100644 --- a/tests/test_mprester.py +++ b/tests/test_mprester.py @@ -5,6 +5,7 @@ import pytest from emmet.core.symmetry import CrystalSystem from emmet.core.vasp.calc_types import CalcType +from emmet.core.summary import HasProps from mp_api.core.settings import MAPISettings from mp_api.matproj import MPRester from mp_api.routes.tasks.models import TaskDoc @@ -263,7 +264,7 @@ def test_query(self, mpr): "crystal_system": CrystalSystem.cubic, "spacegroup_number": 38, "spacegroup_symbol": "Amm2", - "has_props": ["dielectric"], + "has_props": [HasProps.dielectric], "theoretical": True, "has_reconstructed": False, "magnetic_ordering": Ordering.FM,