Esempio n. 1
0
    def test_degeneracy(self):
        sym_perm = self.cell.get_symmetry_permutation()
        self.assertEqual(self.cell.get_degeneracy(sym_perm), 1)

        ### more complex test
        arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
        positions = [[0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.00000],
                     [0.33333, 0.00000, 0.00000], [0.33333, 0.50000, 0.00000],
                     [0.66666, 0.00000, 0.00000], [0.66666, 0.50000, 0.00000],
                     [0.16666, 0.25000, 0.50000], [0.16666, 0.75000, 0.50000],
                     [0.50000, 0.25000, 0.50000], [0.50000, 0.75000, 0.50000],
                     [0.83333, 0.25000, 0.50000], [0.83333, 0.75000, 0.50000]]
        arr_positions = np.array(positions)
        arr_numbers = np.array([5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])
        gcell = GeneralCell(arr_lat, arr_positions, arr_numbers)
        self.assertEqual(gcell.get_degeneracy(sym_perm), 12)

        arr_numbers = np.array([5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])
        gcell = GeneralCell(arr_lat, arr_positions, arr_numbers)
        self.assertEqual(gcell.get_degeneracy(sym_perm), 6)
Esempio n. 2
0
class testGeneralCell(unittest.TestCase):
    def setUp(self):
        arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
        positions = [[0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.00000],
                     [0.33333, 0.00000, 0.00000], [0.33333, 0.50000, 0.00000],
                     [0.66666, 0.00000, 0.00000], [0.66666, 0.50000, 0.00000],
                     [0.16666, 0.25000, 0.50000], [0.16666, 0.75000, 0.50000],
                     [0.50000, 0.25000, 0.50000], [0.50000, 0.75000, 0.50000],
                     [0.83333, 0.25000, 0.50000], [0.83333, 0.75000, 0.50000]]
        arr_positions = np.array(positions)
        arr_numbers = np.array([6] * 12)
        self.cell = GeneralCell(arr_lat, arr_positions, arr_numbers)

    # def test_eq(self):
    #     arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
    #     positions = [
    #                     [0.00000, 0.00000, 0.00000],
    #                     [0.00000, 0.50000, 0.00000],
    #                     [0.33333, 0.00000, 0.00000],
    #                     [0.33333, 0.50000, 0.00000],
    #                     [0.66666, 0.00000, 0.00000],
    #                     [0.66666, 0.50000, 0.00000],
    #                     [0.16666, 0.25000, 0.50000],
    #                     [0.16666, 0.75000, 0.50000],
    #                     [0.50000, 0.25000, 0.50000],
    #                     [0.50000, 0.75000, 0.50000],
    #                     [0.83333, 0.25000, 0.50000],
    #                     [0.83333, 0.75000, 0.50000]
    #                 ]
    #     arr_positions = np.array(positions)
    #     arr_numbers = np.array([6]*12)
    #     cell = GeneralCell(arr_lat, arr_positions, arr_numbers)
    #     self.assertEqual(cell, self.cell)
    #
    #     arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
    #     positions = [
    #                     [0.00000, 0.00000, 0.00000],
    #                     [0.00000, 0.50000, 0.00000],
    #                     [0.33333, 0.00000, 0.00000],
    #                     [0.66666, 0.50000, 0.00000],
    #                     [0.16666, 0.25000, 0.50000],
    #                     [0.16666, 0.75000, 0.50000],
    #                     [0.33333, 0.50000, 0.00000],
    #                     [0.66666, 0.00000, 0.00000],
    #                     [0.50000, 0.25000, 0.50000],
    #                     [0.50000, 0.75000, 0.50000],
    #                     [0.83333, 0.25000, 0.50000],
    #                     [0.83333, 0.75000, 0.50000]
    #                 ]
    #     arr_positions = np.array(positions)
    #     arr_numbers = np.array([6]*12)
    #     cell = GeneralCell(arr_lat, arr_positions, arr_numbers)
    #     self.assertEqual(cell, self.cell)
    #
    #     arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
    #     positions = [
    #                     [0.00000, 0.00000, 0.00000],
    #                     [0.00000, 0.50000, 0.00000],
    #                     [0.33333, 0.00000, 0.00000],
    #                     [0.33333, 0.50000, 0.00000],
    #                     [0.66666, 0.00000, 0.00000],
    #                     [0.66666, 0.50000, 0.00000],
    #                     [0.16666, 0.25000, 0.50000],
    #                     [0.16666, 0.75000, 0.50000],
    #                     [0.50000, 0.25000, 0.50000],
    #                     [0.50000, 0.75000, 0.50000],
    #                     [0.83333, 0.25000, 0.50000],
    #                     [0.83333, 0.75000, 0.50000]
    #                 ]
    #     arr_positions = np.array(positions)
    #     arr_numbers = np.array([4]*12)
    #     cell = GeneralCell(arr_lat, arr_positions, arr_numbers)
    #     self.assertNotEqual(cell, self.cell)
    #
    #     arr_lat = np.array([[2.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
    #     positions = [
    #                     [0.00000, 0.00000, 0.00000],
    #                     [0.00000, 0.50000, 0.00000],
    #                     [0.33333, 0.00000, 0.00000],
    #                     [0.33333, 0.50000, 0.00000],
    #                     [0.66666, 0.00000, 0.00000],
    #                     [0.66666, 0.50000, 0.00000],
    #                     [0.16666, 0.25000, 0.50000],
    #                     [0.16666, 0.75000, 0.50000],
    #                     [0.50000, 0.25000, 0.50000],
    #                     [0.50000, 0.75000, 0.50000],
    #                     [0.83333, 0.25000, 0.50000],
    #                     [0.83333, 0.75000, 0.50000]
    #                 ]
    #     arr_positions = np.array(positions)
    #     arr_numbers = np.array([6]*12)
    #     cell = GeneralCell(arr_lat, arr_positions, arr_numbers)
    #     self.assertNotEqual(cell, self.cell)

    def test_get_speckle_num(self):
        self.assertEqual(self.cell.get_speckle_num(Specie("B")), 0)
        self.assertEqual(self.cell.get_speckle_num(Specie("C")), 12)

    def test_property(self):
        np.testing.assert_equal(self.cell.numbers, np.array([6] * 12))
        self.assertEqual(self.cell.comment, 'C12')

    def test_get_symmetry(self):
        sym = self.cell.get_spacegroup()
        self.assertEqual(sym, 'Im-3m (229)')

    def test_get_symmetry_permutation(self):
        sym_num = len(self.cell.get_symmetry_permutation())
        self.assertEqual(sym_num, 96)

    def test_is_primitive(self):
        self.assertFalse(self.cell.is_primitive())

    def test_degeneracy(self):
        sym_perm = self.cell.get_symmetry_permutation()
        self.assertEqual(self.cell.get_degeneracy(sym_perm), 1)

        ### more complex test
        arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
        positions = [[0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.00000],
                     [0.33333, 0.00000, 0.00000], [0.33333, 0.50000, 0.00000],
                     [0.66666, 0.00000, 0.00000], [0.66666, 0.50000, 0.00000],
                     [0.16666, 0.25000, 0.50000], [0.16666, 0.75000, 0.50000],
                     [0.50000, 0.25000, 0.50000], [0.50000, 0.75000, 0.50000],
                     [0.83333, 0.25000, 0.50000], [0.83333, 0.75000, 0.50000]]
        arr_positions = np.array(positions)
        arr_numbers = np.array([5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])
        gcell = GeneralCell(arr_lat, arr_positions, arr_numbers)
        self.assertEqual(gcell.get_degeneracy(sym_perm), 12)

        arr_numbers = np.array([5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])
        gcell = GeneralCell(arr_lat, arr_positions, arr_numbers)
        self.assertEqual(gcell.get_degeneracy(sym_perm), 6)

    def test_get_cartesian(self):
        arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 1.0]])
        positions = [[0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.00000],
                     [0.33333, 0.00000, 0.00000], [0.33333, 0.50000, 0.00000],
                     [0.66666, 0.00000, 0.00000], [0.66666, 0.50000, 0.00000],
                     [0.16666, 0.25000, 0.50000], [0.16666, 0.75000, 0.50000],
                     [0.50000, 0.25000, 0.50000], [0.50000, 0.75000, 0.50000],
                     [0.83333, 0.25000, 0.50000], [0.83333, 0.75000, 0.50000]]
        arr_positions = np.array(positions)
        arr_numbers = np.array([6] * 12)
        cell = GeneralCell(arr_lat, arr_positions, arr_numbers)

        cart_coor = cell.get_cartesian()
        cart_ans = np.array([[0., 0., 0.], [0., 1., 0.], [0.49998, 0.5, 0.5],
                             [0.49998, 1.5, 0.5], [0.99999, 0., 0.],
                             [0.99999, 1., 0.], [1.5, 0.5, 0.5],
                             [1.5, 1.5, 0.5], [1.99998, 0., 0.],
                             [1.99998, 1., 0.], [2.49999, 0.5, 0.5],
                             [2.49999, 1.5, 0.5]])
        self.assertTrue(np.allclose(cart_coor, cart_ans))

        arr_numbers = np.array([6, 6, 6, 5, 6, 5, 6, 6, 6, 6, 6, 6])
        cell = GeneralCell(arr_lat, arr_positions, arr_numbers)

        cart_coor = cell.get_cartesian(Specie('B'))
        cart_ans = np.array([[0.49998, 1.5, 0.5], [0.99999, 1., 0.]])

    def test_supercell(self):
        scale_mat = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 2]])
        scell = self.cell.supercell(scale_mat)
        arr_lat = np.array([[3.0, 0, 0], [0, 2.0, 0.0], [0, 0, 2.0]])
        positions = [[0., 0., 0.], [0., 0., 0.5], [0., 0.5,
                                                   0.], [0., 0.5, 0.5],
                     [0.16666, 0.25, 0.25], [0.16666, 0.25, 0.75],
                     [0.16666, 0.75, 0.25], [0.16666, 0.75, 0.75],
                     [0.33333, 0., 0.], [0.33333, 0., 0.5], [0.33333, 0.5, 0.],
                     [0.33333, 0.5, 0.5], [0.5, 0.25, 0.25], [0.5, 0.25, 0.75],
                     [0.5, 0.75, 0.25], [0.5, 0.75, 0.75], [0.66666, 0., 0.],
                     [0.66666, 0., 0.5], [0.66666, 0.5, 0.],
                     [0.66666, 0.5, 0.5], [0.83333, 0.25, 0.25],
                     [0.83333, 0.25, 0.75], [0.83333, 0.75, 0.25],
                     [0.83333, 0.75, 0.75]]
        arr_positions = np.array(positions)
        arr_numbers = np.array([6] * 24)
        ans_scell = GeneralCell(arr_lat, arr_positions, arr_numbers)
        self.assertTrue(np.allclose(scell.positions, arr_positions))