Example #1
0
 def Laue_group(self):
     '''
     :return: get the Laue group in :math:`SO(3)` of a 3D lattice, in :math:`SO(2)` of a 2D lattice.
     :rtype: :py:class:`MatrixGroup <structrans.crystallography.MatrixGroup>`
     :raises AttributeError: Laue groups for other than 2D and 3D lattices are not implemented yet.
     '''
     if not self.dimension() in [2, 3]:
         raise AttributeError('Laue groups for other than 2D and 3D lattices are not implemented yet.')
     if self.__LaueGroup is None and self.dimension() == 3:
         self.__LaueGroup = MatrixGroup(np.array([Q for Q in CUBIC_LAUE_GROUP.matrices() if self.inpointgroup(Q)]))
         if self.__LaueGroup.order() == 4:
             hexgroup = MatrixGroup(np.array([Q for Q in HEX_LAUE_GROUP.matrices() if self.inpointgroup(Q)]))
             if hexgroup.order() > self.__LaueGroup.order():
                 self.__LaueGroup = hexgroup
     if self.__LaueGroup is None and self.dimension() == 2:
         self.__LaueGroup = MatrixGroup(np.array([Q for Q in SQUARE_GROUP.matrices() if self.inpointgroup(Q)]))
         if self.__LaueGroup.order() == 2:
             hexGroup = MatrixGroup(np.array([Q for Q in HEX2D_GROUP.matrices() if self.inpointgroup(Q)]))
             if hexGroup.order() > self.__LaueGroup.order():
                 self.__LaueGroup = hexGroup
     return self.__LaueGroup
Example #2
0
 def Laue_group(self):
     '''
     :return: get the Laue group in :math:`SO(3)` of a 3D lattice, in :math:`SO(2)` of a 2D lattice.
     :rtype: :py:class:`MatrixGroup <structrans.crystallography.MatrixGroup>`
     :raises AttributeError: Laue groups for other than 2D and 3D lattices are not implemented yet.
     '''
     if not self.dimension() in [2, 3]:
         raise AttributeError(
             'Laue groups for other than 2D and 3D lattices are not implemented yet.'
         )
     if self.__LaueGroup is None and self.dimension() == 3:
         self.__LaueGroup = MatrixGroup(
             np.array([
                 Q for Q in CUBIC_LAUE_GROUP.matrices()
                 if self.inpointgroup(Q)
             ]))
         if self.__LaueGroup.order() == 4:
             hexgroup = MatrixGroup(
                 np.array([
                     Q for Q in HEX_LAUE_GROUP.matrices()
                     if self.inpointgroup(Q)
                 ]))
             if hexgroup.order() > self.__LaueGroup.order():
                 self.__LaueGroup = hexgroup
     if self.__LaueGroup is None and self.dimension() == 2:
         self.__LaueGroup = MatrixGroup(
             np.array([
                 Q for Q in SQUARE_GROUP.matrices() if self.inpointgroup(Q)
             ]))
         if self.__LaueGroup.order() == 2:
             hexGroup = MatrixGroup(
                 np.array([
                     Q for Q in HEX2D_GROUP.matrices()
                     if self.inpointgroup(Q)
                 ]))
             if hexGroup.order() > self.__LaueGroup.order():
                 self.__LaueGroup = hexGroup
     return self.__LaueGroup
Example #3
0
    def test_groups(self):
        L = Lattice(np.eye(4))
        self.assertRaises(AttributeError, L.Laue_group)
        self.assertRaises(AttributeError, L.point_group)
        self.assertRaises(AttributeError, L.special_lattice_group)
        self.assertRaises(AttributeError, L.lattice_group)

        # fcc with a = 2
        E = [[1., 0., 1.], [1., 1., 0.], [0., 1., 1.]]
        L = Lattice(E)
        Q = [[0., 1., 0.], [1., 0., 0.], [0., 0., -1.]]
        self.assertTrue(L.inpointgroup(Q))
        self.assertEqual(L.Laue_group().order(), 24)
        self.assertEqual(L.point_group().order(), 48)
        self.assertEqual(L.special_lattice_group().order(), 24)
        self.assertEqual(L.lattice_group().order(), 48)

        PG1 = L.point_group()
        self.assertTrue(PG1.hassubgroup(PG1))

        # monoclinic
        E = [[2., 0., 0.20934382], [0., 3., 0.], [0., 0., 3.99451814]]
        L = Lattice(E)
        self.assertFalse(L.inpointgroup(Q))
        self.assertEqual(L.Laue_group().order(), 2)
        self.assertEqual(L.point_group().order(), 4)
        self.assertEqual(L.special_lattice_group().order(), 2)
        self.assertEqual(L.lattice_group().order(), 4)

        PG2 = L.point_group()
        self.assertTrue(PG1.hassubgroup(PG2))

        # hexagonal, a = 2, c = 3
        E = [[2., 1., 0.], [0., np.sqrt(3), 0.], [0., 0., 3.]]
        L = Lattice(E)
        self.assertEqual(L.Laue_group().order(), 12)
        self.assertEqual(L.point_group().order(), 24)
        self.assertEqual(L.special_lattice_group().order(), 12)
        self.assertEqual(L.lattice_group().order(), 24)
        for Q in HEX_LAUE_GROUP.matrices():
            self.assertTrue(L.inpointgroup(Q))

        PG3 = L.point_group()
        self.assertFalse(PG1.hassubgroup(PG3))

        # rounding tolerance of floating numbers
        E = [[2., 1., 0.], [0., 1.73205081, 0.], [0., 0., 3.]]
        L = Lattice(E)
        self.assertEqual(L.Laue_group().order(), 12)
        self.assertEqual(L.point_group().order(), 24)
        self.assertEqual(L.special_lattice_group().order(), 12)
        self.assertEqual(L.lattice_group().order(), 24)
        Q = HEX_LAUE_GROUP.matrices()[6]
        self.assertTrue(L.inpointgroup(Q))

        # a random lattice
        E = 4 * np.random.rand(3, 3)
        while la.det(E) <= 0:
            E = 4 * np.random.rand(3, 3)
        L = Lattice(E)
        # lattice_group, point_group relationship
        PG = L.point_group().matrices()
        LG = L.lattice_group().matrices()

        LGlist = [m.tolist() for m in LG]
        LaueG = [m.tolist() for m in L.Laue_group().matrices()]
        SLG = [m.tolist() for m in L.special_lattice_group().matrices()]
        for Q in PG:
            self.assertEqual(L, Lattice(Q.dot(L.base())))
            self.assertTrue(np.array_equal(Q.T.dot(Q), np.eye(3)))
            self.assertTrue(L.inpointgroup(Q))
            if Q.tolist() in LaueG:
                self.assertTrue(la.det(Q) == 1)
            else:
                self.assertTrue(la.det(Q) == -1)
            # QE = EM
            M = np.rint(la.inv(E).dot(Q.dot(E)))
            self.assertTrue(M.tolist() in LGlist)
            self.assertTrue(L.inlatticegroup(M))

        for M in LG:
            self.assertEqual(L, Lattice(L.base().dot(M)))
            if M.tolist() in SLG:
                self.assertTrue(la.det(M) == 1)
            else:
                self.assertTrue(la.det(M) == -1)
            # QE = EM
            Q = E.dot(M).dot(la.inv(E))
            self.assertTrue(L.inpointgroup(Q))
