def calc_gamma_all(a_fcc=3.840, b_slip=1):
    
    EPI_filename='../y_post_EPI.beta_4.txt'
    EPI_beta =  np.loadtxt( EPI_filename )


    os.system('ls POSCAR_step_* > tmp_filelist')   # debug
    f = open('tmp_filelist', 'r')

    gamma_all = np.zeros(2)
    npos = 0

    for line in f:
        npos += 1
        pos_filename = line.strip('\n') 
    
        # for each structure
        gamma_s, nz = calc_gamma_s(EPI_beta, pos_filename, a_fcc, b_slip)
        gamma_all = np.vstack([gamma_all, gamma_s])

    gamma_all = np.delete(gamma_all, 0, 0)
    vf.confirm_0(gamma_all.shape - np.array([npos*nz/6, 2]) )
    
    filename = 'SRO_gamma_all_%d.txt' %(b_slip)
    np.savetxt(filename, gamma_all)
    os.remove('tmp_filelist')


    write_output(gamma_all, npos, nz, a_fcc, b_slip)
    plot_hist(b_slip)

    return gamma_all.mean(), gamma_all.std() 
Exemplo n.º 2
0
def calc_a1(jobn, a):
    a1 = np.array([])
    for i in np.arange(len(jobn)):
        if jobn[i][0] == '0' or jobn[i][0] == '1':
            a1 = np.append(a1, a[i] / (float(jobn[i])))
    vf.confirm_0(a1.std())
    return a1.mean()
Exemplo n.º 3
0
def check_latt12_E_in_1(latoms, jobn):
    latt_ref = latoms[0].get_cell()[:]  # 1st in jobn

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]
        vf.confirm_0(latt[0:2, 0] / (float(jobn[i])) - latt_ref[0:2, 0] /
                     (float(jobn[0])))
        vf.confirm_0(latt[0:2, 1:] - latt_ref[0:2, 1:])
def check_constraints(Etot, latoms):
    njobs = len(latoms)
    natoms = latoms[0].positions.shape[0]
    print('njobs, natoms:', njobs, natoms)

    dE = np.array([])
    da33 = np.array([])

    for i in np.arange(njobs):
        dE = np.append(dE, Etot[i]-Etot[0])
    

    # check elem
        if latoms[i].get_chemical_formula() \
            != latoms[0].get_chemical_formula():
            sys.exit('ABORT: wrong chemical formula. ')

        temp = latoms[i].get_atomic_numbers() \
            - latoms[0].get_atomic_numbers()
        vf.confirm_0( temp )


        # check latt 
        dlatt = latoms[i].cell[:] - latoms[0].cell[:]

        temp  = dlatt[0:2, :].copy()
        temp2 = dlatt[2, 0:2].copy()

        temp  = np.linalg.norm(temp)
        temp2 = np.linalg.norm(temp2)

        if temp > 1e-10 or temp2 > 1e-10:
            print('dlatt:', dlatt)
            print(i, temp, temp2)
            sys.exit("==> ABORT: lattices wrong. \n" )
    
        da33 = np.append( da33, dlatt[2,2] )

        
        # check pos
        dpos = latoms[i].positions - latoms[0].positions
        dposD = dpos @ np.linalg.inv(latoms[i].cell[:])
        dposD = dposD - np.around(dposD)  
        dpos = dposD @ latoms[i].cell[:]

        temp = np.linalg.norm(dpos)
        if temp > 1e-10:
            print('dpos:', dpos)
            print('\n==> i, norm: {0}'.format([i, temp]) )
            sys.exit("==> ABORT: positions changed. \n" )
    
    
    if (dE.shape[0] != njobs):
        sys.exit("==> ABORT: wrong dimensions. \n" )
   
    return dE, da33
Exemplo n.º 5
0
def check_latt12_E_in_2(latoms, jobn):
    latt_ref = latoms[0].get_cell()[:]  # 1st in jobn

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]
        vf.confirm_0(latt[0:2, :] / latt[0, 0] -
                     latt_ref[0:2, :] / latt_ref[0, 0])

        if jobn[i][0] == '0' or jobn[i][0] == '1':
            vf.confirm_0(latt[0:2, :] / (float(jobn[i])) - latt_ref[0:2, :] /
                         (float(jobn[0])))
