def calc_shellmax(atoms_in, EPI_beta):
    atoms = copy.deepcopy(atoms_in)
    nelem = atoms.get_nelem()
    shellmax = (len(EPI_beta) - 1) / (nelem * (nelem - 1) / 2)
    vf.confirm_int(shellmax)
    shellmax = int(shellmax)
    return shellmax
Beispiel #2
0
def write_poscar(a_pos, latt, lelem, pos, filename='POSCAR'):

    latt = latt / a_pos
    pos = pos / a_pos

    temp = lelem.max()
    vf.confirm_int(temp)
    ns = np.zeros(int(temp))

    for i in np.arange(len(ns)):
        mask = lelem[:] == (i + 1)
        temp = lelem[mask]
        ns[i] = temp.shape[0]

    mask = ns[:] != 0
    ns = ns[mask]

    f = open(filename, 'w+')
    f.write('system name \n %22.16f \n' % (a_pos))

    for i in np.arange(3):
        f.write(' %22.16f %22.16f %22.16f \n' %
                (latt[i, 0], latt[i, 1], latt[i, 2]))

    for i in np.arange(len(ns)):
        f.write(' %d ' % (ns[i]))
    f.write('\nS \nC \n')

    for i in np.arange(pos.shape[0]):
        f.write(' %22.16f %22.16f %22.16f   T T T \n' %
                (pos[i, 0], pos[i, 1], pos[i, 2]))

    f.close()
def vasp_read_post_param(filename='y_post_param', \
    filename2='y_post_param_2', ):

    ljobs = []

    f = open(filename, 'r')
    next(f)
    for line in f:
        temp = line.split()

        job = {
            'jobname': temp[0],
            'ENCUT': temp[1][6:],
            'ISMEAR': temp[2][7:],
            'EDIFF': float(temp[3][6:]),
            'ISIF': temp[4],
            'EDIFFG': float(temp[5]),
            'LREAL': temp[6][6:],
            'KP': temp[7][3:],
        }

        ljobs.append(job)
    f.close()

    f = open(filename2, 'r')
    next(f)
    k = -1
    for line in f:
        temp = line.split()
        k += 1

        if temp[0] != ljobs[k]['jobname']:
            sys.exit('ABORT: wrong post_param_2')

        addgrid = float(temp[10]) / float(temp[9])
        vf.confirm_int(addgrid)
        addgrid = int(addgrid)

        ljobs[k].update({
            'ISTART': temp[1][7:],
            'ICHARG': temp[2][7:],
            'PREC': temp[3][5:],
            'ISPIN': temp[4][6:],
            'VOSKOWN': temp[5][8:],
            'RWIGS': temp[6][6:],
            'IALGO': temp[7][6:],
            'ADDGRID': addgrid,
        })

    f.close()

    return ljobs
def eval_Ef_from_EPI(atoms_in, EPI_beta):
    from myvasp import vasp_EPI_dp_shell as vf2

    atoms = copy.deepcopy(atoms_in)
    nelem = atoms.get_nelem()

    shellmax = (len(EPI_beta) - 1) / (nelem * (nelem - 1) / 2)
    vf.confirm_int(shellmax)
    shellmax = int(shellmax)

    dp_shell = vf2.calc_pairs_per_shell(atoms,
                                        shellmax=shellmax,
                                        write_dp=False)
    X = np.append(1.0, -0.5 * dp_shell)
    Ef = np.dot(X, EPI_beta)
    return Ef
def calc_natomsl_nlayers_nmiss(dz, dz_b):
    dz = dz.copy()
    dz_b = dz_b.copy()

    # interplane id in dz
    intp_id = np.array([])
    for item in np.unique(dz_b):
        temp, = np.where(dz == item)
        intp_id = np.append(intp_id, temp)

    intp_id.sort()

    d_intp_id = np.diff(intp_id)
    vf.confirm_int(d_intp_id)

    # use the most frequent value as the natoms per layer
    natomsl = np.bincount(d_intp_id.astype(int)).argmax()
    # natomsl = calc_natomsl(d_intp_id)

    vf.confirm_int(d_intp_id / natomsl)

    natoms = len(dz) + 1
    nlayers = natoms / natomsl

    temp = np.ceil((intp_id[0] + 1) / natomsl)
    nmiss = natomsl * temp - (intp_id[0] + 1)

    vf.confirm_int([natomsl, nlayers, nmiss])
    print('==> natomsl, nlayers, nmiss:', \
        natomsl, nlayers, nmiss)
    return natomsl, nlayers, nmiss
