예제 #1
0
def replace(path, site, rep):
    """
    * 元素ラベルを交換する\n
    * e.g.: cvm_input.py ファイル名 --site "0011" --rep "AC BD"\n
    * --site は左から順に第一、第二、第三...サイトに対応\n
    0 で交換判定しない、 1 で交換判定するサイトを指定\n
    * "0011" では 4 副格子中の 3 番目と 4 番目の site 原子ラベルを交換する設定\n
    * --rep で交換するラベルの組み合わせを指定する\n
    * "AC BD" は A を C に B を D に置き換える
    * ラベルを変えない場合は "AA" のように同じラベルを振る
    """
    d = len(site)
    site_ids = [j + k*d for k in range(100)
                for j in [int(i) for i in range(len(site)) if site[i] == "1"]]
    print(site_ids)
    replace_dict = {x[0]:x[1] for x in rep.split()}
    strs = CVMStrs.from_str_file(path)
    strs.replace_site_elements(site_ids, replace_dict)
    fname = path + "_rev"
    for s in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        if s in rep:
            largest = s
    strs.complete_elements("ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(largest)+1)
    strs.make_file(fname)
    try:
        enes = CVMEnergies.from_energies_file("energies.txt")
        enes.rename_from_str_labels(strs)
        enes.make_file("energies.txt_rev")
    except IOError:
        pass
예제 #2
0
def make_poscar(args, disord):
    """
    POSCAR を作成する
    str ファイルを引数に指定する
    """
    path = args
    strs = CVMStrs.from_str_file(path, disord=disord)
    # strs[0] | fnc.echo
    strs.make_poscar()
예제 #3
0
def stack(args):
    """
    hcp-fcc Mg stacking 構造を作成する
    """
    path = args
    strs = CVMStrs.from_str_file(path)
    for structure in strs:
        dirc = str(structure.label).split('*')[0]
        Bash.mkdir(dirc)
        structure.make_stack_poscar(os.path.join(dirc, "POSCAR"))
예제 #4
0
def rename_energies(path):
    """
    energies.txt を str ファイルから修正する
    """
    path = "hcp.str"
    strs = CVMStrs.from_str_file(path)

    enes = CVMEnergies.from_energies_file("energies.txt")
    enes.rename_from_str_labels(strs)
    enes.make_file("energies.txt_rev")
예제 #5
0
    def test_make_poscar(self):
        """ for make poscar """
        path = os.path.join(self.PATH, 'str')
        strs = CVMStrs.from_str_file(os.path.join(path, 'bcci.str'))
        # print(strs[100])
        # print(strs[100].sites)

        # strs[100].sites.set_sorted()
        print(strs[100])

        strs[100].make_poscar(1, path)
예제 #6
0
def make_sc(path, dim, disord, rep, key):
    """
    supercell を作成
    e.g.: cvm_input.py make_sc hcpi.str --dim 2 1 1 --rep "BA" --key GS7_
    """
    strs = CVMStrs.from_str_file(path, disord=disord)
    replace_dict = {x[0]:x[1] for x in rep.split()}
    # strs[2].make_supercell(strs.disord.lattice.array, replace_dict, dim)
    supercells = strs.make_supercells(key, replace_dict, dim)
    # supercells.make_poscar()
    supercells.make_file('supercells.str')
예제 #7
0
def exchange_elements(path, elem1, elem2):
    """
    原子ラベルを交換したファイルを作成
    """
    strs = CVMStrs.from_str_file(path)
    enes = CVMEnergies.from_energies_file("energies.txt")
    strs.exchange_elements(elem1, elem2)
    enes.exchange_elements(elem1, elem2)
    fname = path + "_rev"
    strs.make_file(fname)
    enes.make_file("energies.txt_rev")
예제 #8
0
def reject2(args):
    """
    原子が 0 意外を出力
    """
    path, pos = args
    strs = CVMStrs.from_str_file(path)
    tmpstr = []
    for structure in strs:
        a = structure.label.num_atoms[int(pos)]
        if a != 0:
            tmpstr.append(structure)
    outstr = CVMStrs(tmpstr)
    fname = path + "_rejcted"
    outstr.make_file(fname)
예제 #9
0
def alt_scale(args):
    """
    str ファイルの格子長の scale を変更する
    args: fname_str, scale

    scale は分数表記
    小数を与えることができないので、整数に通分する
    """
    path = args[0]
    scale = Fraction(args[1])
    strs = CVMStrs.from_str_file(path)
    strs.alt_lattice(scale)
    fname = path + '_rev'
    strs.make_file(fname)
예제 #10
0
def reject(path, limit):
    """
    条件で構造を絞る
    """
    strs = CVMStrs.from_str_file(path)
    tmpstr = []
    for structure in strs:
        a = structure.label.num_atoms[0] / (structure.label.num_atoms[0] +
                                            structure.label.num_atoms[2] +
                                            structure.label.num_atoms[3])
        if a != 0 and a < limit:
            tmpstr.append(structure)
    outstr = CVMStrs(tmpstr)
    fname = path + "_rejcted"
    outstr.make_file(fname)
예제 #11
0
def reject_bin(args):
    """
    条件で構造を絞る
    二元系用
    """
    path, limit = args
    strs = CVMStrs.from_str_file(path)
    tmpstr = []
    for structure in strs:
        a = structure.label.num_atoms[0] / (structure.label.num_atoms[0] +
                                            structure.label.num_atoms[1])
        if a <= limit:
            tmpstr.append(structure)
    outstr = CVMStrs(tmpstr)
    fname = path + "_rejcted"
    outstr.make_file(fname)
예제 #12
0
def add_site(path, input_file):
    """
    サイトを追加
    """
    with open(input_file, 'r') as rfile:
        lines = rfile.readlines()
    args = {}
    for line in lines:
        key = line.split("=")[0].split()[0]
        tmp = line.split("=")[1].split()
        if len(tmp) == 1:
            try:
                value = int(tmp[0])
            except ValueError:
                value = tmp[0]
        else:
            value = [Fraction(x) for x in tmp]
        args.update({key: value})
    strs = CVMStrs.from_str_file(path)
    strs.add_site(**args) #pylint: disable=W0142
    fname = path + "_added"
    strs.make_file(fname)
예제 #13
0
def add_site(args):
    """
    サイトを追加
    引数は path input_file
    """
    path, input_file = args
    with open(input_file, 'r') as rfile:
        lines = rfile.readlines()
    args = {}
    for line in lines:
        key = line.split("=")[0].split()[0]
        if key in ['primitive_z', 'origin']:
            args.update({key: int(line.split('=')[1].split()[0])})
        elif key == 'trans':
            value = [[Fraction(x) for x in y.split()]
                     for y in line.split('=')[1].split(',')]
            args.update({key: value})
        elif key == 'label':
            args.update({key: line.split('=')[1].split()[0]})
        elif key == 'insert_idx':
            value = [int(x) for x in line.split('=')[1].split(',')]
            args.update({key: value})
        else:
            print(key)
    strs = CVMStrs.from_str_file(path)
    tmp_args = {}
    tmp_args.update({'primitive_z': args['primitive_z'],
                     'origin': args['origin'],
                     'label': args['label']})
    for i, idx in enumerate(args['insert_idx']):
        tmp_args.update({'insert_idx': idx})
        tmp_args.update({'trans': args['trans'][i]})
        strs.add_site(**tmp_args) #pylint: disable=W0142
        if tmp_args['origin'] >= idx:
            tmp_args['origin'] += 1
        tmp_args['primitive_z'] += 1
    fname = path + '_added'
    strs.make_file(fname)