Exemplo n.º 1
0
    def run(self):
        import random
        import string

        # Create a dir contains suplat files
        working_path = os.getcwd()
        suplat_dir = os.path.join(working_path,
                                  'SUPLAT_{:}'.format(self.comment))
        if not os.path.exists(suplat_dir):
            os.makedirs(suplat_dir)
        else:
            shutil.rmtree(suplat_dir)
            os.makedirs(suplat_dir)

        for hnf in self.hnfs:
            rd_suffix = ''.join(random.choices(string.ascii_uppercase
                                               + string.digits, k=4))
            sl_origin = hnf.to_general_cell()
            sl = sl_origin.get_shaped_cell()

            out = GeneralIO(sl)

            ofname = "SUPLAT_{:}_{:}.{:}".format(self.v, rd_suffix, self.outmode)
            lastpath = os.path.join(suplat_dir, ofname)
            out.write_file(lastpath)
Exemplo n.º 2
0
    def run(self):
        import tempfile
        working_path = os.getcwd()

        self.mcell.perturb(self.radius)
        gcell = self.mcell.to_gcell()

        out = GeneralIO(gcell)
        ofname = "{:}_PURB.vasp".format(self.basefname.split('.')[0])

        print("PROCESSING: {:}".format(self.infile))
        out.write_file(ofname)
Exemplo n.º 3
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.º 4
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.º 5
0
    def run(self):
        import tempfile
        working_path = os.getcwd()

        new_mcell = self.clarifier.clarify(self.mcell)
        gcell = new_mcell.to_gcell()
        # todo: add feature- to convcell.
        if self.refined:
            gcell = gcell.get_refined_pcell()

        out = GeneralIO(gcell)
        ofname = "{:}_ACLR.vasp".format(self.basefname.split('.')[0])

        print("PROCESSING: {:}".format(self.infile))
        out.write_file(ofname)
Exemplo n.º 6
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.º 7
0
def pcell(input, outmode):
    from ababe.io.io import GeneralIO
    import os
    infile = click.format_filename(input)
    basefname = os.path.basename(infile)

    gcell = GeneralIO.from_file(infile)
    pcell = gcell.get_refined_pcell()

    out = GeneralIO(pcell)

    if outmode == 'stdio':
        out.write_file(fname=None, fmt='vasp')
    else:
        print("PROCESSING: {:}".format(infile))
        ofname = "{:}_PRIMC.{:}".format(basefname.split('.')[0], outmode)
        out.write_file(ofname)
Exemplo n.º 8
0
def concell(files, outmode, verbose):
    from ababe.io.io import GeneralIO
    import os
    for infile in files:
        basefname = os.path.basename(infile)

        gcell = GeneralIO.from_file(infile)
        pcell = gcell.get_refined_cell()

        out = GeneralIO(pcell)

        if outmode == 'stdio':
            out.write_file(fname=None, fmt='vasp')
        else:
            if verbose: print("PROCESSING: {:}".format(infile))
            ofname = "{:}_CONC.{:}".format(basefname.split('.')[0], outmode)
            out.write_file(ofname)
Exemplo n.º 9
0
def supcell(file, scale, outmode):
    from ababe.io.io import GeneralIO
    import os
    import numpy as np

    basefname = os.path.basename(file)

    gcell = GeneralIO.from_file(file)

    scale_matrix = np.diag(np.array(scale))
    sc = gcell.supercell(scale_matrix)

    out = GeneralIO(sc)

    print("PROCESSING: {:}".format(file))
    if outmode == 'stdio':
        out.write_file(fname=None, fmt='vasp')
    else:
        ofname = "{:}_SUPC.{:}".format(basefname.split('.')[0], outmode)
        out.write_file(ofname)
Exemplo n.º 10
0
    def run(self):
        import tempfile
        working_path = os.getcwd()

        for infile in self.files:
            basefname = os.path.basename(infile)

            # read
            gcell = GeneralIO.from_file(infile)

            mcell = ModifiedCell.from_gcell(gcell)
            new_mcell = self.clarifier.clarify(mcell)
            gcell = new_mcell.to_gcell()
            # todo: add feature- to convcell.
            if self.refined:
                gcell = gcell.get_refined_pcell()

            out = GeneralIO(gcell)
            ofname = "{:}_ACLR.vasp".format(basefname.split('.')[0])

            print("PROCESSING: {:}".format(infile))
            out.write_file(ofname)
