def test_get_start_end_structs_from_hop(self):
     dist_ref = self.m_hop.length
     base = self.lifepo.copy()
     base.remove_species(["Li"])
     start, end, b_sc = get_start_end_structures(
         self.m_hop.isite,
         self.m_hop.esite,
         base_struct=base,
         sc_mat=[[2, 1, 0], [-1, 1, 0], [0, 0, 1]],
         vac_mode=False,
     )
     start_site = next(
         filter(lambda x: x.species_string == "Li", start.sites))
     end_site = next(filter(lambda x: x.species_string == "Li", end.sites))
     self.assertAlmostEqual(start_site.distance(end_site), dist_ref, 3)
Esempio n. 2
0
    def get_sc_structures(
        self,
        vac_mode: bool,
        min_atoms: int = 80,
        max_atoms: int = 240,
        min_length: float = 10.0,
    ) -> Tuple[Structure, Structure, Structure]:
        """
        Construct supercells that represents the start and end positions for migration analysis.

        Args:
            vac_mode: If true simulate vacancy diffusion.
            max_atoms: Maximum number of atoms allowed in the supercell.
            min_atoms: Minimum number of atoms allowed in the supercell.
            min_length: Minimum length of the smallest supercell lattice vector.

        Returns:
            Start, End, Base Structures.

            If not vacancy mode, the base structure is just the host lattice.
            If in vacancy mode, the base structure is the fully intercalated structure

        """
        migrating_specie_sites, other_sites = self._split_migrating_and_other_sites(
            vac_mode)
        if vac_mode:
            base_struct = Structure.from_sites(other_sites +
                                               migrating_specie_sites)
        else:
            base_struct = Structure.from_sites(other_sites)
        sc_mat = get_sc_fromstruct(
            base_struct=base_struct,
            min_atoms=min_atoms,
            max_atoms=max_atoms,
            min_length=min_length,
        )
        start_struct, end_struct, base_sc = get_start_end_structures(
            self.isite,
            self.esite,
            base_struct,
            sc_mat,
            vac_mode=vac_mode  # type: ignore
        )
        return start_struct, end_struct, base_sc
 def test_get_start_end_structs_from_hop_vac(self):
     dist_ref = self.m_hop.length
     start, end, b_sc = get_start_end_structures(
         self.m_hop.isite,
         self.m_hop.esite,
         base_struct=self.lifepo,
         sc_mat=[[2, 1, 0], [-1, 1, 0], [0, 0, 2]],
         vac_mode=True,
     )
     s1 = set()
     s2 = set()
     for itr_start, start_site in enumerate(start.sites):
         for itr_end, end_site in enumerate(end.sites):
             dist_ = start_site.distance(end_site)
             if dist_ < 1e-5:
                 s1.add(itr_start)
                 s2.add(itr_end)
     s1 = sorted(s1, reverse=True)
     s2 = sorted(s2, reverse=True)
     start.remove_sites(s1)
     end.remove_sites(s2)
     self.assertAlmostEqual(start.sites[0].distance(end.sites[0]), dist_ref,
                            3)