Exemplo n.º 6
0
def calc_d0(latoms, elt):

    natoms = latoms[0].get_positions().shape[0]

    d = np.zeros([len(latoms), natoms - 1])

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_positions()
        d[i, :] = np.diff(latt[:, 2]) / elt[i]

    vf.confirm_0(np.std(d, axis=0) / np.mean(d, axis=0) * 1e-8)
    return np.mean(d, axis=0)
Exemplo n.º 7
0
def calc_E_x_nu_xy(E_in_2, E_in_1):
    nu_xy = E_in_2 / E_in_1 - 1

    E_x = E_in_2 * (1 - nu_xy)
    vf.confirm_0(E_in_1 - E_x / (1 - nu_xy**2))

    f = open('y_post_E_in.txt', 'a')
    f.write('\n\n\n%16s %16s %16s %16s \n' \
        %('E_in_2', 'E_in_1', 'E_x', 'nu_xy') )
    f.write('%16.8f %16.8f %16.8f %16.8f \n' \
        %( E_in_2 ,  E_in_1 ,  E_x ,  nu_xy ) )
    f.close()
Exemplo n.º 8
0
def calc_A0(latoms, el, deform_type):
    A = np.array([])
    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]

        if deform_type == 'E_in_2':
            latt = latt / el[i]

        elif deform_type == 'E_in_1':
            latt[:, 0] = latt[:, 0] / el[i]

        temp = np.linalg.norm(np.cross(latt[0, :], latt[1, :]))
        A = np.append(A, temp)

    vf.confirm_0(A.std())
    return A.mean()
Exemplo n.º 9
0
def myfit(Etot, a, a0, V0):
    e = a / a0 - 1

    qe = vf.phy_const('qe')
    ed = Etot / V0 * (qe * 1e21)  # energy density GPa

    param = np.polyfit(e, ed, 2)
    vf.confirm_0(param[1])

    fun = np.poly1d(param)
    edp = fun(e)

    R2 = calc_R2(ed, edp)

    E0 = param[-1] * V0 / (qe * 1e21)  # total energy (eV)

    return e, ed, param, R2, E0
Exemplo n.º 10
0
def calc_transverse_isotropy(Cij_hcp):

    # https://en.wikipedia.org/wiki/Transverse_isotropy
    # 5 to 5

    from myvasp import vasp_func as vf

    if len(Cij_hcp) != 5:
        sys.exit('ABORT, wrong cij_hcp')

    [C11, C12, C13, C33, C44] = Cij_hcp

    E_x = (C11 - C12) * ((C11 + C12) * C33 - 2 * C13**2) / (C11 * C33 - C13**2)
    E_z = C33 - 2 * C13**2 / (C11 + C12)

    nu_xy = (C13**2 - C12 * C33) / (C13**2 - C11 * C33)
    nu_zx = C13 / (C11 + C12)

    mu_xz = C44

    nu_xz = nu_zx / E_z * E_x

    mu_xy = (C11 - C12) / 2
    vf.confirm_0(mu_xy - calc_mu_from_E_nu(E_x, nu_xy))

    #=====================

    CIJ = calc_CIJ_from_Cij('hcp', Cij_hcp)

    S = np.array([
        [1 / E_x, -nu_xy / E_x, -nu_zx / E_z, 0, 0, 0],
        [-nu_xy / E_x, 1 / E_x, -nu_zx / E_z, 0, 0, 0],
        [-nu_xz / E_x, -nu_xz / E_x, 1 / E_z, 0, 0, 0],
        [0, 0, 0, 1 / mu_xz, 0, 0],
        [0, 0, 0, 0, 1 / mu_xz, 0],
        [0, 0, 0, 0, 0, 1 / mu_xy],
    ])

    vf.confirm_0(np.linalg.inv(CIJ) - S)

    return E_x, E_z, nu_xy, nu_xz, mu_xz
Exemplo n.º 11
0
def calc_a_t(latoms):
    natoms = latoms[0].get_positions().shape[0]

    a = np.array([])  # lattice constant
    t = np.array([])  # slab thickness
    tv = np.array([])  # vacuum thickness

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]
        a = np.append(a, latt[0, 0])

        pos = latoms[i].get_positions()
        vf.confirm_0(pos.shape[0] - natoms)

        temp = pos[:, 2].max() - pos[:, 2].min()
        t = np.append(t, temp)

        temp2 = latt[2, 2] - temp
        tv = np.append(tv, temp2)

    return natoms, a, t, tv
