Skip to content

Commit

Permalink
Provenance to summary (#256)
Browse files Browse the repository at this point in the history
* Add provenance to summary builder

* Task IDS added from materials to summary

* Fix summary model

* Linting

* Fix summary tests
  • Loading branch information
Jason Munro authored Sep 2, 2021
1 parent 86b03ad commit 8775a52
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
30 changes: 11 additions & 19 deletions emmet-builders/emmet/builders/materials/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
substrates,
surfaces,
eos,
provenance,
summary,
chunk_size=100,
query=None,
Expand All @@ -45,6 +46,7 @@ def __init__(
self.substrates = substrates
self.surfaces = surfaces
self.eos = eos
self.provenance = provenance
self.summary = summary
self.chunk_size = chunk_size
self.query = query if query else {}
Expand All @@ -65,6 +67,7 @@ def __init__(
surfaces,
substrates,
eos,
provenance,
],
targets=[summary],
chunk_size=chunk_size,
Expand Down Expand Up @@ -98,32 +101,22 @@ def get_items(self):
"materials": self.materials.query_one({self.materials.key: entry}),
"thermo": self.thermo.query_one({self.thermo.key: entry}),
"xas": list(self.xas.query({self.xas.key: entry})),
"grain_boundaries": list(
self.grain_boundaries.query({self.grain_boundaries.key: entry})
),
"electronic_structure": self.electronic_structure.query_one(
{self.electronic_structure.key: entry}
),
"grain_boundaries": list(self.grain_boundaries.query({self.grain_boundaries.key: entry})),
"electronic_structure": self.electronic_structure.query_one({self.electronic_structure.key: entry}),
"magnetism": self.magnetism.query_one({self.magnetism.key: entry}),
"elasticity": self.elasticity.query_one({self.elasticity.key: entry}),
"dielectric": self.dielectric.query_one({self.dielectric.key: entry}),
"piezoelectric": self.piezoelectric.query_one(
{self.piezoelectric.key: entry}
),
"phonon": self.phonon.query_one(
{self.phonon.key: entry}, [self.phonon.key]
),
"piezoelectric": self.piezoelectric.query_one({self.piezoelectric.key: entry}),
"phonon": self.phonon.query_one({self.phonon.key: entry}, [self.phonon.key]),
"insertion_electrodes": list(
self.insertion_electrodes.query(
{self.insertion_electrodes.key: entry},
[self.insertion_electrodes.key],
{self.insertion_electrodes.key: entry}, [self.insertion_electrodes.key],
)
),
"surface_properties": self.surfaces.query_one(
{self.surfaces.key: entry}
),
"surface_properties": self.surfaces.query_one({self.surfaces.key: entry}),
"substrates": list(self.surfaces.query({self.substrates.key: entry})),
"eos": self.eos.query_one({self.eos.key: entry}, [self.eos.key]),
"provenance": self.provenance.query_one({self.provenance.key: entry}),
}

sub_fields = {
Expand All @@ -137,8 +130,7 @@ def get_items(self):
if data[collection] is not None:
data[collection] = (
data[collection][sub_field]
if (sub_field in data[collection])
and (data[collection][sub_field] != {})
if (sub_field in data[collection]) and (data[collection][sub_field] != {})
else None
)

Expand Down
6 changes: 6 additions & 0 deletions emmet-core/emmet/core/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class SummaryDoc(PropertyDoc):

structure: Structure = Field(..., description="The lowest energy structure for this material")

task_ids: List[MPID] = Field(
[], title="Calculation IDs", description="List of Calculations IDs associated with this material.",
)

# Thermo

uncorrected_energy_per_atom: float = Field(
Expand Down Expand Up @@ -268,6 +272,7 @@ def from_docs(cls, material_id: MPID, **docs: Dict[str, Dict]):
"symmetry",
"structure",
"deprecated",
"task_ids",
],
"thermo": [
"uncorrected_energy_per_atom",
Expand Down Expand Up @@ -320,6 +325,7 @@ def from_docs(cls, material_id: MPID, **docs: Dict[str, Dict]):
"weighted_work_function",
"has_reconstructed",
],
"provenance": ["theoretical"],
"eos": [],
"phonon": [],
"insertion_electrodes": [],
Expand Down
8 changes: 8 additions & 0 deletions tests/emmet-builders/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def xas():
return MemoryStore()


@pytest.fixture
def provenance():
return MemoryStore()


@pytest.fixture
def summary():
return MemoryStore(key="material_id")
Expand All @@ -106,6 +111,7 @@ def test_summary_builder(
substrates,
surfaces,
eos,
provenance,
summary,
):

Expand All @@ -124,6 +130,7 @@ def test_summary_builder(
xas=xas,
grain_boundaries=grain_boundaries,
eos=eos,
provenance=provenance,
summary=summary,
)

Expand All @@ -148,6 +155,7 @@ def test_serialization(tmpdir):
MemoryStore(),
MemoryStore(),
MemoryStore(),
MemoryStore(),
)

dumpfn(builder.as_dict(), Path(tmpdir) / "test.json")
Expand Down

0 comments on commit 8775a52

Please sign in to comment.