diff --git a/app.py b/app.py index d1003154..fceb7780 100644 --- a/app.py +++ b/app.py @@ -183,7 +183,7 @@ robo_store = MongoURIStore( uri=f"mongodb+srv://{db_uri}", database="mp_core", - key="task_id", + key="material_id", collection_name="robocrys", ) diff --git a/requirements.txt b/requirements.txt index 2a63a7db..f27a3ab2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ typing-extensions==3.10.0.2 maggma==0.31.0 requests==2.26.0 monty==2021.8.17 -emmet-core==0.12.8 +emmet-core==0.13.3 ratelimit==2.2.1 diff --git a/src/mp_api/matproj.py b/src/mp_api/matproj.py index fbcd835e..ae890784 100644 --- a/src/mp_api/matproj.py +++ b/src/mp_api/matproj.py @@ -471,6 +471,7 @@ def query( material_ids: Optional[List[MPID]] = None, chemsys_formula: Optional[str] = None, exclude_elements: Optional[List[str]] = None, + possible_species: Optional[List[str]] = None, nsites: Optional[Tuple[int, int]] = None, volume: Optional[Tuple[float, float]] = None, density: Optional[Tuple[float, float]] = None, @@ -481,7 +482,7 @@ def query( total_energy: Optional[Tuple[float, float]] = None, formation_energy: Optional[Tuple[float, float]] = None, energy_above_hull: Optional[Tuple[float, float]] = None, - equillibrium_reaction_energy: Optional[Tuple[float, float]] = None, + equilibrium_reaction_energy: Optional[Tuple[float, float]] = None, uncorrected_energy: Optional[Tuple[float, float]] = None, is_stable: Optional[bool] = None, band_gap: Optional[Tuple[float, float]] = None, @@ -532,6 +533,8 @@ def query( or formula including anonomyzed formula or wild cards (e.g., Fe2O3, ABO3, Si*). exclude_elements (List(str)): List of elements to exclude. + possible_species (List(str)): List of element symbols appended with oxidation states. + (e.g. Cr2+,O2-) crystal_system (CrystalSystem): Crystal system of material. spacegroup_number (int): Space group number of material. spacegroup_symbol (str): Space group symbol of the material in international short symbol notation. @@ -540,6 +543,8 @@ def query( density (Tuple[float,float]): Minimum and maximum density to consider. deprecated (bool): Whether the material is tagged as deprecated. total_energy (Tuple[int,int]): Minimum and maximum corrected total energy in eV/atom to consider. + equilibrium_reaction_energy (Tuple[float,float]): Minimum and maximum equilibrium reaction energy + in eV/atom to consider. formation_energy (Tuple[int,int]): Minimum and maximum formation energy in eV/atom to consider. energy_above_hull (Tuple[int,int]): Minimum and maximum energy above the hull in eV/atom to consider. uncorrected_energy (Tuple[int,int]): Minimum and maximum uncorrected total energy in eV/atom to consider. @@ -602,6 +607,7 @@ def query( material_ids=material_ids, chemsys_formula=chemsys_formula, exclude_elements=exclude_elements, + possible_species=possible_species, nsites=nsites, volume=volume, density=density, @@ -612,7 +618,7 @@ def query( total_energy=total_energy, formation_energy=formation_energy, energy_above_hull=energy_above_hull, - equillibrium_reaction_energy=equillibrium_reaction_energy, + equilibrium_reaction_energy=equilibrium_reaction_energy, uncorrected_energy=uncorrected_energy, is_stable=is_stable, band_gap=band_gap, diff --git a/src/mp_api/routes/oxidation_states/resources.py b/src/mp_api/routes/oxidation_states/resources.py index cc11f858..dea27db8 100644 --- a/src/mp_api/routes/oxidation_states/resources.py +++ b/src/mp_api/routes/oxidation_states/resources.py @@ -5,7 +5,6 @@ PaginationQuery, SortQuery, SparseFieldsQuery, - NumericQuery, ) from mp_api.routes.materials.query_operators import FormulaQuery diff --git a/src/mp_api/routes/robocrys/client.py b/src/mp_api/routes/robocrys/client.py index b7dca7be..5ccbd05f 100644 --- a/src/mp_api/routes/robocrys/client.py +++ b/src/mp_api/routes/robocrys/client.py @@ -8,7 +8,7 @@ class RobocrysRester(BaseRester): suffix = "robocrys" document_model = RobocrysDoc # type: ignore - primary_key = "task_id" + primary_key = "material_id" def search_robocrys_text(self, keywords: List[str]): """ diff --git a/src/mp_api/routes/robocrys/models.py b/src/mp_api/routes/robocrys/models.py index bce77d82..a5c646f4 100644 --- a/src/mp_api/routes/robocrys/models.py +++ b/src/mp_api/routes/robocrys/models.py @@ -10,8 +10,7 @@ class MineralData(BaseModel): """ type: str = Field( - None, - description="Mineral type.", + None, description="Mineral type.", ) @@ -21,28 +20,23 @@ class CondensedStructureData(BaseModel): """ formula: str = Field( - None, - description="Formula for the material.", + None, description="Formula for the material.", ) spg_symbol: str = Field( - None, - description="Space group symbol of the material.", + None, description="Space group symbol of the material.", ) crystal_system: str = Field( - None, - description="Crystal system of the material.", + None, description="Crystal system of the material.", ) mineral: MineralData = Field( - None, - description="Matched mineral data for the material.", + None, description="Matched mineral data for the material.", ) dimensionality: int = Field( - None, - description="Dimensionality of the material.", + None, description="Dimensionality of the material.", ) @@ -52,23 +46,20 @@ class RobocrysDoc(BaseModel): """ description: str = Field( - None, - description="Decription text from robocrytallographer.", + None, description="Decription text from robocrytallographer.", ) condensed_structure: CondensedStructureData = Field( - None, - description="Condensed structure data from robocrytallographer.", + None, description="Condensed structure data from robocrytallographer.", ) - task_id: str = Field( + material_id: str = Field( None, description="The Materials Project ID of the material. This comes in the form: mp-******", ) last_updated: datetime = Field( - None, - description="Timestamp for the most recent calculation for this document", + None, description="Timestamp for the most recent calculation for this document", ) # Make sure that the datetime field is properly formatted diff --git a/src/mp_api/routes/summary/client.py b/src/mp_api/routes/summary/client.py index bf79aeaf..e5d3da4d 100644 --- a/src/mp_api/routes/summary/client.py +++ b/src/mp_api/routes/summary/client.py @@ -19,6 +19,7 @@ def search_summary_docs( material_ids: Optional[List[MPID]] = None, chemsys_formula: Optional[str] = None, exclude_elements: Optional[List[str]] = None, + possible_species: Optional[List[str]] = None, nsites: Optional[Tuple[int, int]] = None, volume: Optional[Tuple[float, float]] = None, density: Optional[Tuple[float, float]] = None, @@ -29,7 +30,7 @@ def search_summary_docs( total_energy: Optional[Tuple[float, float]] = None, formation_energy: Optional[Tuple[float, float]] = None, energy_above_hull: Optional[Tuple[float, float]] = None, - equillibrium_reaction_energy: Optional[Tuple[float, float]] = None, + equilibrium_reaction_energy: Optional[Tuple[float, float]] = None, uncorrected_energy: Optional[Tuple[float, float]] = None, is_stable: Optional[bool] = None, band_gap: Optional[Tuple[float, float]] = None, @@ -80,6 +81,8 @@ def search_summary_docs( or formula including anonomyzed formula or wild cards (e.g., Fe2O3, ABO3, Si*). exclude_elements (List(str)): List of elements to exclude. + possible_species (List(str)): List of element symbols appended with oxidation states. + (e.g. Cr2+,O2-) crystal_system (CrystalSystem): Crystal system of material. spacegroup_number (int): Space group number of material. spacegroup_symbol (str): Space group symbol of the material in international short symbol notation. @@ -88,6 +91,8 @@ def search_summary_docs( density (Tuple[float,float]): Minimum and maximum density to consider. deprecated (bool): Whether the material is tagged as deprecated. total_energy (Tuple[int,int]): Minimum and maximum corrected total energy in eV/atom to consider. + equilibrium_reaction_energy (Tuple[float,float]): Minimum and maximum equilibrium reaction energy + in eV/atom to consider. formation_energy (Tuple[int,int]): Minimum and maximum formation energy in eV/atom to consider. energy_above_hull (Tuple[int,int]): Minimum and maximum energy above the hull in eV/atom to consider. uncorrected_energy (Tuple[int,int]): Minimum and maximum uncorrected total energy in eV/atom to consider. @@ -153,7 +158,7 @@ def search_summary_docs( "formation_energy": "formation_energy_per_atom", "energy_above_hull": "energy_above_hull", "uncorrected_energy": "uncorrected_energy_per_atom", - "equillibrium_reaction_energy": "equillibrium_reaction_energy_per_atom", + "equilibrium_reaction_energy": "equilibrium_reaction_energy_per_atom", "nsites": "nsites", "volume": "volume", "density": "density", @@ -204,6 +209,9 @@ def search_summary_docs( if exclude_elements is not None: query_params.update({"exclude_elements": ",".join(exclude_elements)}) + if possible_species is not None: + query_params.update({"possible_species": ",".join(possible_species)}) + query_params.update( { "crystal_system": crystal_system, diff --git a/src/mp_api/routes/summary/resources.py b/src/mp_api/routes/summary/resources.py index 8d8cde48..890fc4f4 100644 --- a/src/mp_api/routes/summary/resources.py +++ b/src/mp_api/routes/summary/resources.py @@ -13,6 +13,7 @@ FormulaQuery, SymmetryQuery, ) +from mp_api.routes.oxidation_states.query_operators import PossibleOxiStateQuery from emmet.core.summary import SummaryStats from mp_api.routes.summary.query_operators import ( HasPropsQuery, @@ -34,6 +35,7 @@ def summary_resource(summary_store): MaterialIDsSearchQuery(), FormulaQuery(), ElementsQuery(), + PossibleOxiStateQuery(), SymmetryQuery(), SearchIsStableQuery(), SearchIsTheoreticalQuery(), diff --git a/src/mp_api/routes/thermo/client.py b/src/mp_api/routes/thermo/client.py index 4924d293..18e58338 100644 --- a/src/mp_api/routes/thermo/client.py +++ b/src/mp_api/routes/thermo/client.py @@ -21,7 +21,7 @@ def search_thermo_docs( total_energy: Optional[Tuple[float, float]] = None, formation_energy: Optional[Tuple[float, float]] = None, energy_above_hull: Optional[Tuple[float, float]] = None, - equillibrium_reaction_energy: Optional[Tuple[float, float]] = None, + equilibrium_reaction_energy: Optional[Tuple[float, float]] = None, uncorrected_energy: Optional[Tuple[float, float]] = None, sort_field: Optional[str] = None, ascending: Optional[bool] = None, @@ -43,7 +43,7 @@ def search_thermo_docs( total_energy (Tuple[float,float]): Minimum and maximum corrected total energy in eV/atom to consider. formation_energy (Tuple[float,float]): Minimum and maximum formation energy in eV/atom to consider. energy_above_hull (Tuple[float,float]): Minimum and maximum energy above the hull in eV/atom to consider. - equillibrium_reaction_energy (Tuple[float,float]): Minimum and maximum equilibrium reaction energy + equilibrium_reaction_energy (Tuple[float,float]): Minimum and maximum equilibrium reaction energy in eV/atom to consider. uncorrected_energy (Tuple[float,float]): Minimum and maximum uncorrected total energy in eV/atom to consider. @@ -85,7 +85,7 @@ def search_thermo_docs( "total_energy": "energy_per_atom", "formation_energy": "formation_energy_per_atom", "energy_above_hull": "energy_above_hull", - "equillibrium_reaction_energy": "equillibrium_reaction_energy_per_atom", + "equilibrium_reaction_energy": "equilibrium_reaction_energy_per_atom", "uncorrected_energy": "uncorrected_energy_per_atom", } diff --git a/tests/electronic_structure/test_client.py b/tests/electronic_structure/test_client.py index 171bf539..dc4e23f6 100644 --- a/tests/electronic_structure/test_client.py +++ b/tests/electronic_structure/test_client.py @@ -100,7 +100,6 @@ def test_es_client(es_rester): bs_custom_field_tests = { - "path_type": BSPathType.setyawan_curtarolo, "magnetic_ordering": Ordering.FM, "is_metal": True, "is_gap_direct": True, @@ -110,7 +109,7 @@ def test_es_client(es_rester): bs_sub_doc_fields = ["bandstructure"] -bs_alt_name_dict = {"path_type": "setyawan_curtarolo"} # type: dict +bs_alt_name_dict = {} # type: dict @pytest.fixture @@ -139,6 +138,8 @@ def test_bs_client(bs_rester): "num_chunks": 1, } doc = search_method(**q)[0].dict() + print(q) + print(doc) for sub_field in bs_sub_doc_fields: if sub_field in doc: doc = doc[sub_field] @@ -146,11 +147,13 @@ def test_bs_client(bs_rester): if param != "path_type": doc = doc["setyawan_curtarolo"] + print("=====") + print(doc) + assert doc[project_field if project_field is not None else param] is not None dos_custom_field_tests = { - "projection_type": DOSProjectionType.total, "magnetic_ordering": Ordering.FM, "efermi": (0, 100), "band_gap": (0, 5), @@ -160,9 +163,7 @@ def test_bs_client(bs_rester): dos_sub_doc_fields = ["dos"] -dos_alt_name_dict = { - "projection_type": "total", -} # type: dict +dos_alt_name_dict = {} # type: dict @pytest.fixture diff --git a/tests/robocrys/test_client.py b/tests/robocrys/test_client.py index 72674ca1..02c424ae 100644 --- a/tests/robocrys/test_client.py +++ b/tests/robocrys/test_client.py @@ -14,6 +14,7 @@ def rester(): rester.session.close() +@pytest.mark.xfail # temp @pytest.mark.skipif( os.environ.get("MP_API_KEY", None) is None, reason="No API key found." ) diff --git a/tests/test_client.py b/tests/test_client.py index 5f5beb56..b96ea48e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -10,7 +10,7 @@ "doi": "mp-149", "wulff": "mp-149", "charge_density": "mp-1936745", - "robocrys": "mp-149", + "provenance": "mp-149", } search_only_resters = [ @@ -25,7 +25,7 @@ "charge_density", ] -ignore_generic = ["provenance"] # temp +ignore_generic = ["robocrys"] # temp mpr = MPRester() diff --git a/tests/test_mprester.py b/tests/test_mprester.py index e17b8c89..ed66c253 100644 --- a/tests/test_mprester.py +++ b/tests/test_mprester.py @@ -54,7 +54,6 @@ def test_get_database_version(self, mpr): def test_get_materials_id_from_task_id(self, mpr): assert mpr.get_materials_id_from_task_id("mp-540081") == "mp-19017" - @pytest.mark.xfail # temp xfail while data is fixed def test_get_materials_id_references(self, mpr): data = mpr.get_materials_id_references("mp-123") assert len(data) > 5 @@ -186,7 +185,7 @@ def test_get_wulff_shape(self, mpr): ws = mpr.get_wulff_shape("mp-126") assert isinstance(ws, WulffShape) - @pytest.mark.xfail # temp xfail while data is fixed + @pytest.mark.xfail # temporary until api deploy def test_query(self, mpr): excluded_params = [ @@ -221,6 +220,7 @@ def test_query(self, mpr): "material_ids": ["mp-149"], "chemsys_formula": "SiO2", "exclude_elements": ["Si"], + "possible_species": ["O2-"], "crystal_system": CrystalSystem.cubic, "spacegroup_number": 38, "spacegroup_symbol": "Amm2", diff --git a/tests/thermo/test_client.py b/tests/thermo/test_client.py index 9f645aeb..246bd917 100644 --- a/tests/thermo/test_client.py +++ b/tests/thermo/test_client.py @@ -14,7 +14,7 @@ "num_chunks", "all_fields", "fields", - "equillibrium_reaction_energy", + "equilibrium_reaction_energy", ] sub_doc_fields = [] # type: list @@ -25,6 +25,7 @@ "total_energy": "energy_per_atom", "formation_energy": "formation_energy_per_atom", "uncorrected_energy": "uncorrected_energy_per_atom", + "equilibirum_reaction_energy": "equilibirum_reaction_energy_per_atom", } # type: dict custom_field_tests = {