Exemplo n.º 11
0
def perturb(files, radius, outmode, verbose):
    from ababe.io.io import GeneralIO
    from ababe.stru.scaffold import ModifiedCell
    from ababe.stru.element import Specie
    import os
    for infile in files:
        basefname = os.path.basename(infile)

        # read
        gcell = GeneralIO.from_file(infile)
        # process
        mcell = ModifiedCell.from_gcell(gcell)
        mcell.perturb(radius)

        # write
        out = GeneralIO(mcell.to_gcell())

        if outmode == 'stdio':
            out.write_file(fname=None, fmt='vasp')
        else:
            if verbose: print("PROCESSING: {:}".format(infile))
            ofname = "{:}_PURB.{:}".format(basefname.split('.')[0], outmode)
            out.write_file(ofname)
Exemplo n.º 12
0
class TestGeneralIO(unittest.TestCase):
    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)

    def test_vasp_from_file(self):
        filename = os.path.join(testdata_dir, "POSCAR_")
        gcell = GeneralIO.from_file(filename)
        expect_latt = np.array([[2.8284, 0.0000, 0.0000],
                                [0.0000, 2.8284, 0.0000],
                                [0.0000, 0.0000, 12.0000]])
        expect_positions = np.array([[0., 0., 0.666667], [0., 0.5, 0.250000],
                                     [0., 0.5, 0.583333], [0., 0.5, 0.916667],
                                     [0.5, 0., 0.083333], [0.5, 0., 0.416667],
                                     [0.5, 0., 0.750000], [0.5, 0.5,
                                                           0.833333]])

        expect_numbers = [30, 16, 16, 16, 16, 16, 16, 30]

        self.assertTrue(np.allclose(gcell.lattice, expect_latt))
        self.assertTrue(np.allclose(gcell.positions, expect_positions))
        self.assertTrue(np.allclose(gcell.numbers, expect_numbers))

    def test_yaml_from_file(self):
        filename = os.path.join(testdata_dir, "zns.yaml")
        gcell = GeneralIO.from_file(filename)

        expect_latt = np.array([[0., 2., 2.], [2., 0., 2.], [2., 2., 0.]])
        expect_positions = np.array([[0., 0., 0.], [0.25, 0.25, 0.25]])
        expect_numbers = np.array([30, 16])
        self.assertTrue(np.allclose(gcell.lattice, expect_latt))
        self.assertTrue(np.allclose(gcell.positions, expect_positions))
        self.assertTrue(np.allclose(gcell.numbers, expect_numbers))

    def test_vasp_write_file(self):
        ##################################################
        # vasp POSCAR write test
        ##################################################
        tmp_file = os.path.join(testdata_dir, "testing.vasp")
        self.io_s.write_file(tmp_file)

        with open(tmp_file, 'r') as testing_file:
            data = testing_file.read()

        self.assertEqual(data, str(self.vasp_out))
        os.remove(tmp_file)

        #################
        tmp_file = os.path.join(testdata_dir, "POSCAR______")
        self.io_s.write_file(tmp_file)

        with open(tmp_file, 'r') as testing_file:
            data = testing_file.read()

        self.assertEqual(data, str(self.vasp_out))
        os.remove(tmp_file)

        ###################
        tmp_file = os.path.join(testdata_dir, "i_have_noname")
        self.io_s.write_file(tmp_file, fmt='vasp')

        with open(tmp_file, 'r') as testing_file:
            data = testing_file.read()

        self.assertEqual(data, str(self.vasp_out))
        os.remove(tmp_file)

    def test_yaml_write_file(self):
        ##################################################
        # yaml write test
        ##################################################
        tmp_file = os.path.join(testdata_dir, "testing.yaml")
        self.io_s.write_file(tmp_file)

        with open(tmp_file, 'r') as testing_file:
            data = testing_file.read()

        self.assertEqual(data, str(self.yaml_out))
        os.remove(tmp_file)

        ########################3
        tmp_file = os.path.join(testdata_dir, "testing")
        self.io_s.write_file(tmp_file, fmt='yaml')

        with open(tmp_file, 'r') as testing_file:
            data = testing_file.read()

        self.assertEqual(data, str(self.yaml_out))
        os.remove(tmp_file)

    def test_noname_write_file(self):
        self.io_s.write_file(fmt="vasp")
        pass