Skip to content

Commit

Permalink
Small oxidation state and thermo changes (#394)
Browse files Browse the repository at this point in the history
* Equilibrium typo fix

* Add oxi states query op to summary

* Emmet bump

* Fix emmet core bump

* Enable oxi state query with summary

* Linting

* Fix material_id in robocrys

* Fix tests

* More test updates

* Remove xfail from some mprester tests
  • Loading branch information
munrojm committed Sep 28, 2021
1 parent b8c0471 commit 8cf8a6d
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions src/mp_api/matproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/mp_api/routes/oxidation_states/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
PaginationQuery,
SortQuery,
SparseFieldsQuery,
NumericQuery,
)

from mp_api.routes.materials.query_operators import FormulaQuery
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/robocrys/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
"""
Expand Down
29 changes: 10 additions & 19 deletions src/mp_api/routes/robocrys/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class MineralData(BaseModel):
"""

type: str = Field(
None,
description="Mineral type.",
None, description="Mineral type.",
)


Expand All @@ -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.",
)


Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/mp_api/routes/summary/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/mp_api/routes/summary/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,6 +35,7 @@ def summary_resource(summary_store):
MaterialIDsSearchQuery(),
FormulaQuery(),
ElementsQuery(),
PossibleOxiStateQuery(),
SymmetryQuery(),
SearchIsStableQuery(),
SearchIsTheoreticalQuery(),
Expand Down
6 changes: 3 additions & 3 deletions src/mp_api/routes/thermo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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",
}

Expand Down
13 changes: 7 additions & 6 deletions tests/electronic_structure/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -139,18 +138,22 @@ 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]

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),
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/robocrys/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"doi": "mp-149",
"wulff": "mp-149",
"charge_density": "mp-1936745",
"robocrys": "mp-149",
"provenance": "mp-149",
}

search_only_resters = [
Expand All @@ -25,7 +25,7 @@
"charge_density",
]

ignore_generic = ["provenance"] # temp
ignore_generic = ["robocrys"] # temp


mpr = MPRester()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/thermo/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"num_chunks",
"all_fields",
"fields",
"equillibrium_reaction_energy",
"equilibrium_reaction_energy",
]

sub_doc_fields = [] # type: list
Expand All @@ -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 = {
Expand Down

0 comments on commit 8cf8a6d

Please sign in to comment.