Example #1
0
    def test_operate_magmom(self):

        # all test magmoms are the same
        magmoms = [
            Magmom([1, 2, 3]),  # as Magmom
            [1, 2, 3],  # as list
            Magmom([-3, 2, 1], saxis=[1, 0, 0]),
        ]  # as Magmom with non-default saxis

        xyzt_strings = ["x, y, z, +1", "x, y, z, -1", "x, -y, z, -1", "-x, -y, z, -1"]

        transformed_magmoms = [[1, 2, 3], [-1, -2, -3], [1, -2, 3], [1, 2, -3]]

        for xyzt_string, transformed_magmom in zip(xyzt_strings, transformed_magmoms):
            for magmom in magmoms:
                op = MagSymmOp.from_xyzt_string(xyzt_string)
                self.assertTrue(np.allclose(transformed_magmom, op.operate_magmom(magmom).global_moment))
Example #2
0
    def test_xyzt_string(self):

        xyzt_strings = [
            'x, y, z, +1', 'x, y, z, -1', '-y+1/2, x+1/2, x+1/2, +1'
        ]

        for xyzt_string in xyzt_strings:
            op = MagSymmOp.from_xyzt_string(xyzt_string)
            xyzt_string_out = op.as_xyzt_string()
            self.assertEqual(xyzt_string, xyzt_string_out)

        op = SymmOp([[3, -2, -1, 0.5], [-1, 0, 0, 12. / 13],
                     [0, 0, 1, 0.5 + 1e-7], [0, 0, 0, 1]])

        magop = MagSymmOp.from_symmop(op, -1)
        magop_str = magop.as_xyzt_string()
        self.assertEqual(magop.time_reversal, -1)
        self.assertEqual(magop_str, '3x-2y-z+1/2, -x+12/13, z+1/2, -1')
Example #3
0
    def test_xyzt_string(self):

        xyzt_strings = ['x, y, z, +1',
                        'x, y, z, -1',
                        '-y+1/2, x+1/2, x+1/2, +1']

        for xyzt_string in xyzt_strings:
            op = MagSymmOp.from_xyzt_string(xyzt_string)
            xyzt_string_out = op.as_xyzt_string()
            self.assertEqual(xyzt_string, xyzt_string_out)

        op = SymmOp([[3, -2, -1, 0.5], [-1, 0, 0, 12. / 13],
                     [0, 0, 1, 0.5 + 1e-7], [0, 0, 0, 1]])

        magop = MagSymmOp.from_symmop(op, -1)
        magop_str = magop.as_xyzt_string()
        self.assertEqual(magop.time_reversal, -1)
        self.assertEqual(magop_str, '3x-2y-z+1/2, -x+12/13, z+1/2, -1')
Example #4
0
    def test_operate_magmom(self):

        # all test magmoms are the same
        magmoms = [Magmom([1, 2, 3]),  # as Magmom
                   [1, 2, 3],  # as list
                   Magmom([-3, 2, 1], saxis=[1, 0, 0])]  # as Magmom with non-default saxis

        xyzt_strings = ['x, y, z, +1',
                        'x, y, z, -1',
                        'x, -y, z, -1',
                        '-x, -y, z, -1']

        transformed_magmoms = [[1, 2, 3],
                               [-1, -2, -3],
                               [1, -2, 3],
                               [1, 2, -3]]

        for xyzt_string, transformed_magmom in zip(xyzt_strings, transformed_magmoms):
            for magmom in magmoms:
                op = MagSymmOp.from_xyzt_string(xyzt_string)
                self.assertTrue(np.allclose(transformed_magmom, op.operate_magmom(magmom).global_moment))
Example #5
0
    def get_magsymops(self, data):
        """
        Equivalent to get_symops except for magnetic symmetry groups.
        Separate function since additional operation for time reversal symmetry
        (which changes magnetic moments on sites) needs to be returned.
        """
        magsymmops = []

        # check to see if magCIF file explicitly contains magnetic symmetry operations
        if data.data.get("_space_group_symop_magn_operation.xyz"):

            xyzt = data.data.get("_space_group_symop_magn_operation.xyz")
            if isinstance(xyzt, six.string_types):
                xyzt = [xyzt]
            magsymmops = [MagSymmOp.from_xyzt_string(s) for s in xyzt]

            if data.data.get("_space_group_symop_magn_centering.xyz"):

                xyzt = data.data.get("_space_group_symop_magn_centering.xyz")
                if isinstance(xyzt, six.string_types):
                    xyzt = [xyzt]
                centering_symops = [
                    MagSymmOp.from_xyzt_string(s) for s in xyzt
                ]

                all_ops = []
                for op in magsymmops:
                    for centering_op in centering_symops:
                        new_translation = [
                            i - np.floor(i) for i in op.translation_vector +
                            centering_op.translation_vector
                        ]
                        new_time_reversal = op.time_reversal * centering_op.time_reversal
                        all_ops.append(
                            MagSymmOp.
                            from_rotation_and_translation_and_time_reversal(
                                rotation_matrix=op.rotation_matrix,
                                translation_vec=new_translation,
                                time_reversal=new_time_reversal))
                magsymmops = all_ops

        # else check to see if it specifies a magnetic space group
        elif data.data.get("_space_group_magn.name_BNS") or data.data.get(
                "_space_group_magn.number_BNS"):

            if data.data.get("_space_group_magn.name_BNS"):
                # get BNS label for MagneticSpaceGroup()
                id = data.data.get("_space_group_magn.name_BNS")
            else:
                # get BNS number for MagneticSpaceGroup()
                # by converting string to list of ints
                id = list(
                    map(int, (data.data.get(
                        "_space_group_magn.number_BNS").split("."))))

            msg = MagneticSpaceGroup(id)

            if data.data.get("_space_group_magn.transform_BNS_Pp_abc"):
                if data.data.get("_space_group_magn.transform_BNS_Pp_abc"
                                 ) != "a,b,c;0,0,0":
                    return NotImplementedError(
                        "Non-standard settings not currently supported.")
            elif data.data.get("_space_group_magn.transform_BNS_Pp"):
                return NotImplementedError(
                    "Incomplete specification to implement.")

            magsymmops = msg.symmetry_ops

        if not magsymmops:
            warnings.warn(
                "No magnetic symmetry detected, using primitive symmetry.")
            magsymmops = [MagSymmOp.from_xyzt_string("x, y, z, 1")]

        return magsymmops