def test_process_ents(self): base_2_ent = ComputedStructureEntry( structure=self.base.structure * [[1, 1, 0], [1, -1, 0], [0, 0, 2]], energy=self.base.energy * 4, ) res = process_entries( [base_2_ent, self.base], [self.inserted_2Li], migrating_ion_entry=self.li_ent, ) for itr_group in res: for i_insert_site in itr_group["inserted"]: if i_insert_site.species_string == "Li": self.assertEqual( i_insert_site.properties["insertion_energy"], 4)
def get_structure_from_entries( base_entries: List[ComputedStructureEntry], inserted_entries: List[ComputedStructureEntry], migrating_ion_entry: ComputedEntry, **kwargs, ) -> List[Structure]: """ Read in a list of base entries and inserted entries. Return a list of structures that contains metastable sites for the migration species decorated with a "insertion_energy" property. Args: base_entries: List of entries that only contains the host lattice inserted_entries: List of entries that contains the inserted structures migrating_ion_entry: The metallic phase of the working ion, used to calculate insertion energies. Additional Kwargs: symprec: symmetry parameter for SpacegroupAnalyzer ltol: Fractional length tolerance for StructureMatcher stol: Site tolerance for StructureMatcher angle_tol: Angle tolerance fro StructureMatcher and SpacegroupAnalyzer only_single_cat: If True, only use single cation insertions so the site energy is more accurate use_strict_tol: halve the ltol and stol parameter for more strict matching. Returns: """ l_base_and_inserted = process_entries( base_entries=base_entries, inserted_entries=inserted_entries, migrating_ion_entry=migrating_ion_entry, **kwargs, ) res = [] for group in l_base_and_inserted: all_sites = group["base"].copy().sites for isite in group["inserted"]: all_sites.append(isite) res.append(Structure.from_sites(all_sites)) return res
def get_structure_from_entries( entries: List[ComputedStructureEntry], migrating_ion_entry: ComputedEntry, **kwargs, ) -> List[Structure]: """ Read in a list of base entries and inserted entries. Return a list of structures that contains metastable sites for the migration species decorated with a "insertion_energy" property. Args: base_entries: List of entries that only contains the host lattice inserted_entries: List of entries that contains the inserted structures migrating_ion_entry: The metallic phase of the working ion, used to calculate insertion energies. Additional Kwargs: symprec: symmetry parameter for SpacegroupAnalyzer ltol: Fractional length tolerance for StructureMatcher stol: Site tolerance for StructureMatcher angle_tol: Angle tolerance fro StructureMatcher and SpacegroupAnalyzer only_single_cat: If True, only use single cation insertions so the site energy is more accurate use_strict_tol: halve the ltol and stol parameter for more strict matching. Returns: a list of host structures with working ion on all the metastable sites. The structures are ranked by the number of metastable sites (most is first) If the given entries are not enough to construct such a structure, return an empty list. """ if len(migrating_ion_entry.composition.elements) != 1: raise RuntimeError( "migrating_ion_entry should only have one element.") migration_element = migrating_ion_entry.composition.elements[0] base_entries = [] inserted_entries = [] for ient in entries: if migration_element in ient.composition.elements: inserted_entries.append(ient) else: base_entries.append(ient) if len(base_entries) == 0: logger.debug( f"No base entries found among {[ient.composition.formula for ient in entries]}" ) return [] if len(base_entries) == 0: logger.debug( f"No inserted entries found among {[ient.composition.formula for ient in entries]}" ) return [] l_base_and_inserted = process_entries( base_entries=base_entries, inserted_entries=inserted_entries, migrating_ion_entry=migrating_ion_entry, **kwargs, ) res = [] for group in l_base_and_inserted: all_sites = group["base"].copy().sites for isite in group["inserted"]: all_sites.append(isite) struct = Structure.from_sites(all_sites) # make spglib ignore all magmoms for isite in struct.sites: isite.properties.pop("magmom", None) res.append(struct) return res