示例#1
0
 def _get_transformation_string_from_Pp(P: Union[List[List[float]],
                                                 np.ndarray],
                                        p: List[float]) -> str:
     P = np.array(P).transpose()
     P_string = transformation_to_string(P, components=("a", "b", "c"))
     p_string = transformation_to_string(np.zeros((3, 3)), p)
     return P_string + ";" + p_string
示例#2
0
    def test_transformation_to_string(self):
        m = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        t = [0, 0, 0]
        s = "x,y,z"
        ms = "mx,my,mz"
        abc = "a,b,c"
        self.assertEqual(s, transformation_to_string(m, t))
        self.assertEqual(ms, transformation_to_string(m, t, c="m"))
        self.assertEqual(
            abc, transformation_to_string(m, t, components=("a", "b", "c"))
        )

        m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        t = [11, 12, 13]
        s = "x+2y+3z+11,4x+5y+6z+12,7x+8y+9z+13"
        self.assertEqual(s, transformation_to_string(m, t))

        m = [
            [-1 / 2, -2 / 3, -3 / 4],
            [-5 / 6, -6 / 7, -7 / 8],
            [-8 / 9, -9 / 10, -10 / 11],
        ]
        t = [-11 / 12, -12 / 13, -13 / 14]
        s = "-x/2-2y/3-3z/4-11/12,-5x/6-6y/7-7z/8-12/13,-8x/9-9y/10-10z/11-13/14"
        self.assertEqual(s, transformation_to_string(m, t))
示例#3
0
        def _parse_wyckoff(b):
            """Parses compact binary representation into list of Wyckoff sites."""
            if len(b) == 0:
                return None

            wyckoff_sites = []

            def get_label(idx):
                if idx <= 25:
                    return chr(97 + idx)  # returns a-z when idx 0-25
                return "alpha"  # when a-z labels exhausted, use alpha, only relevant for a few space groups

            o = 0  # offset
            n = 1  # nth Wyckoff site
            num_wyckoff = b[0]
            while len(wyckoff_sites) < num_wyckoff:
                m = b[1 + o]  # multiplicity
                label = str(b[2 + o] * m) + get_label(num_wyckoff - n)
                sites = []
                for j in range(m):
                    s = b[
                        3 + o + (j * 22):3 + o + (j * 22) +
                        22]  # data corresponding to specific Wyckoff position
                    translation_vec = [s[0] / s[3], s[1] / s[3], s[2] / s[3]]
                    matrix = [
                        [s[4], s[7], s[10]],
                        [s[5], s[8], s[11]],
                        [s[6], s[9], s[12]],
                    ]
                    matrix_magmom = [
                        [s[13], s[16], s[19]],
                        [s[14], s[17], s[20]],
                        [s[15], s[18], s[21]],
                    ]
                    # store string representation, e.g. (x,y,z;mx,my,mz)
                    wyckoff_str = "({};{})".format(
                        transformation_to_string(matrix, translation_vec),
                        transformation_to_string(matrix_magmom, c="m"),
                    )
                    sites.append({
                        "translation_vec": translation_vec,
                        "matrix": matrix,
                        "matrix_magnetic": matrix_magmom,
                        "str": wyckoff_str,
                    })

                # only keeping string representation of Wyckoff sites for now
                # could do something else with these in future
                wyckoff_sites.append({
                    "label": label,
                    "str": " ".join([s["str"] for s in sites])
                })
                n += 1
                o += m * 22 + 2

            return wyckoff_sites
示例#4
0
        def _parse_wyckoff(b):
            '''Parses compact binary representation into list of Wyckoff sites.'''
            if len(b) == 0:
                return None

            wyckoff_sites = []

            def get_label(idx):
                if idx <= 25:
                    return chr(97+idx)  # returns a-z when idx 0-25
                else:
                    return 'alpha'  # when a-z labels exhausted, use alpha, only relevant for a few space groups

            o = 0  # offset
            n = 1  # nth Wyckoff site
            num_wyckoff = b[0]
            while len(wyckoff_sites) < num_wyckoff:
                m = b[1+o]  # multiplicity
                label = str(b[2+o]*m)+get_label(num_wyckoff-n)
                sites = []
                for j in range(m):
                    s = b[3+o+(j*22):3+o+(j*22)+22]  # data corresponding to specific Wyckoff position
                    translation_vec = [s[0]/s[3], s[1]/s[3], s[2]/s[3]]
                    matrix = [[s[4], s[5], s[6]],
                              [s[7], s[8], s[9]],
                              [s[10], s[11], s[12]]]
                    matrix_magmom = [[s[13], s[14], s[15]],
                                     [s[16], s[17], s[18]],
                                     [s[19], s[20], s[21]]]
                    # store string representation, e.g. (x,y,z;mx,my,mz)
                    wyckoff_str = "({};{})".format(transformation_to_string(matrix, translation_vec),
                                                   transformation_to_string(matrix_magmom, c='m'))
                    sites.append({'translation_vec': translation_vec,
                                  'matrix': matrix,
                                  'matrix_magnetic': matrix_magmom,
                                  'str': wyckoff_str})

                # only keeping string representation of Wyckoff sites for now
                # could do something else with these in future
                wyckoff_sites.append({'label': label,
                                      'str': ' '.join([s['str'] for s in sites])})
                n += 1
                o += m*22 + 2

            return wyckoff_sites
