Beispiel #1
0
 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)
Beispiel #2
0
    def test_gen_nodup_exch(self):
        lattice = np.array([[5.0, 0.0000000000, 0.0000000000],
                            [2.5, 4.330127, 0.0000000000],
                            [0.0000000000, 0.0000000000, 20]])
        positions = np.array([[0.666667, 0.000000, 0.5281],
                              [0.000000, 0.333333, 0.5281],
                              [0.333333, 0.666667, 0.5281],
                              [0.000000, 0.000000, 0.6115],
                              [0.500000, 0.000000, 0.6115],
                              [0.000000, 0.500000, 0.6115],
                              [0.500000, 0.500000, 0.6115]])
        numbers = np.array([12, 12, 12, 28, 28, 28, 28])
        gcell = GeneralCell(lattice, positions, numbers)
        ocu_gen = OccupyGenerator(gcell)
        nodup_gen = ocu_gen.gen_nodup_exch(Specie('Mg'), Specie('Ni'), 1)
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 3)

        ocu_gen = OccupyGenerator(gcell)
        nodup_gen = ocu_gen.gen_nodup_exch(Specie('Mg'), Specie('Ni'), 2)
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 4)

        ocu_gen = OccupyGenerator(gcell)
        nodup_gen = ocu_gen.gen_nodup_exch(Specie('Mg'), Specie('Ni'), 3)
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 2)
Beispiel #3
0
 def setUp(self):
     latt = np.array([[0., 0.5, 0.53333333333], [0.5, 0., 0.56666666667],
                      [0.5, 0.5, 0.]])
     positions = np.array([[0., 0., 0.], [0.25, 0.25, 0.25]])
     numbers = np.array([30, 16])
     cell = GeneralCell(latt, positions, numbers)
     self.vasp_out = VaspOutput(cell)
Beispiel #4
0
    def to_general_cell(self):
        """
        The function used to convert the superlattice
        HermiteLattice to a GeneralCell instance.
        input aps for atome_position_s, which are atom positions
        of the unit basis.
        input numbers are element number of the corespoding positions.
        """
        # lat_coeff is represent as column vector
        # while ub and latt is row vector
        latt = np.matmul(self.lat_coeff, self.ub)

        # coor_unit_pos = np.matmul(self.upositions, self.ub)
        # o_unit_pos = np.matmul(coor_unit_pos, np.linalg.inv(self.lat_coeff))
        ########################################################
        # Tag: algorithm changed May be harmful!!!!!!!!
        ########################################################
        o_unit_pos = np.matmul(self.upositions, np.linalg.inv(self.lat_coeff))
        o_pos = self.get_frac_from_H(self.lat_coeff)

        l_of_positions = [
            i for i in map(lambda x: x + o_pos, list(o_unit_pos))
        ]
        # pdb.set_trace()
        pos = np.concatenate(l_of_positions, axis=0)

        n = self.lat_coeff.diagonal().prod()
        numbers = np.repeat(self.unumbers, n)

        # pdb.set_trace()
        return GeneralCell(latt, pos, numbers)
Beispiel #5
0
 def setUp(self):
     a_latt = np.array([[0.5, 0.5, -0.5], [-0.5, 0.5, 0.5],
                        [0.5, -0.5, 0.5]])
     a_pos = np.array([[0, 0, 0]])
     a_num = np.array([16])
     a_cell = GeneralCell(a_latt, a_pos, a_num)
     self.a_yaml = YamlOutput(a_cell, zoom=3)
Beispiel #6
0
 def setUp(self):
     self.bcc_base = np.array([[0.5, 0.5, -0.5], [-0.5, 0.5, 0.5],
                               [0.5, -0.5, 0.5]])
     self.bcc_u_position = np.array([[0, 0, 0]])
     self.bcc_u_n = np.array([0])
     self.bcc_uc = GeneralCell(self.bcc_base, self.bcc_u_position,
                               self.bcc_u_n)
