Exemplo n.º 1
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))
Exemplo n.º 2
0
    def __init__(self, infile, comment, element, speckle, trs, refined,
                 outmode):
        # read comment & zoom from setting file first
        # if not exist, read from cmd args, then default
        self.cell = GeneralIO.from_file(infile)

        self.comment = comment or self.cell.comment

        self.element = element

        # Get number and index of target element
        num = self.cell.numbers
        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.n = tgt_ele_index.size

        self.s1, self.s2 = speckle
        # 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
Exemplo n.º 3
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])))
Exemplo n.º 4
0
 def test_all_speckle_gen_of_ele(self):
     big_gen = self.binary_ocu_gen.all_speckle_gen_of_ele(4, Specie("S"), Specie('Ti'))
     num_list = [1, 4, 4, 8]
     gen_list = [i for i in big_gen]
     for c, r_gen in zip(num_list, gen_list):
         r_length = len([i for i in r_gen])
         self.assertEqual(r_length, c)
Exemplo n.º 5
0
 def __init__(self, position, ele):
     self._position = tuple(position)
     if isinstance(ele, Specie):
         self._element = ele
     elif isinstance(ele, int):
         self._element = Specie.from_num(ele)
     else:
         self._element = Specie(ele)
Exemplo n.º 6
0
    def test_gen_nodup(self):
        nodup_gen = self.binary_ocu_gen.gen_nodup('c', 3, Specie('Ti'))
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 4)

        nodup_gen = self.binary_ocu_gen.gen_nodup_of_ele(Specie("S"), 3, Specie('Ti'))
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 4)
Exemplo n.º 7
0
    def test_gen_dup(self):
        dup_gen = self.binary_ocu_gen.gen_dup('c', 3, Specie('Ti'))
        l = [i for i in dup_gen]
        self.assertEqual(len(l), 56)

        # test case for provide element as input
        dup_gen = self.binary_ocu_gen.gen_dup_of_ele(Specie("S"), 3, Specie('Ti'))
        l = [i for i in dup_gen]
        self.assertEqual(len(l), 56)
Exemplo n.º 8
0
    def __init__(self, infile, cenele, radius, ele, refined):
        gcell = GeneralIO.from_file(infile)
        self.infile = infile
        self.basefname = os.path.basename(infile)

        self.mcell = ModifiedCell.from_gcell(gcell)

        self.clarifier = VerboseAtomRemoveClarifier(Specie(cenele), radius,
                                                    Specie(ele))
        self.refined = refined
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def test_gen_nodup_unitary(self):
        nodup_gen = self.ocu_gen.gen_nodup_unitary(3, Specie('B'))
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 9)

        nodup_gen = self.ocu_gen.gen_nodup_unitary(4, Specie('B'))
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 21)

        nodup_gen = self.ocu_gen.gen_nodup_unitary(1, Specie('B'))
        l = [i for i in nodup_gen]
        self.assertEqual(len(l), 1)
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def comment(self):
        from collections import Counter, OrderedDict
        atoms_name_list = list(
            map(lambda x: Specie.to_name(x), list(self.numbers)))
        d = Counter(atoms_name_list)
        ordered_atoms = OrderedDict(
            sorted(d.items(), key=lambda x: Specie(x[0]).Z))
        if 'G' in ordered_atoms:
            del ordered_atoms['G']

        comment = ''.join(
            ['{}{}'.format(k, v) for k, v in ordered_atoms.items()])
        return comment
Exemplo n.º 13
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))
Exemplo n.º 14
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
Exemplo n.º 15
0
    def run(self):
        # Create directory contain POSCARs
        import random
        import string

        rd_suffix = ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=5))
        working_path = os.getcwd()
        out_dir = os.path.join(
            working_path,
            'STRUCTURES_{0:}_{1:}'.format(self.comment, rd_suffix))
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        else:
            shutil.rmtree(out_dir)
            os.makedirs(out_dir)

        ogg = OccupyGenerator(self.cell)

        if self.tr is not None:
            tr = (Specie(self.tr[0]), self.tr[1])
            applied_restriction = MinDistanceRestriction(tr)

        for n1 in range(1, self.n - 1):
            for n2 in range(1, self.n - n1):
                g = ogg.gen_nodup_trinary_alloy(Specie(self.s1), n1,
                                                Specie(self.s2), n2)

                for n_count, c in enumerate(g):
                    if self.tr is not None:
                        condition = c.is_primitive(
                        ) and applied_restriction.is_satisfied(c)
                    else:
                        condition = c.is_primitive()

                    if condition:
                        if self.refined:
                            c = c.get_refined_pcell()
                        out = GeneralIO(c)

                        f_suffix = ''.join(
                            random.choices(string.ascii_uppercase +
                                           string.digits,
                                           k=4))
                        ofname = "STRUCTURE_{:}_{:}.{:}".format(
                            c.comment, f_suffix, self.outmode)
                        lastpath = os.path.join(out_dir, ofname)
                        out.write_file(lastpath)
