def test_as_dict_and_from_dict(self): sm = StructureMatcher(ltol=0.1, stol=0.2, angle_tol=2, primitive_cell=False, scale=False, comparator=FrameworkComparator()) d = sm.as_dict() sm2 = StructureMatcher.from_dict(d) self.assertEqual(sm2.as_dict(), d)
def __init__( self, existing_structures, structure_matcher=StructureMatcher(comparator=ElementComparator()), symprec=None, ): """ Remove existing structures based on the structure matcher and symmetry (if symprec is given). Args: existing_structures: List of existing structures to compare with structure_matcher: Provides a structure matcher to be used for structure comparison. symprec: The precision in the symmetry finder algorithm if None ( default value), no symmetry check is performed and only the structure matcher is used. A recommended value is 1e-5. """ self.symprec = symprec self.structure_list = [] self.existing_structures = existing_structures if isinstance(structure_matcher, dict): self.structure_matcher = StructureMatcher.from_dict(structure_matcher) else: self.structure_matcher = structure_matcher
def test_to_dict_and_from_dict(self): sm = StructureMatcher(ltol=0.1, stol=0.2, angle_tol=2, primitive_cell=False, scale=False, comparator=FrameworkComparator()) d = sm.to_dict sm2 = StructureMatcher.from_dict(d) self.assertEqual(sm2.to_dict, d)
def __init__(self, structure_matcher=StructureMatcher( comparator=ElementComparator()), symprec=None): """ Remove duplicate structures based on the structure matcher and symmetry (if symprec is given). Args: structure_matcher: Provides a structure matcher to be used for structure comparison. symprec: The precision in the symmetry finder algorithm if None ( default value), no symmetry check is performed and only the structure matcher is used. A recommended value is 1e-5. """ self._symprec = symprec self._structure_list = [] if isinstance(structure_matcher, dict): self._sm = StructureMatcher.from_dict(structure_matcher) else: self._sm = structure_matcher
def run_task(self, fw_spec): reference_struct = fw_spec.get("base_structure") results = fw_spec.get("inserted_results", []) max_inserted_atoms = fw_spec.get("max_inserted_atoms", None) working_ion = fw_spec.get("working_ion") sm_dict = fw_spec.get("structure_matcher", SM_DICT) if not isinstance(sm_dict, dict): sm_dict = sm_dict.as_dict() sm_dict["ignored_species"] = [working_ion] sm = StructureMatcher.from_dict(sm_dict) if len(results) == 0: # can happen if all parents fizzled raise RuntimeError("No insertion calculation completed") tmp_struct_ = results[0]["structure"] # type: Structure n_ions = int(tmp_struct_.composition.as_dict()[working_ion]) if max_inserted_atoms is not None and n_ions >= max_inserted_atoms: return FWAction(defuse_children=True) best_res = {"energy": math.inf} n_completed = 0 for ires in results: n_completed += 1 ires_struct_ = ires["structure"] if (sm.fit(ires_struct_, reference_struct) and ires["energy"] < best_res["energy"]): logger.info("Found new optimal_structure") best_res = ires if "structure" not in best_res: # No matching structure was found in the completed results if n_completed > 0: return FWAction(defuse_children=True) # Get the new structures return FWAction( update_spec={"optimal_structure": best_res["structure"]})
def __init__( self, structure_matcher=StructureMatcher(comparator=ElementComparator()), symprec=None): """ Remove duplicate structures based on the structure matcher and symmetry (if symprec is given). Args: structure_matcher: Provides a structure matcher to be used for structure comparison. symprec: The precision in the symmetry finder algorithm if None (default value), no symmetry check is performed and only the structure matcher is used. A recommended value is 1e-5 """ self._symprec = symprec self._structure_list = [] if isinstance(structure_matcher, dict): self._sm = StructureMatcher.from_dict(structure_matcher) else: self._sm = structure_matcher