Skip to content

Commit 7455c23

Browse files
add poscar to data output for workflows
1 parent 7a2e84c commit 7455c23

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

mp_api/mcp/_schemas.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from emmet.core.summary import SummaryDoc
77
from pydantic import BaseModel, Field, model_validator
8+
from pymatgen.core import Structure
89
from typing_extensions import Self
910

1011
from mp_api.client.core.utils import validate_ids
@@ -266,6 +267,13 @@ class MaterialMetadata(BaseModel):
266267
),
267268
)
268269

270+
poscar: str | None = Field(
271+
None,
272+
description=(
273+
"The structure in VASP's POSCAR format: " "https://vasp.at/wiki/POSCAR"
274+
),
275+
)
276+
269277
cell_vectors: list[list[float]] | None = Field(
270278
None,
271279
description=(
@@ -368,6 +376,7 @@ def from_summary_data(cls, summary_data: dict[str, Any], **kwargs) -> Self:
368376
site["properties"].get("magmom") for site in struct_dict["sites"]
369377
]
370378
metadata.update(
379+
poscar=Structure.from_dict(struct_dict).to(fmt="poscar"),
371380
cell_vectors=struct_dict["lattice"]["matrix"],
372381
atoms=[site["species"][0]["element"] for site in struct_dict["sites"]],
373382
cartesian_coordinates=[site["xyz"] for site in struct_dict["sites"]],

mp_api/mcp/tools.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ def _validate_identifiers(
234234

235235
return list(valid_mpids.union(new_mpids))
236236

237-
def fetch_many(self, str_idxs: str) -> list[FetchResult]:
237+
def fetch_many(
238+
self, str_idxs: str, limit_one_per_chemsys: bool = False
239+
) -> list[FetchResult]:
238240
"""Retrieve complete material information for a list of materials.
239241
240242
Should only be used to retrieve at most 100 materials.
@@ -248,6 +250,8 @@ def fetch_many(self, str_idxs: str) -> list[FetchResult]:
248250
str_idxs (str) : A list of Materials Project IDs,
249251
chemical formulas, or chemical systems, separated by
250252
commas, e.g., "mp-13, LiCl, Fe-O"
253+
limit_one_per_chemsys (bool) : Whether to limit to one
254+
entry per chemical system.
251255
252256
Returns:
253257
list of FetchResult with detailed material metadata.
@@ -263,7 +267,10 @@ def fetch_many(self, str_idxs: str) -> list[FetchResult]:
263267
"most 100 identifiers or use `fetch_all` to retrieve all "
264268
"data and filter down."
265269
)
266-
idxs = self._validate_identifiers(idxs, limit_one_per_chemsys=True)
270+
idxs = self._validate_identifiers(
271+
idxs,
272+
limit_one_per_chemsys=limit_one_per_chemsys,
273+
)
267274
return self._aggregate_fetch_results_from_mpids(idxs)
268275

269276
def fetch(self, idx: str) -> FetchResult:
@@ -294,7 +301,7 @@ def fetch(self, idx: str) -> FetchResult:
294301
Raises:
295302
MPRestError: If no identifier is specified
296303
"""
297-
return self.fetch_many(idx)[0]
304+
return self.fetch_many(idx, limit_one_per_chemsys=True)[0]
298305

299306
def get_phase_diagram_from_elements(
300307
self,

0 commit comments

Comments
 (0)