Ejemplo n.º 1
0
 def setUp(self):
     g = GhostSpecie()
     b = Specie("B")
     self.sites = [[[b, b], [g, g]], [[b, g], [g, b]]]
     self.sg = SitesGrid(self.sites)
     self.allg0 = SitesGrid.sea(2, 2, 2, GhostSpecie())
     self.allg = SitesGrid.sea(4, 2, 2, GhostSpecie())
Ejemplo n.º 2
0
    def test_get_cell(self):
        c = Specie("Cu")
        t = Specie("Ti")
        m = [[-0.5, -0.5, -0.5], [-0.5, 0.5, 0.5], [0.5, -0.5, 0.5]]

        sites01 = [[[c]]]
        sites02 = [[[t, c, t], [t, t, c]]]
        sg01 = SitesGrid(sites01)
        sg02 = SitesGrid(sites02)
        cstru01 = CStru(m, sg01)
        cstru02 = CStru(m, sg02)
        lat01, pos01, num01 = cstru01.get_cell()
        lat02, pos02, num02 = cstru02.get_cell()
        self.assertTrue(
            np.allclose(
                lat01,
                np.array([[-0.5, -0.5, -0.5], [-0.5, 0.5, 0.5],
                          [0.5, -0.5, 0.5]])))
        self.assertTrue(np.allclose(pos01, np.array([[0, 0, 0]])))
        self.assertTrue(np.allclose(num01, np.array([29])))

        self.assertTrue(
            np.allclose(
                lat02,
                np.array([[-0.5, -0.5, -0.5], [-1, 1, 1], [1.5, -1.5, 1.5]])))
        self.assertTrue(
            np.allclose(
                pos02,
                np.array([[0, 0, 0], [0, 0, 1 / 3], [0, 0,
                                                     2 / 3], [0, 1 / 2, 0],
                          [0, 1 / 2, 1 / 3], [0, 1 / 2, 2 / 3]])))
        self.assertTrue(np.allclose(num02, np.array([22, 29, 22, 22, 22, 29])))
Ejemplo n.º 3
0
    def test_update_isoset(self):
        c = Specie("Cu")
        t = Specie("Ti")
        m = [[-0.5, -0.5, -0.5],
             [-0.5,  0.5,  0.5],
             [ 0.5, -0.5,  0.5]]
        ele_sea = SitesGrid.sea(2, 2, 2, c)
        cell_mother_stru = CStru(m, ele_sea).get_cell()
        sym = get_symmetry(cell_mother_stru, symprec=1e-5)
        ops = [(r, t) for r, t in zip(sym['rotations'], sym['translations'])]
        sym_perm = sogen.get_permutation_cell(cell_mother_stru)

        sites_0 = [[[c, c],
                    [c, c]],

                   [[c, c],
                    [t, c]]]
        sg_0 = SitesGrid(sites_0)
        cstru01 = CStru(m, sg_0)
        number01 = cstru01.get_cell()[2]

        isoset_init = set()
        isoset_init_copy = isoset_init.copy()
        isoset_a01 = sogen._update_isoset(isoset_init, number01, sym_perm)
        self.assertNotEqual(isoset_a01, isoset_init_copy)
        self.assertIsInstance(isoset_a01, set)

        isoset_a01_copy = isoset_a01.copy()
        isoset_a02 = sogen._update_isoset(isoset_a01, number01, sym_perm)
        self.assertEqual(isoset_a02, isoset_a01_copy)
        self.assertLessEqual(len(isoset_a01), len(ops))
Ejemplo n.º 4
0
 def test_gen_speckle(self):
     c = Specie("Cu")
     t = Specie("Ti")
     sites = [[[c, c], [t, t]], [[c, t], [t, c]]]
     self.sg = SitesGrid(sites)
     gen = SitesGrid.gen_speckle(Specie("Cu"), (2, 2, 2), Specie("Ti"), 4)
     from collections import Iterator
     self.assertIsInstance(gen, Iterator)
     self.assertIn(self.sg, gen)
     self.assertEqual(next(gen).to_array().sum(), 204)
     self.assertEqual(next(gen).to_array().sum(), 204)