Beispiel #7
0
    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([5, 6, 22, 6, 5, 6, 6, 29, 6, 6, 6, 6])
        self.p6cell = GeneralCell(arr_lat, arr_positions, arr_numbers)

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

        self.p6_restrc = SpaceGroupRestriction([6])
        self.p6orsym_restrc = SpaceGroupRestriction([6, 47])
Beispiel #8
0
 def setUp(self):
     latt = np.array([[0., 0.5, 0.53333333333], [0.5, 0., 0.56666666667],
                      [0.5, 0.5, 0.]])
     pos = np.array([[0., 0., 0.], [0.25, 0.25, 0.25]])
     numbers = np.array([30, 16])
     gcell = GeneralCell(latt, pos, numbers)
     self.vasp_out = VaspOutput(gcell)
     self.yaml_out = YamlOutput(gcell)
     self.io_s = GeneralIO(gcell)
Beispiel #9
0
 def gen_dup_unitary(self, n, sp):
     init_numbers = self.init_cell.numbers
     num_count = init_numbers.size  # number of atoms in structure
     i_speckle = sp.Z
     from itertools import combinations
     for comb_index in combinations(range(num_count), n):
         numbers = init_numbers.copy()
         for index in comb_index:
             numbers[index] = i_speckle
         yield GeneralCell(self.lattice, self.positions, numbers)
Beispiel #10
0
 def gen_dup(self, wy, n, sp):
     init_numbers = self.init_cell.numbers
     i_speckle = sp.Z
     wyckoffs = self.wyckoffs
     sp_ind = [i for i, w in enumerate(wyckoffs) if w is wy]
     # pdb.set_trace()
     for comb_index in combinations(sp_ind, n):
         numbers = init_numbers.copy()
         for index in comb_index:
             numbers[index] = i_speckle
         yield GeneralCell(self.lattice, self.positions, numbers)
Beispiel #11
0
    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.]])
Beispiel #12
0
    def gen_dup_of_ele(self, ele, n, sp):
        # ele is a Specie instance

        ele_num = ele.Z
        init_numbers = self.init_cell.numbers
        i_speckle = sp.Z
        sp_ind = [i for i, e in enumerate(init_numbers) if e == ele_num]

        for comb_index in combinations(sp_ind, n):
            numbers = init_numbers.copy()
            for index in comb_index:
                numbers[index] = i_speckle
            yield GeneralCell(self.lattice, self.positions, numbers)
Beispiel #13
0
 def gen_add_one_speckle(self, gen, wy, sp):
     atom = sp.Z
     id_db = dict()
     for cell in gen:
         wy_ele = zip(self.wyckoffs, cell.numbers)
         for index, tuple_w_e in enumerate(wy_ele):
             numbers_new = cell.numbers.copy()
             if tuple_w_e[0] == wy and atom != tuple_w_e[1]:
                 numbers_new[index] = atom
                 num_id = numbers2id(numbers_new)
                 if num_id not in id_db:
                     yield GeneralCell(cell.lattice, cell.positions,
                                       numbers_new)
                     id_db[num_id] = None
Beispiel #14
0
    def gen_dup_exch(self, sp1, sp2, n):
        init_numbers = self.init_cell.numbers
        n_sp1 = sp1.Z
        n_sp2 = sp2.Z
        sp1_ind = [i for i, e in enumerate(init_numbers) if e == n_sp1]
        sp2_ind = [i for i, e in enumerate(init_numbers) if e == n_sp2]

        for ex_sp1 in combinations(sp1_ind, n):
            for ex_sp2 in combinations(sp2_ind, n):
                numbers = init_numbers.copy()
                for ind_sp1, ind_sp2 in zip(ex_sp1, ex_sp2):
                    numbers[ind_sp1] = n_sp2
                    numbers[ind_sp2] = n_sp1
                yield GeneralCell(self.lattice, self.positions, numbers)
