Skip to content

Commit

Permalink
Fix trajectory convenience function (#542)
Browse files Browse the repository at this point in the history
* Fix trajectory convenience function

* Add trajectory test

* Fix task test

* Test bug fix
  • Loading branch information
Jason Munro authored Mar 1, 2022
1 parent aeefde8 commit 2c04bf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/mp_api/routes/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, Union

from emmet.core.tasks import TaskDoc
from mp_api.core.client import BaseRester
from mp_api.core.client import BaseRester, MPRestError


class TaskRester(BaseRester[TaskDoc]):
Expand All @@ -17,10 +17,17 @@ def get_trajectory(self, task_id):
observing how a material relaxes during a geometry optimization.
:param task_id: A specified task_id
:return: Trajectory object
:return: List of trajectory objects
"""

pass
traj_data = self._query_resource_data(
suburl=f"trajectory/{task_id}/", use_document_model=False
)[0].get("trajectories", None)

if traj_data is None:
raise MPRestError(f"No trajectory data for {task_id} found")

return traj_data

def search_task_docs(
self,
Expand Down Expand Up @@ -65,5 +72,5 @@ def search_task_docs(
chunk_size=chunk_size,
all_fields=all_fields,
fields=fields,
**query_params
**query_params,
)
9 changes: 9 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pytest
from pymatgen.core.trajectory import Trajectory
from mp_api.routes.tasks import TaskRester

import inspect
Expand Down Expand Up @@ -94,3 +95,11 @@ def test_client(rester):
doc[project_field if project_field is not None else param]
is not None
)


def test_get_trajectories():

trajectories = resters[0].get_trajectory("mp-149")

for traj in trajectories:
assert isinstance(traj, Trajectory)

0 comments on commit 2c04bf7

Please sign in to comment.