Example #4
0
    def test_groups(self):
        L = Lattice(np.eye(4))
        self.assertRaises(AttributeError, L.Laue_group)
        self.assertRaises(AttributeError, L.point_group)
        self.assertRaises(AttributeError, L.special_lattice_group)
        self.assertRaises(AttributeError, L.lattice_group)

        # fcc with a = 2
        E = [[1., 0., 1.], [1., 1., 0.], [0., 1., 1.]]
        L = Lattice(E)
        Q = [[0., 1., 0.], [1., 0., 0.], [0., 0., -1.]]
        self.assertTrue(L.inpointgroup(Q))
        self.assertEqual(L.Laue_group().order(), 24)
        self.assertEqual(L.point_group().order(), 48)
        self.assertEqual(L.special_lattice_group().order(), 24)
        self.assertEqual(L.lattice_group().order(), 48)

        PG1 = L.point_group()
        self.assertTrue(PG1.hassubgroup(PG1))

        # monoclinic
        E = [[2., 0., 0.20934382], [0., 3., 0.], [0., 0., 3.99451814]]
        L = Lattice(E)
        self.assertFalse(L.inpointgroup(Q))
        self.assertEqual(L.Laue_group().order(), 2)
        self.assertEqual(L.point_group().order(), 4)
        self.assertEqual(L.special_lattice_group().order(), 2)
        self.assertEqual(L.lattice_group().order(), 4)

        PG2 = L.point_group()
        self.assertTrue(PG1.hassubgroup(PG2))

        # hexagonal, a = 2, c = 3
        E = [[2., 1., 0.], [0., np.sqrt(3), 0.], [0., 0., 3.]]
        L = Lattice(E)
        self.assertEqual(L.Laue_group().order(), 12)
        self.assertEqual(L.point_group().order(), 24)
        self.assertEqual(L.special_lattice_group().order(), 12)
        self.assertEqual(L.lattice_group().order(), 24)
        for Q in HEX_LAUE_GROUP.matrices():
            self.assertTrue(L.inpointgroup(Q))

        PG3 = L.point_group()
        self.assertFalse(PG1.hassubgroup(PG3))

        # rounding tolerance of floating numbers
        E = [[2., 1., 0.], [0., 1.73205081, 0.], [0., 0., 3.]]
        L = Lattice(E)
        self.assertEqual(L.Laue_group().order(), 12)
        self.assertEqual(L.point_group().order(), 24)
        self.assertEqual(L.special_lattice_group().order(), 12)
        self.assertEqual(L.lattice_group().order(), 24)
        Q = HEX_LAUE_GROUP.matrices()[6]
        self.assertTrue(L.inpointgroup(Q))

        # a random lattice
        E = 4 * np.random.rand(3, 3)
        while la.det(E) <= 0:
            E = 4 * np.random.rand(3, 3)
        L = Lattice(E)
        # lattice_group, point_group relationship
        PG = L.point_group().matrices()
        LG = L.lattice_group().matrices()

        LGlist = [m.tolist() for m in LG]
        LaueG = [m.tolist() for m in L.Laue_group().matrices()]
        SLG = [m.tolist() for m in L.special_lattice_group().matrices()]
        for Q in PG:
            self.assertEqual(L, Lattice(Q.dot(L.base())))
            self.assertTrue(np.array_equal(Q.T.dot(Q), np.eye(3)))
            self.assertTrue(L.inpointgroup(Q))
            if Q.tolist() in LaueG:
                self.assertTrue(la.det(Q) == 1)
            else:
                self.assertTrue(la.det(Q) == -1)
            # QE = EM
            M = np.rint(la.inv(E).dot(Q.dot(E)))
            self.assertTrue(M.tolist() in LGlist)
            self.assertTrue(L.inlatticegroup(M))

        for M in LG:
            self.assertEqual(L, Lattice(L.base().dot(M)))
            if M.tolist() in SLG:
                self.assertTrue(la.det(M) == 1)
            else:
                self.assertTrue(la.det(M) == -1)
            # QE = EM
            Q = E.dot(M).dot(la.inv(E))
            self.assertTrue(L.inpointgroup(Q))