Beispiel #15
0
    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([5, 6, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6])
        self.cell = GeneralCell(arr_lat, arr_positions, arr_numbers)

        self.carbon_restrc = MinDistanceRestriction((Specie('C'), 0.85))
        self.boron_restrc = MinDistanceRestriction((Specie('B'), 1.01))
Beispiel #16
0
    def test_is_equivalent(self):
        # perm_sym = self.cell.get_symmetry_permutation()
        self.assertTrue(self.ocu_gen.is_equivalent(self.cell_a, self.cell_b))

        # cell_3A = GeneralCell(self.arr_lat, self.arr_positions, self.numbers_3A)
        # cell_3B = GeneralCell(self.arr_lat, self.arr_positions, self.numbers_3B)
        # cell_3C = GeneralCell(self.arr_lat, self.arr_positions, self.numbers_3C)
        # cell_3D = GeneralCell(self.arr_lat, self.arr_positions, self.numbers_3D)

        # self.assertTrue(self.ocu_gen.is_equivalent(cell_3A, cell_3B))
        # self.assertTrue(self.ocu_gen.is_equivalent(cell_3C, cell_3D))

        tri_num_A = np.array([28, 28, 28, 28, 51, 51, 50, 50, 22, 22, 22, 22])
        tri_num_B = np.array([28, 28, 28, 28, 51, 50, 50, 51, 22, 22, 22, 22])
        trinary_cell_A = GeneralCell(self.trinary_lat, self.trinary_positions, tri_num_A)
        trinary_cell_B = GeneralCell(self.trinary_lat, self.trinary_positions, tri_num_B)
        self.assertTrue(self.trinary_ocu_gen.is_equivalent(trinary_cell_A, trinary_cell_B))

        bin_num_A = np.array([30, 30, 30, 30, 30, 30, 30, 30, 50, 50, 16, 16, 16, 16, 16, 16])
        bin_num_B = np.array([30, 30, 30, 30, 30, 30, 30, 30, 16, 16, 50, 50, 16, 16, 16, 16])
        bin_cell_A = GeneralCell(self.binary_lat, self.binary_positions, bin_num_A)
        bin_cell_B = GeneralCell(self.binary_lat, self.binary_positions, bin_num_B)
        self.assertTrue(self.binary_ocu_gen.is_equivalent(bin_cell_A, bin_cell_B))
Beispiel #17
0
 def gen_add_one_speckle_of_ele(self, gen, ele, sp):
     ele_Z = ele.Z
     atom = sp.Z
     id_db = dict()
     for cell in gen:
         # site_ele = zip(self.wyckoffs, cell.numbers)
         for index, e in enumerate(cell.numbers):
             numbers_new = cell.numbers.copy()
             if e == ele_Z and e != atom:
                 numbers_new[index] = atom
                 num_id = numbers2id(numbers_new)
                 if num_id not in id_db:
                     yield GeneralCell(cell.lattice, cell.positions,
                                       numbers_new)
                     id_db[num_id] = None
Beispiel #18
0
    def __init__(self, settings, comment, element, speckle, nspeckle, zoom,
                 trs, refined, outmode, mpr):
        # read comment & zoom from setting file first
        # if not exist, read from cmd args, then default
        if zoom is None:
            try:
                zoom = settings['zoom']
            except:
                zoom = 1
        self.zoom = zoom

        if comment is None:
            try:
                comment = settings['comment']
            except:
                comment = 'default'
        self.comment = comment

        lat = np.array(settings['lattice'])
        pos = np.array(settings['positions'])
        num = np.array(settings['numbers'])
        self.cell = GeneralCell(lat * self.zoom, pos, num)

        self.element = element

        # Get number and index of target element
        if element is None:
            tgt_ele = int(num[1])
        else:
            tgt_ele = Specie(element).Z
        tgt_ele_index = np.where(num == tgt_ele)[0]

        self.s1, self.s2 = speckle
        self.n1, self.n2 = nspeckle
        # self.ele for function all-speckle-gen-of-ele in run
        self.ele = Specie.from_num(tgt_ele)

        # if there no restriction given then no restriction
        if trs != ():
            self.tr = trs[0]
        else:
            self.tr = None

        self.refined = refined
        self.outmode = outmode
        self.mpr = mpr

        self.n0 = tgt_ele_index.size - self.n1 - self.n2
