-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from materialsproject/robocrys
Robocrystallographer document
- Loading branch information
Showing
10 changed files
with
176 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Dict, Optional, List | ||
from maggma.builders.map_builder import MapBuilder | ||
from maggma.core import Store | ||
|
||
from pymatgen.core.structure import Structure | ||
from emmet.core.robocrys import RobocrystallogapherDoc | ||
from emmet.core.utils import jsanitize | ||
|
||
|
||
class RobocrystallographerBuilder(MapBuilder): | ||
def __init__( | ||
self, | ||
oxidation_states: Store, | ||
robocrys: Store, | ||
query: Optional[Dict] = None, | ||
**kwargs | ||
): | ||
self.oxidation_states = oxidation_states | ||
self.robocrys = robocrys | ||
self.kwargs = kwargs | ||
|
||
self.robocrys.key = "material_id" | ||
self.oxidation_states.key = "material_id" | ||
|
||
super().__init__( | ||
source=oxidation_states, | ||
target=robocrys, | ||
query=query, | ||
projection=["material_id", "structure"], | ||
**kwargs | ||
) | ||
|
||
def unary_function(self, item): | ||
structure = Structure.from_dict(item["structure"]) | ||
mpid = item["material_id"] | ||
|
||
doc = RobocrystallogapherDoc.from_structure( | ||
structure=structure, | ||
material_id=mpid, | ||
fields=[], | ||
) | ||
|
||
return jsanitize(doc.dict(), allow_bson=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import Union | ||
|
||
from pydantic import BaseModel, Field | ||
from pymatgen.core.structure import Structure | ||
from robocrys import StructureCondenser, StructureDescriber | ||
from robocrys import __version__ as __robocrys_version__ | ||
|
||
from emmet.core.material_property import PropertyDoc | ||
from emmet.core.mpid import MPID | ||
|
||
|
||
class MineralData(BaseModel): | ||
""" | ||
Model for mineral data in the condensed structure robocrystallographer field | ||
""" | ||
|
||
type: Union[str, None] = Field( | ||
description="Mineral type.", | ||
) | ||
|
||
name: str = Field(None, description="The mineral name if found") | ||
|
||
|
||
class CondensedStructureData(BaseModel): | ||
""" | ||
Model for data in the condensed structure robocrystallographer field | ||
More details: https://hackingmaterials.lbl.gov/robocrystallographer/format.html | ||
""" | ||
|
||
mineral: MineralData = Field( | ||
description="Matched mineral data for the material.", | ||
) | ||
|
||
dimensionality: int = Field( | ||
description="Dimensionality of the material.", | ||
) | ||
|
||
|
||
class RobocrystallogapherDoc(PropertyDoc): | ||
""" | ||
This document contains the descriptive data from robocrystallographer | ||
for a material: | ||
Structural features, mineral prototypes, dimensionality, ... | ||
""" | ||
|
||
description: str = Field( | ||
description="Decription text from robocrytallographer.", | ||
) | ||
|
||
condensed_structure: CondensedStructureData = Field( | ||
description="Condensed structure data from robocrytallographer.", | ||
) | ||
|
||
robocrys_version: str = Field( | ||
__robocrys_version__, | ||
description="The version of Robocrystallographer used to generate this document", | ||
) | ||
|
||
@classmethod | ||
def from_structure(cls, structure: Structure, material_id: MPID, **kwargs): # type: ignore[override] | ||
condensed_structure = StructureCondenser().condense_structure(structure) | ||
description = StructureDescriber( | ||
describe_symmetry_labels=False, fmt="unicode", return_parts=False | ||
).describe(condensed_structure=condensed_structure) | ||
|
||
return cls( | ||
structure=structure, | ||
material_id=material_id, | ||
condensed_structure=condensed_structure, | ||
description=description, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pymatgen==2022.0.9 | ||
monty==v2021.3.3 | ||
monty==2021.6.10 | ||
pydantic==1.8.2 | ||
pybtex==0.24.0 | ||
typing-extensions==3.10.0.0 | ||
seekpath==2.0.1 | ||
setuptools-scm==6.0.1 | ||
robocrys==0.2.7 | ||
matminer==0.7.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
from pymatgen.core import Structure | ||
from pymatgen.util.testing import PymatgenTest | ||
|
||
from emmet.core.robocrys import RobocrystallogapherDoc | ||
|
||
test_structures = { | ||
name: struc.get_reduced_structure() | ||
for name, struc in PymatgenTest.TEST_STRUCTURES.items() | ||
if name | ||
in [ | ||
"SiO2", | ||
"Li2O", | ||
"LiFePO4", | ||
"TlBiSe2", | ||
"K2O2", | ||
"Li3V2(PO4)3", | ||
"CsCl", | ||
"Li2O2", | ||
"NaFePO4", | ||
"Pb2TiZrO6", | ||
"SrTiO3", | ||
"TiO2", | ||
"BaNiO3", | ||
"VO2", | ||
] | ||
} | ||
|
||
|
||
@pytest.mark.parametrize("structure", test_structures.values()) | ||
def test_robocrys(structure: Structure): | ||
"""Very simple test to make sure this actually works""" | ||
print(f"Should work : {structure.composition}") | ||
doc = RobocrystallogapherDoc.from_structure(structure, material_id=33) | ||
assert doc is not None |