Skip to content

Commit

Permalink
Merge branch 'main' into scan-id
Browse files Browse the repository at this point in the history
# Conflicts:
#	emmet-builders/emmet/builders/materials/oxidation_states.py
  • Loading branch information
shyamd committed Jun 29, 2021
2 parents ada37d3 + 0564284 commit 622a05a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ ENV/

# PyCharm
.idea
<<<<<<< HEAD

# Pytest
.pytest_cache
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v0.4.1](https://github.com/materialsproject/emmet/tree/v0.4.1) (2021-06-27)

[Full Changelog](https://github.com/materialsproject/emmet/compare/v0.4.0...v0.4.1)

**Merged pull requests:**

- Fix oxidation doc composition [\#217](https://github.com/materialsproject/emmet/pull/217) ([shyamd](https://github.com/shyamd))

## [v0.4.0](https://github.com/materialsproject/emmet/tree/v0.4.0) (2021-06-24)

[Full Changelog](https://github.com/materialsproject/emmet/compare/v0.3.6...v0.4.0)
Expand Down
11 changes: 3 additions & 8 deletions emmet-builders/emmet/builders/materials/oxidation_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pymatgen.core import __version__ as pymatgen_version

from emmet.core.oxidation_states import OxidationStateDoc
from emmet.core.utils import jsanitize


class OxidationStatesBuilder(MapBuilder):
Expand Down Expand Up @@ -38,16 +39,10 @@ def __init__(
def unary_function(self, item):
structure = Structure.from_dict(item["structure"])
mpid = item["material_id"]

oxi_doc = OxidationStateDoc.from_structure(
structure=structure, material_id=mpid
)
doc = oxi_doc.dict()

doc.update(
{
"pymatgen_version": pymatgen_version,
"successful": True,
}
)
doc = jsanitize(oxi_doc.dict(), allow_bson=True)

return doc
6 changes: 4 additions & 2 deletions emmet-core/emmet/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ def from_composition(
if fields is None
else fields
)
composition = composition.remove_charges()

elsyms = sorted(set([e.symbol for e in composition.elements]))

data = {
"elements": elsyms,
"nelements": len(elsyms),
"composition": composition,
"composition_reduced": composition.reduced_composition,
"composition_reduced": composition.reduced_composition.remove_charges(),
"formula_pretty": composition.reduced_formula,
"formula_anonymous": composition.anonymized_formula,
"chemsys": "-".join(elsyms),
Expand Down Expand Up @@ -126,7 +128,7 @@ def from_structure(
if fields is None
else fields
)
comp = structure.composition
comp = structure.composition.remove_charges()
elsyms = sorted(set([e.symbol for e in comp.elements]))
symmetry = SymmetryData.from_structure(structure)

Expand Down
30 changes: 30 additions & 0 deletions tests/emmet-builders/test_oxidation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from maggma.stores import JSONStore, MemoryStore

from emmet.builders.materials.oxidation_states import OxidationStatesBuilder


@pytest.fixture(scope="session")
def fake_materias(test_dir):
entries = JSONStore(test_dir / "LiTiO2_batt.json", key="entry_id")
entries.connect()

materials_store = MemoryStore(key="material_id")
materials_store.connect()

for doc in entries.query():
materials_store.update(
{"material_id": doc["entry_id"], "structure": doc["structure"]}
)
return materials_store


def test_oxidation_store(fake_materias):
oxi_store = MemoryStore()
builder = OxidationStatesBuilder(
materials=fake_materias, oxidation_states=oxi_store
)
builder.run()

assert oxi_store.count() == 6
assert all([isinstance(d["composition"], dict) for d in oxi_store.query()])

0 comments on commit 622a05a

Please sign in to comment.