def shift_to_poscar_layer(nmiss):
    atoms = vf.my_read_vasp(filename='CONTCAR')

    z = atoms.get_positions()[:, -1]
    z.sort()
    natoms = len(z)

    latt33 = atoms.get_cell()[2, 2]

    temp1 = latt33 - z[int(-1 * nmiss)]
    temp2 = z[int(-1 * nmiss)] - z[int(-1 * nmiss - 1)]

    zshift = temp1 + 0.5 * temp2

    pos = atoms.get_positions()
    pos[:, 2] = pos[:, 2] + zshift
    atoms.set_positions(pos)
    atoms.wrap()

    vf.my_write_vasp(atoms, filename='POSCAR_layer', vasp5=True)

    # check
    atoms2 = vf.my_read_vasp('POSCAR_layer')
    atoms3 = vf.my_read_vasp('CONTCAR')

    latt = atoms2.get_cell()[:]
    vf.confirm_0(latt - atoms3.get_cell()[:])

    dpos = atoms2.get_positions() - atoms3.get_positions()

    dposD = dpos @ np.linalg.inv(latt)
    dposD = dposD - np.around(dposD)
    dpos = dposD @ latt

    for i in np.arange(3):
        dpos[:, i] = dpos[:, i] - dpos[:, i].mean()

    vf.confirm_0(dpos)
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 check_ldata(ldata):

    iref0 = ldata[0]['iref']

    for i in np.arange(len(ldata)):
        iref1 = ldata[i]['iref']

        vf.confirm_0(ldata[0]['e'][iref0] - ldata[i]['e'][iref1])
        vf.confirm_0(ldata[0]['ed'][iref0] - ldata[i]['ed'][iref1])
        vf.confirm_0(ldata[0]['s'][iref0] - ldata[i]['s'][iref1])
def check_constraints(Etot, latoms, ibulk):
    njobs = len(latoms)
    natoms = latoms[ibulk].positions.shape[0]
    print('njobs, natoms:', njobs, natoms)

    dE = np.array([])
    da3 = np.zeros([1, 3])
    dpos_all = np.zeros([1, natoms, 3])
    
    for i in np.arange(njobs):
        dE = np.append(dE, Etot[i]-Etot[ibulk])
    

        # check elem
        if latoms[i].get_chemical_formula() \
            != latoms[ibulk].get_chemical_formula():
            sys.exit('ABORT: wrong chemical formula. ')

        temp = latoms[i].get_atomic_numbers() \
            - latoms[ibulk].get_atomic_numbers()
        vf.confirm_0( temp )
        

        # check latt 
        dlatt = latoms[i].cell[:] - latoms[ibulk].cell[:]

        temp = dlatt[0:2, :].copy()
        temp = np.linalg.norm(temp)
        if temp > 1e-10:
            print('dlatt:', dlatt)
            print('\n==> i, norm: {0}'.format([i, temp]) )
            sys.exit("==> ABORT: in-plane lattices changed. \n" )
    

        temp = dlatt[2, :].copy()
        da3 = np.vstack([ da3, temp[np.newaxis, :] ])
        

        # check pos
        dpos = latoms[i].positions - latoms[ibulk].positions
        dposD = dpos @ np.linalg.inv(latoms[i].cell[:])
        dposD = dposD - np.around(dposD)  
        dpos = dposD @ latoms[i].cell[:]

        temp = dpos.copy()
        for j in np.arange(3):
            temp[:,j] = temp[:,j] - temp[:,j].mean()
        dpos_all = np.vstack([ dpos_all, temp[np.newaxis, :] ])
        
          
    da3 = np.delete(da3, 0, 0)
    dpos_all = np.delete(dpos_all, 0, 0)
    
    if (dE.shape[0] != njobs)  \
        or (da3.shape[0] != njobs)  \
        or (dpos_all.shape[0] != njobs) \
        or (dpos_all.shape[1] != natoms) \
        or (dpos_all.shape[2] != 3) :
        sys.exit("==> ABORT: wrong dimensions. \n" )
   
    return dE, da3, dpos_all