def calc_gamma_s(EPI_beta, pos_filename, a_fcc, b_slip):

    atoms = vf.my_read_vasp( pos_filename )
    latt = atoms.get_cell()[:]
    natoms = atoms.get_positions().shape[0]

    b = atoms.pos_a0/np.sqrt(2)
    nx = np.around( latt[0,0]/b )
    vf.confirm_int(nx)
    nx = int(nx)
        
    nlayers, nmiss = vf_shift.check_layers(filename = pos_filename)
    vf.confirm_0(nmiss)
    nz = nlayers

    E_s = calc_E_s(atoms, nx, nz, EPI_beta, b_slip)
    
    vf.confirm_0( E_s.shape - np.array([nz/6, 2]) )

    qe = vf.phy_const('qe')
    gamma_s = E_s/(natoms/nz) / (np.sqrt(3)/2*a_fcc**2/2) *qe*1e23

    return gamma_s, nz
def plot_dp_shell(atoms_in,
                  EPI_beta=np.array([]),
                  dp_shell=np.array([]),
                  dp_type='dp'):
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    import pandas as pd
    from myvasp import vasp_EPI_dp_shell as vf2

    atoms = copy.deepcopy(atoms_in)

    nelem = atoms.get_nelem()
    shellmax = (len(EPI_beta) - 1) / (nelem * (nelem - 1) / 2)
    vf.confirm_int(shellmax)
    shellmax = int(shellmax)

    if len(dp_shell) < 0.1:
        dp_shell = vf2.calc_pairs_per_shell(atoms, \
            shellmax=shellmax, write_dp=True)
    else:
        print('==> Use input dp_shell.')

    temp = int(len(dp_shell) / shellmax)
    dp_shell_2 = dp_shell.reshape(shellmax, temp)

    rcry, ncry = vf2.crystal_shell('fcc')
    xi = rcry[0:shellmax].copy()

    fig_xlim = np.array([xi[0] - 0.15, xi[-1] + 0.15])
    # fig_ylim = np.array([-0.5, 0.5])

    elem_sym = pd.unique(atoms.get_chemical_symbols())
    print('elem_sym:', elem_sym)
    nelem = elem_sym.shape[0]

    fig_wh = [2.7, 2.5]
    fig_subp = [1, 1]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp)

    fig_pos = np.array([0.27, 0.17, 0.70, 0.78])
    ax1.set_position(fig_pos)

    ax1.plot(fig_xlim, [0, 0], ':k')

    k = -1
    for i in np.arange(nelem):
        for j in np.arange(i, nelem):
            if i != j:
                k = k + 1

                elems_name = '%s%s' % (elem_sym[i], elem_sym[j])
                # str1 = '$\\Delta \\eta_{\\mathrm{%s}, d}$' %(elems_name)
                str1 = '%s' % (elems_name)
                mycolor, mymarker = mycolors(elems_name)

                ax1.plot(xi,  dp_shell_2[:, k], '-', \
                    color = mycolor, marker = mymarker, \
                    label = str1)

    vf.confirm_0(dp_shell_2.shape[1] - (k + 1))
    ax1.legend(loc='best', ncol=2, framealpha=0.4, \
        fontsize=7)

    ax1.set_xlabel('Pair distance $d/a$')

    ax1.set_xlim(fig_xlim)
    # ax1.set_ylim( fig_ylim )
    fig_ylim = ax1.get_ylim()

    if dp_type == 'dp':
        ax1.set_ylabel('$\\Delta \\eta_{nm, d}$')

        if len(EPI_beta) > 0.1:
            Ef = -0.5 * np.dot(dp_shell, EPI_beta[1:])

            str1 = '$E_{f, \\mathrm{Pred}} - {E}^\\mathrm{rand}_{f}$\n= %.3f meV/atom' % (
                Ef * 1e3)
            ax1.text(
                fig_xlim[0]+(fig_xlim[1]-fig_xlim[0])*0.95, \
                fig_ylim[0]+(fig_ylim[1]-fig_ylim[0])*0.06, str1, \
                horizontalalignment='right' )

        filename = 'y_post_dp_shell.pdf'

    elif dp_type == 'SRO':
        ax1.set_ylabel('Warren-Cowley SRO $\\alpha_{nm, d}$')

        filename = 'y_post_WC_SRO_shell.pdf'

    plt.savefig(filename)
    plt.close('all')
    return dp_shell