Exemple #1
0
    def test_cons_specific_volume(self):
        wanted = [2, 6, 12, 41]
        got = []
        cg = CG(self.fcc_pcell)
        for v in [1, 2, 3, 4]:
            con = cg.cons_specific_volume([(1, 5), (2,)], v)
            got.append(len([i for i in con]))

        self.assertEqual(got, wanted)
Exemple #2
0
    def test_cons_specific_volume_c(self):
        wanted = [7]
        got = []
        cg = CG(self.fcc_pcell)
        for v in [4]:
            con = cg.cons_specific_volume([(1, 5), (2,)], v, e_num=(3, 1))
            got.append(len([i for i in con]))

        self.assertEqual(got, wanted)
Exemple #3
0
def conf(cell_filename, comment, pmode, cmode, dimension, volume, element,
         substitutes, number, symprec, comprec, verbose):
    """
    <parent_cell_file> is the parent cell to generating configurations by sites disorder.\n
    The non-primitive cell can only used as argument when '--pmode=sc'.\n
    Command line tool only provide configurations generator for elements disorder, for more flexible usage such as specific site disorder, please see document http:// , or use python library directly.
    """
    cell = read_vasp(cell_filename)
    cg = ConfigurationGenerator(cell, symprec)
    if pmode == 'varv' and cmode == 'vc':
        click.secho("Expanding and generating configurations: ")
        click.secho("(may take much time)",
                    blink=True,
                    bold=True,
                    bg='magenta',
                    fg='white')
        spinner = Spinner()
        spinner.start()
        (min_v, max_v) = volume
        if min_v == -1:
            min_v = 1
        sites = _get_sites(list(cell.atoms), element, substitutes)
        confs = cg.cons_max_volume(sites,
                                   max_v,
                                   min_volume=min_v,
                                   dimension=dimension,
                                   symprec=symprec)
        for idx, c in enumerate(confs):
            c = c.get_primitive_cell()
            filename = '{:s}_id{:d}'.format(comment, idx)
            write_vasp(c, filename)
        spinner.stop()
        click.secho("DONE", bold=True, bg='green', fg='white')
    elif pmode == 'svc' and cmode == 'vc':
        click.secho("Expanding and generating configurations: ")
        click.secho("(may take much time)",
                    blink=True,
                    bold=True,
                    bg='magenta',
                    fg='white')
        spinner = Spinner()
        spinner.start()
        (min_v, max_v) = volume
        sites = _get_sites(list(cell.atoms), element, substitutes)
        confs = cg.cons_specific_volume(sites,
                                        volume=max_v,
                                        e_num=None,
                                        dimension=dimension,
                                        symprec=symprec)
        f_deg = open('deg.txt', 'a')
        for idx, (c, d) in enumerate(confs):
            filename = '{:s}_id{:d}'.format(comment, idx)
            write_vasp(c, filename)
            deg_line = filename + '{:10d}'.format(d) + '\n'
            f_deg.write(deg_line)
        f_deg.close()

        spinner.stop()
        click.secho("DONE", bold=True, bg='green', fg='white')
    elif pmode == 'svc' and cmode == 'cc':
        click.secho("Expanding and generating configurations: ")
        click.secho("(may take much time)",
                    blink=True,
                    bold=True,
                    bg='magenta',
                    fg='white')
        spinner = Spinner()
        spinner.start()
        (min_v, max_v) = volume
        l_atoms = cell.atoms.tolist()
        sites = _get_sites(l_atoms, element, substitutes)
        # number to enum
        ele_n = s2n(element)
        e_total = l_atoms.count(ele_n) * max_v
        e_n = e_total - sum(number)  # 第一个元素的数量
        e_num = [e_n] + list(number)  # 各个元素的数量
        confs = cg.cons_specific_volume(sites,
                                        volume=max_v,
                                        e_num=e_num,
                                        dimension=dimension,
                                        symprec=symprec)
        f_deg = open('deg.txt', 'a')
        for idx, (c, d) in enumerate(confs):
            filename = '{:s}_id{:d}'.format(comment, idx)
            write_vasp(c, filename)
            deg_line = filename + '{:10d}'.format(d) + '\n'
            f_deg.write(deg_line)
        f_deg.close()

        spinner.stop()
        click.secho("DONE", bold=True, bg='green', fg='white')
    elif pmode == 'sc' and cmode == 'vc':
        click.secho("Generating configurations: ")
        click.secho("(may take much time)",
                    blink=True,
                    bold=True,
                    bg='magenta',
                    fg='white')
        spinner = Spinner()
        spinner.start()
        l_atoms = cell.atoms.tolist()
        sites = _get_sites(l_atoms, element, substitutes)
        confs = cg.cons_specific_cell(sites, None, symprec=symprec)
        f_deg = open('deg.txt', 'a')
        for idx, (c, d) in enumerate(confs):
            filename = '{:s}_id{:d}'.format(comment, idx)
            write_vasp(c, filename)
            # import pdb; pdb.set_trace()
            deg_line = filename + '{:10d}'.format(d) + '\n'
            f_deg.write(deg_line)
        f_deg.close()

        spinner.stop()
        click.secho("DONE", bold=True, bg='green', fg='white')
    elif pmode == 'sc' and cmode == 'cc':
        click.secho("Generating configurations: ")
        click.secho("(may take much time)",
                    blink=True,
                    bold=True,
                    bg='magenta',
                    fg='white')
        spinner = Spinner()
        spinner.start()
        l_atoms = cell.atoms.tolist()
        sites = _get_sites(l_atoms, element, substitutes)
        # number to enum
        ele_n = s2n(element)
        e_total = l_atoms.count(ele_n)
        e_n = e_total - sum(number)  # 第一个元素的数量
        e_num = [e_n] + list(number)  # 各个元素的数量
        confs = cg.cons_specific_cell(sites, e_num, symprec=symprec)
        f_deg = open('deg.txt', 'a')
        # TODO f.close()
        for idx, (c, d) in enumerate(confs):
            filename = '{:s}_id{:d}'.format(comment, idx)
            write_vasp(c, filename)
            deg_line = filename + '{:10d}'.format(d) + '\n'
            f_deg.write(deg_line)
        f_deg.close()

        spinner.stop()
        click.secho("DONE", bold=True, bg='green', fg='white')
    else:
        click.secho("ERROR: --pmode={:s} --cmode={:s} not supported.".format(
            pmode, cmode),
                    bold=True,
                    bg='red',
                    fg='white')