Skip to content

Commit

Permalink
Add task_ids query to legacy molecules rester (#897)
Browse files Browse the repository at this point in the history
* Add task_ids query to legacy molecules rester

* Fix jcesr test
  • Loading branch information
Jason Munro authored Feb 29, 2024
1 parent daefc5f commit 4d8dba0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mp_api/client/routes/molecules/jcesr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pymatgen.core.periodic_table import Element

from mp_api.client.core import BaseRester
from mp_api.client.core.utils import validate_ids


class JcesrMoleculesRester(BaseRester[MoleculesDoc]):
Expand All @@ -15,6 +16,7 @@ class JcesrMoleculesRester(BaseRester[MoleculesDoc]):

def search(
self,
task_ids: str | list[str] | None = None,
charge: tuple[float, float] | None = None,
elements: list[Element] | None = None,
EA: tuple[float, float] | None = None,
Expand All @@ -30,6 +32,8 @@ def search(
"""Query equations of state docs using a variety of search criteria.
Arguments:
task_ids (str, List[str]): A single molecule task ID string or list of strings.
(e.g., mol-45004, [mol-45004, mol-45228]).
charge (Tuple[float,float]): Minimum and maximum value of the charge in +e to consider.
elements (List[Element]): A list of elements.
film_orientation (List[Elements]): List of elements that are in the molecule.
Expand All @@ -49,6 +53,12 @@ def search(
"""
query_params = defaultdict(dict) # type: dict

if task_ids:
if isinstance(task_ids, str):
task_ids = [task_ids]

query_params.update({"task_ids": ",".join(validate_ids(task_ids))})

if elements:
query_params.update({"elements": ",".join([str(ele) for ele in elements])})

Expand Down
3 changes: 2 additions & 1 deletion tests/molecules/test_jcesr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def rester():

sub_doc_fields = [] # type: list

alt_name_dict = {} # type: dict
alt_name_dict = {"task_ids": "task_id"} # type: dict

custom_field_tests = {
"task_ids": ["mol-45228"],
"elements": [Element("H")],
"pointgroup": "C1",
"smiles": "C#CC(=C)C.CNCCNC",
Expand Down

0 comments on commit 4d8dba0

Please sign in to comment.