Beispiel #19
0
    def _gen_dup_trinary_alloy(self, sp1, n1, sp2, n2):
        init_numbers = self.init_cell.numbers
        isp1 = sp1.Z
        isp2 = sp2.Z

        sp_ind_origin = [i for i, s in enumerate(init_numbers)]
        for sp1_comb_index in combinations(sp_ind_origin, n1):
            sp_ind_bin = [x for x in sp_ind_origin if x not in sp1_comb_index]
            for sp2_comb_index in combinations(sp_ind_bin, n2):
                numbers = init_numbers.copy()
                for i1, i2 in zip_longest(sp1_comb_index, sp2_comb_index):
                    if i1 is not None:
                        numbers[i1] = isp1
                    if i2 is not None:
                        numbers[i2] = isp2
                yield GeneralCell(self.lattice, self.positions, numbers)
Beispiel #20
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))
Beispiel #21
0
 def gen_add_one_speckle_unitary(self, gen, sp):
     """
     input a structure generator __ spg_cell(mostly nonduplicate)
     output a generator with one more speckle.
     This a method give duplicate structures which have one more speckle
     than the input structures.
     """
     atom = sp.Z
     id_db = dict()
     for cell in gen:
         for index, val in enumerate(cell.numbers):
             numbers_new = cell.numbers.copy()
             if atom != val:
                 numbers_new[index] = atom
                 num_id = numbers2id(numbers_new)
                 if num_id not in id_db:
                     yield GeneralCell(cell.lattice, cell.positions,
                                       numbers_new)
                     id_db[num_id] = None
Beispiel #22
0
    def test_HNFs_from_n(self):
        # use bcc data from <PHYSICAL REVIEW B 80, 014120 (2009)>
        # to test...
        results = [2, 3, 7, 5, 10, 7]
        for i, result in zip(range(2, 8), results):
            nodup_hnfs = SuperLatticeGenerator.hnfs_from_n(self.bcc_uc, i)
            self.assertEqual(len(nodup_hnfs), result)

        # hcp test
        hcp_b = np.array([[2.51900005, 0., 0.], [-1.25950003, 2.18151804, 0.],
                          [0., 0., 4.09100008]])
        hcp_positions = np.array([[0.33333334, 0.66666669, 0.25],
                                  [0.66666663, 0.33333331, 0.75]])
        hcp_numbers = np.array([0, 0])
        hcp_uc = GeneralCell(hcp_b, hcp_positions, hcp_numbers)
        # import pdb; pdb.set_trace()
        result = [
            len(SuperLatticeGenerator.hnfs_from_n(hcp_uc, i))
            for i in range(1, 10)
        ]
        self.assertEqual(result, [1, 3, 5, 11, 7, 19, 11, 34, 23])
Beispiel #23
0
    def test_to_general_cell(self):
        hnfs = SuperLatticeGenerator.hnfs_from_n_dups(self.bcc_uc, 4)
        hnf = hnfs[2]
        cell = hnf.to_general_cell()
        # print(cell.spg_cell)
        self.assertEqual(len(cell.spg_cell[2]), 4)

        zb_b = np.array([[3.82863, 0., 0.], [1.91431, 3.31569, 0.],
                         [1.91431, 1.10523, 3.12606]])
        zb_pos = np.array([[0., 0., 0.], [0.25, 0.25, 0.25]])
        zb_num = np.array([30, 16])
        zb_uc = GeneralCell(zb_b, zb_pos, zb_num)
        zbs = SuperLatticeGenerator.hnfs_from_n(zb_uc, 3)
        one_zb = zbs[1]
        cell = one_zb.to_general_cell()
        # print(cell.spg_cell)
        self.assertEqual(len(cell.spg_cell[2]), 6)

        h = np.array([[1, 0, 3], [0, 2, 2], [0, 0, 4]])
        strange_hnf = SuperLatticeCell(self.bcc_uc, h)
        shnf = strange_hnf.to_general_cell()
        self.assertEqual(len(shnf.spg_cell[2]), 8)