Exemplo n.º 16
0
Arquivo: vasp.py Projeto: yuansr/ababe
    def from_string(content):
        # move empty line
        lines = [l for l in content.split('\n') if l.rstrip()]

        comment = lines[0]
        zoom = float(lines[1])
        lattice = np.around(np.array([[float(i) for i in line.split()]
                                      for line in lines[2:5]]),
                            decimals=6)
        if zoom < 0:
            # In vasp, a negative scale factor is treated as a volume. We need
            # to translate this to a proper lattice vector scaling.
            vol = abs(np.linalg.det(lattice))
            lattice *= (-zoom / vol)**(1 / 3)
        else:
            lattice *= zoom

        nsymbols = [Specie(s).Z for s in lines[5].split()]
        natoms = [int(i) for i in lines[6].split()]
        numbers = []
        for i, s in enumerate(natoms):
            numbers += s * [nsymbols[i]]
        numbers = np.array(numbers)

        positions = np.around(np.array([[float(i) for i in line.split()[0:3]]
                                        for line in lines[8:]]),
                              decimals=6)

        return lattice, positions, numbers
Exemplo n.º 17
0
Arquivo: yaml.py Projeto: yuansr/ababe
    def __init__(self, gcell):
        self.lattice = np.around(gcell.lattice, decimals=6)
        self.positions = np.around(gcell.positions, decimals=6)
        self.numbers = gcell.numbers

        atoms_name_list = list(
            map(lambda x: Specie.to_name(x), list(self.numbers)))
        d = Counter(atoms_name_list)
        ordered_atoms = OrderedDict(
            sorted(d.items(), key=lambda x: Specie(x[0]).Z))
        # remove Ghostatoms
        if 'G' in ordered_atoms:
            del ordered_atoms['G']

        self.comment = ''.join(
            ['{}{}'.format(k, v) for k, v in ordered_atoms.items()])
Exemplo n.º 18
0
 def test_all_speckle_gen_unitary(self):
     big_gen = self.ocu_gen.all_speckle_gen_unitary(4, Specie('B'))
     num_list = [1, 5, 9, 21]
     gen_list = [i for i in big_gen]
     for c, r_gen in zip(num_list, gen_list):
         r_length = len([i for i in r_gen])
         self.assertEqual(r_length, c)
Exemplo n.º 19
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.]])
Exemplo n.º 20
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())
Exemplo n.º 21
0
 def test_equal(self):
     s1 = Site((1, 2, 0), 'S')
     s2 = Site((1, 2, 0), Specie('S'))
     s3 = Site((1, 2, 0), 16)
     self.assertEqual(s1, s1)
     self.assertEqual(s1, s2)
     self.assertEqual(s1, s3)
Exemplo n.º 22
0
 def test_gen_2nodup_gen(self):
     init_gen = (i for i in [self.cell])
     add_one_speckle_gen = self.ocu_gen.gen_add_one_speckle_unitary(init_gen, Specie("B"))
     # l = [s for s in add_one_speckle_gen]
     nodup_gen = self.ocu_gen.gen_2nodup_gen(add_one_speckle_gen)
     l = [s for s in nodup_gen]
     # print(l)
     self.assertEqual(len(l), 1)
Exemplo n.º 23
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)
Exemplo n.º 24
0
Arquivo: io.py Projeto: yuansr/ababe
    def __init__(self, gcell, zoom=1):
        self.lattice = gcell.lattice
        self.positions = gcell.positions
        self.numbers = gcell.numbers

        self.atoms_name_list = list(
            map(lambda x: Specie.to_name(x), list(self.numbers)))

        self.zoom = zoom
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
0
    def __init__(self, numbers):
        self._lattice = np.array(_buckyball["lattice"])
        numbers = np.array(numbers)

        # Sorting positions (x,y,z)
        init_positions = np.array(_buckyball["positions"])
        init_index = self._get_new_id_seq(init_positions, numbers)
        self._positions = init_positions[init_index]

        self._atom_numbers = numbers
        self._spg_cell = (self._lattice, self._positions, self._atom_numbers)
        self._carbon = Specie("C")
        self._sym_perm = list(_perm_table)
