Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dev/generate_mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def regenerate_tools(
COORDINATION_GEOMETRIES_IUPAC,
COORDINATION_GEOMETRIES_NAMES,
)
from emmet.core.electronic_structure import BSPathType, DOSProjectionType
from emmet.core.band_theory import BSPathType
from emmet.core.electronic_structure import DOSProjectionType
from emmet.core.grain_boundary import GBTypeEnum
from emmet.core.mpid import MPID
from emmet.core.thermo import ThermoType
Expand Down
6 changes: 4 additions & 2 deletions mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import cache, lru_cache
from typing import TYPE_CHECKING

from emmet.core.electronic_structure import BSPathType
from emmet.core.band_theory import BSPathType
from emmet.core.mpid import MPID, AlphaID
from emmet.core.types.enums import ThermoType
from emmet.core.vasp.calc_types import CalcType
Expand Down Expand Up @@ -1231,9 +1231,11 @@ def get_charge_density_from_task_id(
Returns:
(Chgcar, (Chgcar, CoreTaskDoc | dict), None): Pymatgen Chgcar object, or tuple with object and CoreTaskDoc
"""
# TODO: change when `validate_ids` is updated to return AlphaID
validated_id = AlphaID(validate_ids([task_id])[0].split("-")[-1], prefix="mp")
chgcar = self.materials.tasks._query_open_data(
bucket="materialsproject-parsed",
key=f"chgcars/{validate_ids([task_id])[0]}.json.gz",
key=f"chgcars/{validated_id.string}.json.gz",
decoder=lambda x: load_json(x, deser=True),
)[0][0]["data"]

Expand Down
4 changes: 3 additions & 1 deletion mp_api/client/routes/materials/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def search(
{f"{param}_min": value[0], f"{param}_max": value[1]}
)
elif param == "battery_ids":
query_params[param] = ",".join(validate_ids(value))
query_params[param] = ",".join(
validate_ids([value] if isinstance(value, str) else value)
)
elif param == "working_ion":
query_params["working_ion"] = ",".join(
str(ele)
Expand Down
2 changes: 1 addition & 1 deletion mp_api/client/routes/materials/electronic_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from collections import defaultdict
from typing import TYPE_CHECKING

from emmet.core.band_theory import BSPathType
from emmet.core.electronic_structure import (
BSPathType,
DOSProjectionType,
ElectronicStructureDoc,
)
Expand Down
23 changes: 20 additions & 3 deletions mp_api/client/routes/materials/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from emmet.core.mpid import MPID, AlphaID
from emmet.core.tasks import CoreTaskDoc
from emmet.core.trajectory import RelaxTrajectory
from emmet.core.vasp.calc_types import RunType

from mp_api.client.core import BaseRester, MPRestError
from mp_api.client.core.utils import validate_ids
Expand All @@ -24,18 +25,28 @@ class TaskRester(BaseRester):
primary_key: str = "task_id"
delta_backed = True

def get_trajectory(self, task_id: MPID | AlphaID | str) -> dict[str, Any]:
def get_trajectory(
self, task_id: MPID | AlphaID | str, run_type: str | RunType | None = None
) -> dict[str, Any]:
"""Returns a Trajectory object containing the geometry of the
material throughout a calculation. This is most useful for
observing how a material relaxes during a geometry optimization.

Args:
task_id (str, MPID, AlphaID): Task ID
run_type (str, RunType): Task run type

Returns:
dict representing emmet.core.trajectory.RelaxTrajectory
"""
as_alpha = str(AlphaID(task_id, padlen=8)).split("-")[-1]

predicate = (
f"WHERE run_type='{str(run_type)}' AND identifier='{as_alpha}'"
if run_type
else f"WHERE identifier='{as_alpha}'"
)

traj_tbl = DeltaTable(
"s3a://materialsproject-parsed/core/trajectories/",
storage_options={"AWS_SKIP_SIGNATURE": "true", "AWS_REGION": "us-east-1"},
Expand All @@ -48,7 +59,7 @@ def get_trajectory(self, task_id: MPID | AlphaID | str) -> dict[str, Any]:
f"""
SELECT *
FROM traj
WHERE identifier='{as_alpha}'
{predicate};
"""
)
.read_all()
Expand Down Expand Up @@ -96,7 +107,13 @@ def search(
if isinstance(task_ids, str):
task_ids = [task_ids]

query_params.update({"task_ids": ",".join(validate_ids(task_ids))})
# TODO: this should just be a join on `validate_ids`,
# once `validate_ids` returns AlphaID
validated = validate_ids(task_ids)
validated += [
str(AlphaID(task_id.split("-")[-1], padlen=8)) for task_id in validated
]
query_params["task_ids"] = ",".join(validated)

if formula:
query_params.update({"formula": formula})
Expand Down
7 changes: 5 additions & 2 deletions mp_api/client/routes/materials/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from emmet.core.types.enums import ThermoType
from pymatgen.analysis.phase_diagram import PhaseDiagram
from pymatgen.core import Element
from pymatgen.core import __version__ as __pmg_version__

from mp_api.client.core import BaseRester
from mp_api.client.core.utils import load_json, validate_ids
Expand Down Expand Up @@ -173,10 +174,12 @@ def get_phase_diagram_from_chemsys(
)[0][0].get("phase_diagram")

pd = PhaseDiagram.from_dict(
{
{ # type: ignore[arg-type]
k: v if k != "elements" else [e.get("element", e) for e in v]
for k, v in pd_dct.items() # type: ignore[union-attr]
}
} # post pymatgen/-core split, different serialization behavior
if int(__pmg_version__.split(".", 1)[0]) >= 2026
else pd_dct # pymatgen<=2025.10.7
)

# Ensure el_ref keys are Element objects for PDPlotter.
Expand Down
3 changes: 2 additions & 1 deletion mp_api/mcp/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
COORDINATION_GEOMETRIES_IUPAC,
COORDINATION_GEOMETRIES_NAMES,
)
from emmet.core.electronic_structure import BSPathType, DOSProjectionType
from emmet.core.band_theory import BSPathType
from emmet.core.electronic_structure import DOSProjectionType
from emmet.core.grain_boundary import GBTypeEnum
from emmet.core.mpid import MPID
from emmet.core.summary import HasProps
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Topic :: Scientific/Engineering",
]
dependencies = [
"pymatgen>=2022.3.7,!=2024.2.20",
"pymatgen>2024.2.20",
"typing-extensions>=3.7.4.1",
"requests>=2.23.0",
"monty>=2024.12.10",
Expand Down
26 changes: 13 additions & 13 deletions requirements/requirements-ubuntu-latest_py3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ bibtexparser==1.4.4
# via pymatgen-core
blake3==1.0.8
# via emmet-core
boto3==1.42.90
boto3==1.42.94
# via mp-api (pyproject.toml)
botocore==1.42.90
botocore==1.42.94
# via
# boto3
# s3transfer
certifi==2026.2.25
certifi==2026.4.22
# via requests
charset-normalizer==3.4.7
# via requests
contourpy==1.3.3
# via matplotlib
cycler==0.12.1
# via matplotlib
deltalake==1.5.0
deltalake==1.5.1
# via mp-api (pyproject.toml)
deprecated==1.3.1
# via deltalake
emmet-core==0.86.4rc1
emmet-core==0.86.4rc2
# via mp-api (pyproject.toml)
fonttools==4.62.1
# via matplotlib
idna==3.11
idna==3.13
# via requests
inflect==7.5.0
# via emmet-core
Expand All @@ -48,7 +48,7 @@ kiwisolver==1.5.0
# via matplotlib
latexcodec==3.0.1
# via pybtex
lxml==6.0.4
lxml==6.1.0
# via pymatgen-core
matplotlib==3.10.8
# via pymatgen-core
Expand All @@ -61,7 +61,7 @@ more-itertools==11.0.2
# via inflect
mpmath==1.3.0
# via sympy
narwhals==2.19.0
narwhals==2.20.0
# via plotly
networkx==3.6.1
# via pymatgen-core
Expand Down Expand Up @@ -93,18 +93,18 @@ plotly==6.7.0
# via pymatgen-core
pubchempy==1.0.5
# via emmet-core
pyarrow==23.0.1
pyarrow==24.0.0
# via mp-api (pyproject.toml)
pybtex==0.26.1
# via emmet-core
pydantic==2.13.1
pydantic==2.13.3
# via
# emmet-core
# pydantic-settings
# pymatgen-io-validation
pydantic-core==2.46.1
pydantic-core==2.46.3
# via pydantic
pydantic-settings==2.13.1
pydantic-settings==2.14.0
# via
# emmet-core
# pymatgen-io-validation
Expand Down Expand Up @@ -137,7 +137,7 @@ requests==2.33.1
# pymatgen-io-validation
ruamel-yaml==0.19.1
# via monty
s3transfer==0.16.0
s3transfer==0.16.1
# via boto3
scipy==1.17.1
# via pymatgen-core
Expand Down
Loading
Loading