Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
emmet-builders/emmet/builders/materials/oxidation_states.py
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,55 @@ | ||
from typing import Dict, List, Optional | ||
|
||
from maggma.builders.map_builder import MapBuilder | ||
from maggma.core import Store | ||
from pymatgen.core import Structure | ||
|
||
from pymatgen.core import __version__ as pymatgen_version | ||
|
||
|
||
from emmet.core.oxidation_states import OxidationStateDoc | ||
|
||
|
||
class OxidationStates(MapBuilder): | ||
def __init__( | ||
self, | ||
materials: Store, | ||
oxidation_states: Store, | ||
**kwargs, | ||
): | ||
""" | ||
Creates Oxidation State documents from materials | ||
Args: | ||
materials: Store of materials docs | ||
oxidation_states: Store to update with oxidation state document | ||
query : query on materials to limit search | ||
""" | ||
self.materials = materials | ||
self.oxidation_states = oxidation_states | ||
self.kwargs = kwargs | ||
|
||
# Enforce that we key on material_id | ||
self.materials.key = "material_id" | ||
self.oxidation_states.key = "material_id" | ||
super().__init__( | ||
source=materials, | ||
target=oxidation_states, | ||
projection=["structure"], | ||
**kwargs, | ||
) | ||
|
||
def unary_function(self, item): | ||
|
||
structure = Structure.from_dict(item["structure"]) | ||
oxi_doc = OxidationStateDoc.from_structure(structure) | ||
doc = oxi_doc.dict() | ||
|
||
doc.update( | ||
{ | ||
"pymatgen_version": pymatgen_version, | ||
"successful": True, | ||
} | ||
) | ||
|
||
return doc |