Exemplo n.º 16
0
def check_latt3_bulk(latoms, t2):

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]
        vf.confirm_0(latt[2, :] - np.array([0, 0, t2[i]]))
Exemplo n.º 17
0
def plot_E_in(natoms, sys_name, Etot, V0, a, a0, t, t0, deform_type):

    e, ed, param, R2, E0 = myfit(Etot, a, a0, V0)

    xi = np.linspace(e[0], e[-1], 1000)
    fun = np.poly1d(param)
    yi = fun(xi)

    fig_wh = [3.15, 5]
    fig_subp = [2, 1]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp)

    fig_pos = np.array([0.25, 0.55, 0.70, 0.4])
    fig_dpos = np.array([0, -0.45, 0, 0])
    for i in np.arange(2):
        ax1[i].set_position(fig_pos + i * fig_dpos)

    ax1[0].plot(e, ed - param[-1], 'o')
    ax1[0].plot(xi, yi - param[-1], '-')

    xlim = ax1[0].get_xlim()

    ylim = ax1[0].get_ylim()
    ax1[0].plot(np.array([0, 0]), ylim, '--k', alpha=0.2)
    ax1[0].set_ylim(ylim)

    ax1[0].set_ylabel('Elastic energy density (GPa)')

    #==========================

    et = t / t0 - 1

    param2 = np.polyfit(e, et, 1)
    vf.confirm_0(param2[-1])

    fun2 = np.poly1d(param2)
    yi2 = fun2(xi)

    ax1[1].plot(e, et, 'o')
    ax1[1].plot(xi, yi2, '-')

    ylim2 = ax1[1].get_ylim()
    ax1[1].plot(np.array([0, 0]), ylim2, '--k', alpha=0.2)
    ax1[1].set_ylim(ylim2)

    ax1[1].set_ylabel('Out-of-plane strain $\\epsilon_{zz}$')

    if deform_type == 'E_in_2':

        ax1[1].set_xlabel(
            'Biaxial in-plane strain $\\epsilon_{xx}$ and $\\epsilon_{yy}$')

        str0 = '%s\n$a_0 = %.4f~\\mathrm{\AA}$\n\n$\\frac{ E_{x} }{ 1-\\nu_{xy} } = %.2f$ GPa\n$E_0 = %.4f$ eV/atom'  \
            %(sys_name, a0, param[0], E0/natoms)

        str1 = '$t_0 = %.4f~\\mathrm{\AA}$\n\n$\\frac{ \\nu_{xz} }{ 1-\\nu_{xy} } = %.4f $' \
            %(t0, param2[0]/(-2))

    elif deform_type == 'E_in_1':

        ax1[1].set_xlabel(
            'Uniaxial in-plane strain $\\epsilon_{xx}$ ($\\epsilon_{yy} = 0$)')

        str0 = '%s\n$a_0 = %.4f~\\mathrm{\AA}$\n\n$\\frac{ E_{x} }{ 1-\\nu_{xy}^2 } = %.2f$ GPa\n$E_0 = %.4f$ eV/atom'  \
            %(sys_name, a0, param[0]*2, E0/natoms)

        str1 = '$t_0 = %.4f~\\mathrm{\AA}$\n\n$\\frac{ \\nu_{xz} }{ 1-\\nu_{xy} } = %.4f $' \
            %(t0, param2[0]/(-1))


    ax1[0].text( xlim[0]+(xlim[1]-xlim[0])*0.25, ylim[0]+(ylim[1]-ylim[0])*0.55, \
        str0, horizontalalignment = 'left' )


    ax1[1].text( xlim[0]+(xlim[1]-xlim[0])*0.55, ylim2[0]+(ylim2[1]-ylim2[0])*0.7, \
        str1, horizontalalignment = 'left' )

    plt.savefig('y_post_E_in.pdf')
    plt.close('all')
Exemplo n.º 18
0
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
Exemplo n.º 19
0
def check_latt3_slab(latoms):
    latt_ref = latoms[0].get_cell()[:]  # 1st in jobn

    for i in np.arange(len(latoms)):
        latt = latoms[i].get_cell()[:]
        vf.confirm_0(latt[2, :] - latt_ref[2, :])