Skip to content

Commit

Permalink
Formula query added to electrodes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm authored and tschaume committed Mar 26, 2021
1 parent 539a484 commit 7d20334
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/mp_api/electrodes/query_operators.py
@@ -1,11 +1,39 @@
from typing import Optional
from fastapi import Query
from mp_api.core.query_operator import STORE_PARAMS, QueryOperator
from mp_api.materials.utils import formula_to_criteria
from pymatgen.core.periodic_table import Element

from collections import defaultdict


class ElectrodeFormulaQuery(QueryOperator):
"""
Method to generate a query for framework formula data
"""

def query(
self,
formula: Optional[str] = Query(
None,
description="Query by formula including anonymized formula or by including wild cards",
),
) -> STORE_PARAMS:

crit = {}

if formula:
crit.update(formula_to_criteria(formula))

for key in list(crit):
if "composition_reduced" in key:
framework_entry = "framework.{}".format(key.split(".")[1])
crit[framework_entry] = crit[key]
crit.pop(key)

return {"criteria": crit}


class VoltageStepQuery(QueryOperator):
"""
Method to generate a query for ranges of voltage step data values
Expand Down
2 changes: 2 additions & 0 deletions src/mp_api/electrodes/resources.py
Expand Up @@ -6,6 +6,7 @@
VoltageStepQuery,
InsertionVoltageStepQuery,
InsertionElectrodeQuery,
ElectrodeFormulaQuery,
)
from mp_api.materials.query_operators import ElementsQuery

Expand All @@ -15,6 +16,7 @@ def insertion_electrodes_resource(insertion_electrodes_store):
insertion_electrodes_store,
InsertionElectrodeDoc,
query_operators=[
ElectrodeFormulaQuery(),
ElementsQuery(),
VoltageStepQuery(),
InsertionVoltageStepQuery(),
Expand Down

0 comments on commit 7d20334

Please sign in to comment.