示例#5
0
    def test_transformation_to_string(self):
        m = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        t = [0, 0, 0]
        s = 'x,y,z'
        ms = 'mx,my,mz'
        abc = 'a,b,c'
        self.assertEqual(s, transformation_to_string(m, t))
        self.assertEqual(ms, transformation_to_string(m, t, c='m'))
        self.assertEqual(abc, transformation_to_string(m, t, components=('a', 'b', 'c')))

        m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        t = [11, 12, 13]
        s = 'x+2y+3z+11,4x+5y+6z+12,7x+8y+9z+13'
        self.assertEqual(s, transformation_to_string(m, t))

        m = [[-1 / 2, -2 / 3, -3 / 4], [-5 / 6, -6 / 7, -7 / 8], [-8 / 9, -9 / 10, -10 / 11]]
        t = [-11 / 12, -12 / 13, -13 / 14]
        s = '-x/2-2y/3-3z/4-11/12,-5x/6-6y/7-7z/8-12/13,-8x/9-9y/10-10z/11-13/14'
        self.assertEqual(s, transformation_to_string(m, t))
示例#6
0
    def test_transformation_to_string(self):
        m = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        t = [0, 0, 0]
        s = 'x,y,z'
        ms = 'mx,my,mz'
        abc = 'a,b,c'
        self.assertEqual(s, transformation_to_string(m, t))
        self.assertEqual(ms, transformation_to_string(m, t, c='m'))
        self.assertEqual(abc, transformation_to_string(m, t, components=('a', 'b', 'c')))

        m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        t = [11, 12, 13]
        s = 'x+2y+3z+11,4x+5y+6z+12,7x+8y+9z+13'
        self.assertEqual(s, transformation_to_string(m, t))

        m = [[-1 / 2, -2 / 3, -3 / 4], [-5 / 6, -6 / 7, -7 / 8], [-8 / 9, -9 / 10, -10 / 11]]
        t = [-11 / 12, -12 / 13, -13 / 14]
        s = '-x/2-2y/3-3z/4-11/12,-5x/6-6y/7-7z/8-12/13,-8x/9-9y/10-10z/11-13/14'
        self.assertEqual(s, transformation_to_string(m, t))
示例#7
0
    def as_xyz_string(self):
        """
        Returns a string of the form 'x, y, z', '-x, -y, z',
        '-y+1/2, x+1/2, z+1/2', etc. Only works for integer rotation matrices
        """
        # test for invalid rotation matrix
        if not np.all(np.isclose(self.rotation_matrix,
                                 np.round(self.rotation_matrix))):
            warnings.warn('Rotation matrix should be integer')

        return transformation_to_string(self.rotation_matrix, translation_vec=self.translation_vector, delim=", ")
示例#8
0
    def as_xyz_string(self):
        """
        Returns a string of the form 'x, y, z', '-x, -y, z',
        '-y+1/2, x+1/2, z+1/2', etc. Only works for integer rotation matrices
        """
        xyz = ['x', 'y', 'z']
        strings = []

        # test for invalid rotation matrix
        if not np.all(np.isclose(self.rotation_matrix,
                                 np.round(self.rotation_matrix))):
            warnings.warn('Rotation matrix should be integer')

        return transformation_to_string(self.rotation_matrix, translation_vec=self.translation_vector, delim=", ")
示例#9
0
 def _parse_transformation(b):
     """Parses compact binary representation into transformation between OG and BNS settings."""
     if len(b) == 0:
         return None
     # capital letters used here by convention,
     # IUCr defines P and p specifically
     P = [[b[0], b[3], b[6]], [b[1], b[4], b[7]], [b[2], b[5], b[8]]]
     p = [b[9] / b[12], b[10] / b[12], b[11] / b[12]]
     P = np.array(P).transpose()
     P_string = transformation_to_string(P, components=("a", "b", "c"))
     p_string = (f"{Fraction(p[0]).limit_denominator()},"
                 f"{Fraction(p[1]).limit_denominator()},"
                 f"{Fraction(p[2]).limit_denominator()}")
     return P_string + ";" + p_string
示例#10
0
 def _parse_transformation(b):
     '''Parses compact binary representation into transformation between OG and BNS settings.'''
     if len(b) == 0:
         return None
     # capital letters used here by convention,
     # IUCr defines P and p specifically
     P = [[b[0], b[1], b[2]], [b[3], b[4], b[5]], [b[6], b[7], b[8]]]
     p = [b[9] / b[12], b[10] / b[12], b[11] / b[12]]
     P = np.array(P).transpose()
     P_string = transformation_to_string(P, components=('a', 'b', 'c'))
     p_string = "{},{},{}".format(
         Fraction(p[0]).limit_denominator(),
         Fraction(p[1]).limit_denominator(),
         Fraction(p[2]).limit_denominator())
     return P_string + ";" + p_string
示例#11
0
 def _parse_transformation(b):
     '''Parses compact binary representation into transformation between OG and BNS settings.'''
     if len(b) == 0:
         return None
     # capital letters used here by convention,
     # IUCr defines P and p specifically
     P = [[b[0], b[1], b[2]],
          [b[3], b[4], b[5]],
          [b[6], b[7], b[8]]]
     p = [b[9]/b[12], b[10]/b[12], b[11]/b[12]]
     P = np.array(P).transpose()
     P_string = transformation_to_string(P, components=('a', 'b', 'c'))
     p_string = "{},{},{}".format(Fraction(p[0]).limit_denominator(),
                                  Fraction(p[1]).limit_denominator(),
                                  Fraction(p[2]).limit_denominator())
     return P_string + ";" + p_string
示例#12
0
 def _get_transformation_string_from_Pp(P, p):
     # type: (List[List[float]], List[float]) -> str
     P = np.array(P).transpose()
     P_string = transformation_to_string(P, components=('a', 'b', 'c'))
     p_string = transformation_to_string(np.zeros((3, 3)), p)
     return P_string+";"+p_string