Skip to content

Commit

Permalink
Add COD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Jun 12, 2024
1 parent e696953 commit 83421d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
from pymatgen.util.typing import CompositionLike, MillerIndex, PathLike, PbcLike, SpeciesLike

FileFormats = Literal["cif", "poscar", "cssr", "json", "yaml", "yml", "xsf", "mcsqs", "res", "pwmat", ""]
StructureSources = Literal["Materials Project"]
StructureSources = Literal["Materials Project", "COD"]


class Neighbor(Site):
Expand Down Expand Up @@ -2945,14 +2945,18 @@ def from_id(cls, id: str, source: StructureSources = "Materials Project", **kwar
Args:
id: The id. E.g., the materials project id.
source: Source of the data. Defaults to "Materials Project", which is the only currently support method.
source: Source of the data. Defaults to "Materials Project".
**kwargs: Pass-through to any API calls.
"""
if source == "Materials Project":
from pymatgen.ext.matproj import MPRester

mpr = MPRester(**kwargs)
return mpr.get_structure_by_material_id(id) # type: ignore
elif source == "COD":
from pymatgen.ext.cod import COD
cod = COD()
return cod.get_structure_by_id(id)
raise ValueError(f"Invalid source: {source}")

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ def test_from_id(self):
s = Structure.from_id("mp-1143")
assert isinstance(s, Structure)
assert s.reduced_formula == "Al2O3"
s = Structure.from_id("1101077", source="COD")
assert s.reduced_formula == "LiV2O4"

def test_mutable_sequence_methods(self):
struct = self.struct
Expand Down

0 comments on commit 83421d3

Please sign in to comment.