Ejemplo n.º 5
0
    def test_gen_nodup_cstru(self):
        c = Specie("Cu")
        t = Specie("Ti")
        m = [[-0.5, -0.5, -0.5],
             [-0.5,  0.5,  0.5],
             [ 0.5, -0.5,  0.5]]
        ele_sea = SitesGrid.sea(2, 2, 2, c)
        cell_mother_stru = CStru(m, ele_sea).get_cell()
        sym = get_symmetry(cell_mother_stru, symprec=1e-3)
        ops = [(r, t) for r, t in zip(sym['rotations'], sym['translations'])]

        sites_0 = [[[c, c],
                    [c, c]],

                   [[c, c],
                    [t, c]]]
        sg_0 = SitesGrid(sites_0)
        cstru01 = CStru(m, sg_0)

        gen_01 = sogen.gen_nodup_cstru(m, c, (2,2,2), t, 1)
        nodup_01 = [stru for stru in gen_01]
        self.assertEqual(len(nodup_01), 1)

        gen_02 = sogen.gen_nodup_cstru(m, c, (1,2,8), t, 4)
        nodup_02 = [stru for stru in gen_02]
        # eq_(len(nodup_02), 51)

        m_tri = [[0, 0, 20],
                        [1, 0, 0],
                        [0.5, 0.8660254, 0]]
        ele_sea = SitesGrid.sea(1, 3, 3, c)
        cell_mother_stru = CStru(m, ele_sea).get_cell()
        sym = get_symmetry(cell_mother_stru, symprec=1e-3)
        ops = [(r, t) for r, t in zip(sym['rotations'], sym['translations'])]

        sites_0 = [[[c, c, c],
                    [c, c, c],
                    [c, c, c]]]
        sg_0 = SitesGrid(sites_0)
        cstru01 = CStru(m, sg_0)

        gen_01 = sogen.gen_nodup_cstru(m_tri, c, (1,3,3), t, 2)
        nodup_01 = [stru for stru in gen_01]
        self.assertEqual(len(nodup_01), 2)

        gen_02 = sogen.gen_nodup_cstru(m_tri, c, (1,3,3), t, 3)
        nodup_02 = [stru for stru in gen_02]
        self.assertEqual(len(nodup_02), 4)

        gen_03 = sogen.gen_nodup_cstru(m_tri, c, (1,5,5), t, 2)
        nodup_03 = [stru for stru in gen_03]
        self.assertEqual(len(nodup_03), 4)
Ejemplo n.º 6
0
def gen_nodup_cstru(lattice, sea_ele, size, speckle, num):
    d, w, l = size
    ele_sea = SitesGrid.sea(d, w, l, sea_ele)
    cell_mother_stru = CStru(lattice, ele_sea).get_cell()

    sym_perm = get_permutation_cell(cell_mother_stru)

    # For testing: Show that the first unit matrix convert to range(num) perm_operator
    # print(sym_perm[0])

    gen_dup_cstrus = CStru.gen_speckle(lattice, sea_ele, size, speckle, num)

    # Add the progress bar when looping
    from scipy.special import comb
    number_of_structures = comb((d * w * l), num)
    bar = ProgressBar(max_value=number_of_structures)

    isoset = set()
    for cstru in bar(gen_dup_cstrus):
        b, pos, atom_num = cstru.get_cell()
        #id_cstru = _get_id_seq(pos, atom_num)
        id_cstru = _get_atom_seq_identifier(atom_num)
        # print(id_cstru)
        if id_cstru not in isoset:
            # print(len(sym_perm))
            # print(len(isoset))
            # print(cstru.get_array())
            yield cstru
            _update_isoset(isoset, atom_num, sym_perm)
Ejemplo n.º 7
0
 def __init__(self, goal_num):
     self.goal_num = goal_num
     m = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
     self.delta = 2.1  # the distance threshold to collect neighbors
     sg = SitesGrid([[[GhostSpecie() for _ in range(goal_num)]
                      for _ in range(goal_num)] for _ in range(goal_num)])
     self.bg = CStru(m, sg)
     self.start_position = self.bg.get_midpoint()
Ejemplo n.º 8
0
    def setUp(self):
        self.m = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        g = GhostSpecie()
        b = Specie("B")
        self.sites = [[[g, b], [g, g]], [[b, b], [b, g]]]

        self.arr = np.array([0, 5, 0, 0, 5, 5, 5, 0]).reshape([2, 2, 2])
        self.sg = SitesGrid(self.sites)
        self.s = CStru(self.m, self.sg)
Ejemplo n.º 9
0
    def test_equal(self):
        m_0 = [[1, 1, 1], [0, 0, 1], [1, 0, 0]]
        g = GhostSpecie()
        b = Specie("B")
        sites_0 = [[[b, b], [g, g]], [[b, g], [g, b]]]
        sg_0 = SitesGrid(sites_0)

        diff_m = CStru(m_0, self.sg)
        diff_s = CStru(self.m, sg_0)
        self.assertEqual(self.s, self.s)
        self.assertNotEqual(diff_m, self.s)
        self.assertNotEqual(diff_s, self.s)
