Skip to content

Commit

Permalink
General upgrades (#390)
Browse files Browse the repository at this point in the history
* Formula to criteria wildcard bug fix

* Add formula to criteria test

* Add exclude elements to mprester

* Increase default rate limit setting

* Default deprecation query to false and update epts

* Remove wulff endpoint

* Remove wulff import

* Fix potcar deserialization in task doc

* Bug and test fixes

* Temp xfails included
  • Loading branch information
munrojm committed Sep 23, 2021
1 parent 714f2d5 commit b8c0471
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 126 deletions.
15 changes: 1 addition & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
surface_props_store_json = os.environ.get(
"SURFACE_PROPS_STORE", "surface_props_store.json"
)
wulff_store_json = os.environ.get("WULFF_STORE", "wulff_store.json")
robocrys_store_json = os.environ.get("ROBOCRYS_STORE", "robocrys_store.json")
synth_store_json = os.environ.get("SYNTH_STORE", "synth_store.json")
insertion_electrodes_store_json = os.environ.get(
Expand Down Expand Up @@ -181,13 +180,6 @@
collection_name="surface_properties",
)

wulff_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
key="task_id",
collection_name="wulff",
)

robo_store = MongoURIStore(
uri=f"mongodb+srv://{db_uri}",
database="mp_core",
Expand Down Expand Up @@ -322,14 +314,13 @@
doi_store = loadfn(doi_store_json)
substrates_store = loadfn(substrates_store_json)
surface_props_store = loadfn(surface_props_store_json)
wulff_store = loadfn(wulff_store_json)
robo_store = loadfn(robocrys_store_json)
synth_store = loadfn(synth_store_json)
insertion_electrodes_store = loadfn(insertion_electrodes_store_json)
molecules_store = loadfn(molecules_store_json)
oxi_states_store = loadfn(oxi_states_store_json)
provenance_store = loadfn(provenance_store_json)
ssummary_store = loadfn(summary_store_json)
summary_store = loadfn(summary_store_json)

es_store = loadfn(es_store_json)

Expand Down Expand Up @@ -450,10 +441,6 @@

resources.update({"surface_properties": [surface_props_resource(surface_props_store)]})

# Wulff
from mp_api.routes.wulff.resources import wulff_resource

resources.update({"wulff": [wulff_resource(wulff_store)]})

# Robocrystallographer
from mp_api.routes.robocrys.resources import robo_resource, robo_search_resource
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MAPISettings(BaseSettings):
db_version: str = Field("2021_prerelease", description="Database version")

requests_per_min: int = Field(
60, description="Number of requests per minute to for rate limit."
100, description="Number of requests per minute to for rate limit."
)

class Config:
Expand Down
3 changes: 3 additions & 0 deletions src/mp_api/matproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def query(
self,
material_ids: Optional[List[MPID]] = None,
chemsys_formula: Optional[str] = None,
exclude_elements: Optional[List[str]] = None,
nsites: Optional[Tuple[int, int]] = None,
volume: Optional[Tuple[float, float]] = None,
density: Optional[Tuple[float, float]] = None,
Expand Down Expand Up @@ -530,6 +531,7 @@ def query(
chemsys_formula (str): A chemical system (e.g., Li-Fe-O),
or formula including anonomyzed formula
or wild cards (e.g., Fe2O3, ABO3, Si*).
exclude_elements (List(str)): List of elements to exclude.
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 Down Expand Up @@ -599,6 +601,7 @@ def query(
return self.summary.search_summary_docs( # type: ignore
material_ids=material_ids,
chemsys_formula=chemsys_formula,
exclude_elements=exclude_elements,
nsites=nsites,
volume=volume,
density=density,
Expand Down
1 change: 0 additions & 1 deletion src/mp_api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from mp_api.routes.grain_boundary.client import GrainBoundaryRester
from mp_api.routes.substrates.client import SubstratesRester
from mp_api.routes.surface_properties.client import SurfacePropertiesRester
from mp_api.routes.wulff.client import WulffRester
from mp_api.routes.phonon.client import PhononRester
from mp_api.routes.elasticity.client import ElasticityRester
from mp_api.routes.thermo.client import ThermoRester
Expand Down
4 changes: 4 additions & 0 deletions src/mp_api/routes/electronic_structure/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mp_api.routes.materials.query_operators import (
ElementsQuery,
FormulaQuery,
DeprecationQuery,
)

from mp_api.routes.electronic_structure.query_operators import (
Expand All @@ -26,6 +27,7 @@ def es_resource(es_store):
FormulaQuery(),
ElementsQuery(),
NumericQuery(model=ElectronicStructureDoc),
DeprecationQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(
Expand All @@ -45,6 +47,7 @@ def bs_resource(es_store):
ElectronicStructureDoc,
query_operators=[
BSDataQuery(),
DeprecationQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(
Expand Down Expand Up @@ -84,6 +87,7 @@ def dos_resource(es_store):
ElectronicStructureDoc,
query_operators=[
DOSDataQuery(),
DeprecationQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/materials/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DeprecationQuery(QueryOperator):
def query(
self,
deprecated: Optional[bool] = Query(
None, description="Whether the material is marked as deprecated",
False, description="Whether the material is marked as deprecated",
),
) -> STORE_PARAMS:

Expand Down
14 changes: 6 additions & 8 deletions src/mp_api/routes/materials/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def formula_to_criteria(formula: str) -> Dict:
if "*" in eles:
crit["nelements"] = len(eles)
crit["elements"] = {"$all": [ele for ele in eles if ele != "*"]}

if crit["elements"]["$all"] == []:
del crit["elements"]

return crit
else:
chemsys = "-".join(sorted(eles))
Expand All @@ -34,17 +38,11 @@ def formula_to_criteria(formula: str) -> Dict:

formula_dummies = formula.replace("*", "{}").format(*dummies[:nstars])

integer_formula = Composition(formula_dummies).get_integer_formula_and_factor()[
0
]
integer_formula = Composition(formula_dummies).get_integer_formula_and_factor()[0]
comp = Composition(integer_formula).reduced_composition
crit = dict()
crit["formula_anonymous"] = comp.anonymized_formula
real_elts = [
str(e)
for e in comp.elements
if not e.as_dict().get("element", "A") in dummies
]
real_elts = [str(e) for e in comp.elements if not e.as_dict().get("element", "A") in dummies]

for el, n in comp.to_reduced_dict.items():
if el in real_elts:
Expand Down
3 changes: 2 additions & 1 deletion src/mp_api/routes/provenance/resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from maggma.api.resource import ReadOnlyResource
from maggma.api.query_operator import PaginationQuery
from mp_api.routes.materials.query_operators import DeprecationQuery

from emmet.core.provenance import ProvenanceDoc

Expand All @@ -8,7 +9,7 @@ def provenance_resource(provenance_store):
resource = ReadOnlyResource(
provenance_store,
ProvenanceDoc,
query_operators=[PaginationQuery()],
query_operators=[DeprecationQuery(), PaginationQuery()],
tags=["Provenance"],
disable_validation=True,
enable_default_search=False,
Expand Down
5 changes: 5 additions & 0 deletions src/mp_api/routes/summary/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def search_summary_docs(
self,
material_ids: Optional[List[MPID]] = None,
chemsys_formula: Optional[str] = None,
exclude_elements: Optional[List[str]] = None,
nsites: Optional[Tuple[int, int]] = None,
volume: Optional[Tuple[float, float]] = None,
density: Optional[Tuple[float, float]] = None,
Expand Down Expand Up @@ -78,6 +79,7 @@ def search_summary_docs(
chemsys_formula (str): A chemical system (e.g., Li-Fe-O),
or formula including anonomyzed formula
or wild cards (e.g., Fe2O3, ABO3, Si*).
exclude_elements (List(str)): List of elements to exclude.
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 Down Expand Up @@ -199,6 +201,9 @@ def search_summary_docs(
if chemsys_formula:
query_params.update({"formula": chemsys_formula})

if exclude_elements is not None:
query_params.update({"exclude_elements": ",".join(exclude_elements)})

query_params.update(
{
"crystal_system": crystal_system,
Expand Down
13 changes: 11 additions & 2 deletions src/mp_api/routes/tasks/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from datetime import datetime
from enum import Enum
from typing import List
from json import decoder
from typing import List, Dict

from monty.json import MontyDecoder
from pydantic import BaseModel, Field, validator

from pymatgen.core.structure import Structure
from pymatgen.core.composition import Composition
from pymatgen.core.periodic_table import Element
from pymatgen.io.vasp import Incar, Poscar, Kpoints, Potcar
from pymatgen.io.vasp import Incar, Poscar, Kpoints
from pymatgen.core.trajectory import Trajectory

monty_decoder = MontyDecoder()
Expand All @@ -30,6 +31,14 @@ class TaskType(str, Enum):
GGA_U_Structure_Optimization = "GGA+U Structure Optimization"


class Potcar(BaseModel):
functional: str = Field(None, description="Functional type use in the calculation.")

symbols: List[str] = Field(
None, description="List of VASP potcar symbols used in the calculation."
)


class OrigInputs(BaseModel):
incar: Incar = Field(
None, description="Pymatgen object representing the INCAR file",
Expand Down
Empty file.
9 changes: 0 additions & 9 deletions src/mp_api/routes/wulff/client.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/mp_api/routes/wulff/client.pyi

This file was deleted.

50 changes: 0 additions & 50 deletions src/mp_api/routes/wulff/models.py

This file was deleted.

20 changes: 0 additions & 20 deletions src/mp_api/routes/wulff/resources.py

This file was deleted.

1 change: 1 addition & 0 deletions tests/materials/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ def test_formula_to_criteria():
# Chemsys
assert formula_to_criteria("Si-O") == {"chemsys": "O-Si"}
assert formula_to_criteria("Si-*") == {"elements": {"$all": ["Si"]}, "nelements": 2}
assert formula_to_criteria("*-*-*") == {"nelements": 3}
Loading

0 comments on commit b8c0471

Please sign in to comment.