示例#1
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
示例#2
0
    def __init__(self, infile, radius):
        gcell = GeneralIO.from_file(infile)
        self.infile = infile
        self.basefname = os.path.basename(infile)
        self.mcell = ModifiedCell.from_gcell(gcell)

        self.radius = radius
示例#3
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
示例#4
0
文件: test_io.py 项目: yuansr/ababe
    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))
示例#5
0
def pspg(files, sym, verbose):
    from ababe.io.io import GeneralIO
    import os
    for infile in files:
        basefname = os.path.basename(infile)

        # read
        gcell = GeneralIO.from_file(infile)

        # print spacegroup
        print(gcell.get_spacegroup(sym))
示例#6
0
文件: runatilib.py 项目: yuansr/ababe
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)
示例#7
0
文件: test_io.py 项目: yuansr/ababe
    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))
示例#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)
示例#9
0
    def __init__(self, infile, comment, volumn, ld, outmode):
        self.ucell = GeneralIO.from_file(infile)
        # check whether input a unit cell
        if not self.ucell.is_primitive():
            raise ValueError('Lattice in setting file are not primitive.\n'
                             'You can reinput OR get the primitive lattice\n'
                             'by using runati pcell <file>\n')
        self.v = volumn

        self.comment = comment or "default"

        self.outmode = outmode

        if ld:
            LatticeGen = SuperLatticeGenerator2D
        else:
            LatticeGen = SuperLatticeGenerator

        self.hnfs = LatticeGen.hnfs_from_n(self.ucell, self.v)
示例#10
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)
示例#11
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)
示例#12
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)