Beispiel #24
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)
Beispiel #25
0
 def test_from_to_gcell(self):
     gcell = GeneralCell(self.latt, self.pos, self.numbers)
     modcell = ModifiedCell.from_gcell(gcell)
     new_gcell = modcell.to_gcell()
     self.assertTrue(np.allclose(new_gcell.positions, gcell.positions))
Beispiel #26
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))
Beispiel #27
0
    def setUp(self):
        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]
                    ]
        self.arr_positions = np.array(positions)
        arr_numbers_0 = np.array([6]*12)
        self.cell = GeneralCell(self.arr_lat, self.arr_positions, arr_numbers_0)
        self.ocu_gen = OccupyGenerator(self.cell)

        tmp = arr_numbers_0.copy()
        tmp[0] = 5
        arr_numbers_a = tmp

        tmp = arr_numbers_0.copy()
        tmp[1] = 5
        arr_numbers_b = tmp

        self.cell_a = GeneralCell(self.arr_lat, self.arr_positions, arr_numbers_a)
        self.cell_b = GeneralCell(self.arr_lat, self.arr_positions, arr_numbers_b)

        # self.numbers_3A = np.array([5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6])
        # self.numbers_3B = np.array([5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6])

        # self.numbers_3C = np.array([5, 5, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6])
        # self.numbers_3D = np.array([5, 5, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6])

        self.trinary_lat = np.array([[1.5, 0., 0.], [0., 1.5, 0.], [0., 0., 1.5]])
        self.trinary_positions = np.array([[0.25,  0.25,  0.25],
                                           [0.25,  0.75,  0.75],
                                           [0.75,  0.25,  0.75],
                                           [0.75,  0.75,  0.25],
                                           [0.00,  0.00,  0.00],
                                           [0.50,  0.50,  0.00],
                                           [0.50,  0.00,  0.50],
                                           [0.00,  0.50,  0.50],
                                           [0.75,  0.75,  0.75],
                                           [0.75,  0.25,  0.25],
                                           [0.25,  0.75,  0.25],
                                           [0.25,  0.25,  0.75]])
        self.trinary_numbers = np.array([28, 28, 28, 28, 50, 50, 50, 50, 22, 22, 22, 22])
        self.trinary_cell = GeneralCell(self.trinary_lat, self.trinary_positions, self.trinary_numbers)
        self.trinary_ocu_gen = OccupyGenerator(self.trinary_cell)

        import os
        test_dir = os.path.join(os.path.dirname(__file__), 'test_files')
        file_name = os.path.join(test_dir, 'zns_f43m2x.yaml')
        zns2x = open(file_name, "r")
        binary = yaml.load(zns2x)
        self.binary_lat = np.array(binary["lattice"])
        self.binary_positions = np.array(binary["positions"])
        self.binary_numbers = np.array(binary["numbers"])
        self.binary_cell = GeneralCell(self.binary_lat, self.binary_positions, self.binary_numbers)
        self.binary_ocu_gen = OccupyGenerator(self.binary_cell)
Beispiel #28
0
 def get_cell(self):
     return GeneralCell(self.latt, self.pos, self.numbers)
Beispiel #29
0
 def test_test(self):
     zb_b = np.array([[3.82863, 0., 0.], [1.91431, 3.31569, 0.],
                      [1.91431, 1.10523, 3.12606]])
     zb_pos = np.array([[0., 0., 0.], [0.25, 0.25, 0.25]])
     zb_num = np.array([30, 16])
     zb_uc = GeneralCell(zb_b, zb_pos, zb_num)