Ejemplo n.º 10
0
    def test_is_speckle_disjunct(self):
        g = GhostSpecie()
        b = Specie('B')
        m = [[0, 0, 20],
             [1, 0, 0],
             [0.5, 0.8660254, 0]]
        # ele_sea = SitesGrid.sea(4, 4, 1, b)
        # cell_mother_stru = CStru(m, ele_sea).get_cell()
        # sym = get_symmetry(cell_mother_stru, symprec=1e-3)
        # ops = [(r, t) for r, t in zip(sym['rotations'], sym['translations'])]

        sites_0 = [[[g, g, b, b],
                    [b, b, b, b],
                    [b, b, b, b],
                    [b, b, b, b]]]
        sg_0 = SitesGrid(sites_0)
        cstru00 = CStru(m, sg_0)

        self.assertFalse(sogen.is_speckle_disjunct(cstru00, g))

        sites_1 = [[[g, b, b, g],
                    [b, b, b, b],
                    [b, b, b, b],
                    [b, b, b, b]]]
        sg_1 = SitesGrid(sites_1)
        cstru01 = CStru(m, sg_1)

        self.assertFalse(sogen.is_speckle_disjunct(cstru01, g))


        sites_2 = [[[g, b, b, b],
                    [b, g, b, b],
                    [b, b, b, b],
                    [b, b, b, b]]]
        sg_2 = SitesGrid(sites_2)
        cstru02 = CStru(m, sg_2)

        self.assertTrue(sogen.is_speckle_disjunct(cstru02, g))
Ejemplo n.º 11
0
 def test_random_fill(self):
     r = SitesGrid.random_fill(GhostSpecie(), (2, 2, 2), Specie("B"))
     self.assertIn(r.to_array().sum(), [5 * x for x in range(9)])
Ejemplo n.º 12
0
 def test_from_array(self):
     arr = np.array([5, 5, 0, 0, 5, 0, 0, 5]).reshape([2, 2, 2])
     ss = SitesGrid.from_array(arr)
     self.assertEqual(ss, self.sg)
Ejemplo n.º 13
0
 def test_equal(self):
     other = SitesGrid.sea(4, 2, 2, Specie("Ti"))
     self.assertNotEqual(other, self.allg)
     self.assertNotEqual(None, self.allg)
Ejemplo n.º 14
0
class testSitesGrid(unittest.TestCase):
    def setUp(self):
        g = GhostSpecie()
        b = Specie("B")
        self.sites = [[[b, b], [g, g]], [[b, g], [g, b]]]
        self.sg = SitesGrid(self.sites)
        self.allg0 = SitesGrid.sea(2, 2, 2, GhostSpecie())
        self.allg = SitesGrid.sea(4, 2, 2, GhostSpecie())

    def test_properties(self):
        # ok_(np.allclose(self.g.base_vector,
        # np.array(m, dtype=np.float64).reshape((3,3))))
        self.assertEqual(self.allg.depth, 4)
        self.assertEqual(self.allg.length, 2)
        self.assertEqual(self.allg.width, 2)
        self.assertEqual(self.sg.sites, self.sites)

    def test_get(self):
        self.assertEqual(self.sg[0, 1, 1], GhostSpecie())

        self.sg[0, 1, 1] = Specie("B")
        self.assertEqual(self.sg[0, 1, 1], Specie("B"))

    def test_equal(self):
        other = SitesGrid.sea(4, 2, 2, Specie("Ti"))
        self.assertNotEqual(other, self.allg)
        self.assertNotEqual(None, self.allg)

    def test_deepCopy(self):
        g_copy = self.allg.deepCopy()
        self.assertEqual(g_copy, self.allg)
        self.assertNotEqual(id(g_copy), id(self.allg))
        # assert_not_equal(id(g_copy[0, 0, 0]), id(g_copy[0, 0, 0]))

    def test_hash(self):
        pass

    def test_to_array(self):
        a = np.array([0] * 8).reshape((2, 2, 2))
        self.assertTrue(np.allclose(self.allg0.to_array(), a))
        b = np.array([5, 5, 0, 0, 5, 0, 0, 5]).reshape((2, 2, 2))
        self.assertTrue(np.allclose(self.sg.to_array(), b))

    def test_from_array(self):
        arr = np.array([5, 5, 0, 0, 5, 0, 0, 5]).reshape([2, 2, 2])
        ss = SitesGrid.from_array(arr)
        self.assertEqual(ss, self.sg)

    def test_random_fill(self):
        r = SitesGrid.random_fill(GhostSpecie(), (2, 2, 2), Specie("B"))
        self.assertIn(r.to_array().sum(), [5 * x for x in range(9)])

    def test_gen_speckle(self):
        c = Specie("Cu")
        t = Specie("Ti")
        sites = [[[c, c], [t, t]], [[c, t], [t, c]]]
        self.sg = SitesGrid(sites)
        gen = SitesGrid.gen_speckle(Specie("Cu"), (2, 2, 2), Specie("Ti"), 4)
        from collections import Iterator
        self.assertIsInstance(gen, Iterator)
        self.assertIn(self.sg, gen)
        self.assertEqual(next(gen).to_array().sum(), 204)
        self.assertEqual(next(gen).to_array().sum(), 204)