Exemplo n.º 28
0
    def run(self):
        # Create directory contain POSCARs
        import random
        import string

        rd_suffix = ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=5))
        working_path = os.getcwd()
        out_dir = os.path.join(
            working_path,
            'STRUCTURES_{0:}_{1:}'.format(self.comment, rd_suffix))
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        else:
            shutil.rmtree(out_dir)
            os.makedirs(out_dir)

        ogg = OccupyGenerator(self.cell)
        g = ogg.gen_nodup_of_ele(self.ele, self.n, self.speckle)
        # sym for getting degeneracy
        sym_perm = self.cell.get_symmetry_permutation()

        if self.tr is not None:
            tr = (Specie(self.tr[0]), self.tr[1])
            applied_restriction = MinDistanceRestriction(tr)

        for n_count, c in enumerate(g):
            if self.mpr:
                if self.tr is not None:
                    condition = c.is_primitive(
                    ) and applied_restriction.is_satisfied(c)
                else:
                    condition = c.is_primitive()
            else:
                if self.tr is not None:
                    condition = applied_restriction.is_satisfied(c)
                else:
                    condition = True

            if condition:
                if self.refined:
                    c = c.get_refined_pcell()
                out = GeneralIO(c)
                f_suffix = ''.join(
                    random.choices(string.ascii_uppercase + string.digits,
                                   k=4))
                ofname = "STRUCTURE_{:}_D{:}D_{:}.{:}".format(
                    c.comment, c.get_degeneracy(sym_perm), f_suffix,
                    self.outmode)
                lastpath = os.path.join(out_dir, ofname)
                out.write_file(lastpath)
Exemplo n.º 29
0
    def run(self):
        # Create directory contain POSCARs
        import random
        import string

        rd_suffix = ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=4))
        working_path = os.getcwd()
        out_dir = os.path.join(
            working_path,
            'STRUCTURES_{0:}_{1:}'.format(self.comment, rd_suffix))
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        else:
            shutil.rmtree(out_dir)
            os.makedirs(out_dir)

        ogg = OccupyGenerator(self.cell)
        gg = ogg.all_speckle_gen_of_ele(self.nmax, self.ele, self.speckle)

        if self.tr is not None:
            tr = (Specie(self.tr[0]), self.tr[1])
            applied_restriction = MinDistanceRestriction(tr)

        for i, outer_gen in enumerate(gg):
            # print("Processing: {0:3}s substitue {1:2d}...".format(speckle, i+1))
            for n_count, c in enumerate(outer_gen):
                if self.mpr:
                    if self.tr is not None:
                        condition = c.is_primitive(
                        ) and applied_restriction.is_satisfied(c)
                    else:
                        condition = c.is_primitive()
                else:
                    if self.tr is not None:
                        condition = applied_restriction.is_satisfied(c)
                    else:
                        condition = True

                if condition:
                    if self.refined:
                        c = c.get_refined_pcell()
                    out = GeneralIO(c)

                    f_suffix = ''.join(
                        random.choices(string.ascii_uppercase + string.digits,
                                       k=4))
                    ofname = "STRUCTURE_{:}_{:}.{:}".format(
                        c.comment, f_suffix, self.outmode)
                    lastpath = os.path.join(out_dir, ofname)
                    out.write_file(lastpath)
Exemplo n.º 30
0
    def setUp(self):
        self.latt = np.array([[4.898979, 0.000000, 0.000000],
                              [2.449490, 4.242641, 0.000000],
                              [1.632993, -0.000000, 4.618802]])
        self.pos = np.array([[0.208333, 0.333333, 0.375000],
                             [0.375000, 0.000000, 0.875000],
                             [0.541667, 0.666667, 0.375000],
                             [0.708333, 0.333333, 0.875000],
                             [0.875000, 0.000000, 0.375000],
                             [0.000000, 0.000000, 0.000000],
                             [0.166667, 0.666667, 0.500000],
                             [0.333333, 0.333333, 0.000000],
                             [0.500000, 0.000000, 0.500000],
                             [0.666667, 0.666667, 0.000000],
                             [0.833333, 0.333333, 0.500000],
                             [0.041667, 0.666667, 0.875000]])
        self.numbers = np.array(
            [16, 16, 16, 16, 55, 30, 30, 30, 30, 30, 30, 55])
        self.modcell = ModifiedCell(self.latt, self.pos, self.numbers)

        ele = Specie('Zn')
        r = 2
        self.nearZnClarifier = VerboseAtomRemoveClarifier(
            Specie('Cs'), r, Specie('Zn'))