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])))
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)
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_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))
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()
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)
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)
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)
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))