From ef884a61e14870f229bab323f3f8458b81180a2c Mon Sep 17 00:00:00 2001 From: JSX Date: Tue, 2 Mar 2021 13:50:16 -0800 Subject: [PATCH] fixes --- .../emmet/builders/materials/electrodes.py | 60 ++++++++++++------- emmet-builders/emmet/builders/vasp/thermo.py | 2 +- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/emmet-builders/emmet/builders/materials/electrodes.py b/emmet-builders/emmet/builders/materials/electrodes.py index 0fe24de01c..6b9db42d8f 100644 --- a/emmet-builders/emmet/builders/materials/electrodes.py +++ b/emmet-builders/emmet/builders/materials/electrodes.py @@ -160,7 +160,7 @@ def get_items(self): ) ] - self.logger.debug( + self.logger.info( f"Performing initial checks on {len(all_chemsys)} chemical systems containing redox elements with or without the Working Ion." ) self.total = len(all_chemsys) @@ -230,8 +230,15 @@ def get_items(self): f"There are {len(mat_ids)} material ids in the source database vs {len(target_mat_ids)} in the target database." ) if mat_ids == target_mat_ids and max_mat_time < min_target_time: + self.logger.info( + f"Skipping all documents in {chemsys}." + ) + all_mats_in_chemsys = [] continue else: + self.logger.debug(f"MPIDS: {mat_ids} -> {max_mat_time}") + self.logger.debug(f"MPIDS: {target_mat_ids} -> {min_target_time}") + self.logger.debug(f"MPIDS: {target_mat_ids}") self.logger.info( f"Nuking all {len(target_mat_ids)} documents in chemsys {chemsys} in the target database." ) @@ -261,6 +268,11 @@ def _entry_from_mat_doc(self, mdoc): return ComputedStructureEntry.from_dict(d_) def process_item(self, item: Any) -> Any: + self.logger.info( + f"Processing {len(item['materials'])} materials entries in {item['chemsys']}." + ) + if len(item["materials"])==0: + return None entries = [*map(self._entry_from_mat_doc, item["materials"])] s_groups = StructureGroupDoc.from_ungrouped_structure_entries( entries=entries, @@ -281,28 +293,29 @@ def _remove_targets(self, rm_ids): class InsertionElectrodeBuilder(MapBuilder): def __init__( self, - grouped_materials: MongoStore, - insertion_electrode: MongoStore, - thermo: MongoStore, + sgroup: MongoStore, material: MongoStore, + insertion_electrode: MongoStore, + thermo: MongoStore = None, query: dict = None, **kwargs, ): - self.grouped_materials = grouped_materials + self.sgroup = sgroup self.insertion_electrode = insertion_electrode self.thermo = thermo self.material = material qq_ = {} if query is None else query qq_.update({"structure_matched": True, "has_distinct_compositions": True}) super().__init__( - source=self.grouped_materials, + source=self.sgroup, target=self.insertion_electrode, query=qq_, **kwargs, ) def get_items(self): - """""" + """ + """ @lru_cache(None) def get_working_ion_entry(working_ion): @@ -317,17 +330,20 @@ def modify_item(item): self.logger.debug( f"Looking for {len(item['grouped_ids'])} material_id in the Thermo DB." ) - with self.thermo as store: - thermo_docs = [ - *store.query( - { - "$and": [ - {"material_id": {"$in": item["grouped_ids"]}}, - ] - }, - properties=["material_id", "_sbxn", "thermo"], - ) - ] + thermo_docs = [] + self.logger.debug(self.thermo) + if self.thermo is not None: + with self.thermo as store: + thermo_docs = [ + *store.query( + { + "$and": [ + {"material_id": {"$in": item["grouped_ids"]}}, + ] + }, + properties=["material_id", "_sbxn", "thermo"], + ) + ] with self.material as store: material_docs = [ @@ -348,13 +364,17 @@ def modify_item(item): "Insertion electrode can only be defined for one working ion species" ) working_ion_doc = get_working_ion_entry(item["ignored_species"][0]) - return { + + res = { "material_id": item["material_id"], "working_ion_doc": working_ion_doc, "working_ion": item["ignored_species"][0], - "thermo_docs": thermo_docs, "material_docs": material_docs, } + if self.thermo: + resp["thermo_docs"] = thermo_docs + + return res yield from map(modify_item, super().get_items()) diff --git a/emmet-builders/emmet/builders/vasp/thermo.py b/emmet-builders/emmet/builders/vasp/thermo.py index 547e26dc8d..e5324fbfa7 100644 --- a/emmet-builders/emmet/builders/vasp/thermo.py +++ b/emmet-builders/emmet/builders/vasp/thermo.py @@ -90,7 +90,7 @@ def get_items(self) -> Iterator[List[Dict]]: if chemsys not in to_process_chemsys: to_process_chemsys |= chemsys_permutations(chemsys) - self.logger.inf( + self.logger.info( f"Found {len(to_process_chemsys)} chemical systems with new/updated materials to process" ) self.total = len(to_process_chemsys)