Skip to content

Commit

Permalink
add oxidation state builder
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed May 27, 2021
1 parent 0791b3b commit 801f920
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions emmet-builders/emmet/builders/materials/oxidation_states.py
@@ -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

0 comments on commit 801f920

Please sign in to comment.