Esempio n. 1
0
 def test_relative_to_crystal_axes(self):
     lattice = Lattice.from_parameters(5, 10, 5, 90, 110, 90)
     moment = [1, 0, 2]
     magmom = Magmom.from_moment_relative_to_crystal_axes(moment, lattice)
     self.assertTrue(
         np.allclose(magmom.moment, [0.93969262, 0.0, 1.65797986]))
     self.assertTrue(
         np.allclose(magmom.get_moment_relative_to_crystal_axes(lattice),
                     moment))
Esempio n. 2
0
    def _unique_coords(self, coords_in, magmoms_in=None, lattice=None):
        """
        Generate unique coordinates using coord and symmetry positions
        and also their corresponding magnetic moments, if supplied.
        """
        coords = []
        coords_num = []

        if magmoms_in:
            magmoms = []
            if len(magmoms_in) != len(coords_in):
                raise ValueError
            for tmp_coord, tmp_magmom in zip(coords_in, magmoms_in):
                count = 0
                for op in self.symmetry_operations:
                    coord = op.operate(tmp_coord)
                    coord = np.array([i - math.floor(i) for i in coord])
                    if isinstance(op, MagSymmOp):
                        # Up to this point, magmoms have been defined relative
                        # to crystal axis. Now convert to Cartesian and into
                        # a Magmom object.
                        magmom = Magmom.from_moment_relative_to_crystal_axes(
                            op.operate_magmom(tmp_magmom), lattice=lattice)
                    else:
                        magmom = Magmom(tmp_magmom)
                    if not in_coord_list_pbc(
                            coords, coord, atol=self._site_tolerance):
                        coords.append(coord)
                        magmoms.append(magmom)
                        count = count + 1
                coords_num.append(count)
            return coords, magmoms, coords_num
        else:
            for tmp_coord in coords_in:
                count = 0
                for op in self.symmetry_operations:
                    coord = op.operate(tmp_coord)
                    coord = np.array([i - math.floor(i) for i in coord])
                    if not in_coord_list_pbc(
                            coords, coord, atol=self._site_tolerance):
                        coords.append(coord)
                        count = count + 1
                coords_num.append(count)
            return coords, [Magmom(0)
                            ] * len(coords), coords_num  # return dummy magmoms
Esempio n. 3
0
 def parse_magmoms(self, data, lattice=None):
     """
     Parse atomic magnetic moments from data dictionary
     """
     if lattice is None:
         raise Exception(
             'Magmoms given in terms of crystal axes in magCIF spec.')
     try:
         magmoms = {
             data["_atom_site_moment_label"][i]:
             Magmom.from_moment_relative_to_crystal_axes([
                 str2float(data["_atom_site_moment_crystalaxis_x"][i]),
                 str2float(data["_atom_site_moment_crystalaxis_y"][i]),
                 str2float(data["_atom_site_moment_crystalaxis_z"][i])
             ], lattice)
             for i in range(len(data["_atom_site_moment_label"]))
         }
     except (ValueError, KeyError):
         return None
     return magmoms
Esempio n. 4
0
 def test_relative_to_crystal_axes(self):
     lattice = Lattice.from_parameters(5, 10, 5, 90, 110, 90)
     moment = [1, 0, 2]
     magmom = Magmom.from_moment_relative_to_crystal_axes(moment, lattice)
     self.assertTrue(np.allclose(magmom.moment, [0.93969262, 0.0, 1.65797986]))
     self.assertTrue(np.allclose(magmom.get_moment_relative_to_crystal_axes(lattice), moment))