Exemplo n.º 1
0
def plot_eos(V, Etot, fitres, p_dft, V1, ca, magtot):
 
    qe = vf.phy_const('qe')
    E0 = fitres[0]
    V0 = fitres[1]
    B0 = fitres[2] *qe*1e21
    B1 = fitres[3]


    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt

    fig_wh = [3.15, 9]
    fig_subp = [4, 1]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp)
     

    fig_pos  = np.array([0.23, 0.77, 0.70, 0.205])
    fig_dpos = np.array([0, -0.24, 0, 0])
    
    for i in np.arange(4):
        ax1[i].set_position(fig_pos + i* fig_dpos)
   

    xi=np.arange(V.min()/V0, V.max()/V0, 1e-4)

    ax1[0].plot(V/V0, (Etot-E0), 'o')
    yi1 = myeqn(fitres[:-1], xi*V0) -E0
    ax1[0].plot(xi, yi1, '-')

    ax1[1].plot(V/V0, p_dft, 'o')
    yi2 = myeosp(fitres[:-1], xi*V0) *qe*1e21   #[GPa]
    ax1[1].plot(xi, yi2, '-')

    ax1[2].plot(V/V0, ca, 'o')
    
    ax1[3].plot(V/V0, magtot, 'o')
    ax1[3].set_ylim([-0.1, np.ceil(magtot.max()+1e-6)])


    plt.setp(ax1[-1], xlabel='Volume $V/V_0$')
    plt.setp(ax1[0],  ylabel='Energy $E-E_0$ (eV/atom)')
    plt.setp(ax1[1],  ylabel='Pressure $p$ (GPa)')
    plt.setp(ax1[2],  ylabel='$c/a$')
    plt.setp(ax1[3],  ylabel='Net magnetic moment ($\\mu_B$/atom)')


    ax1[0].text(xi[0]+(xi[-1]-xi[0])*0.2, yi1.max()*0.7, \
    '$E_0$ = %.4f eV/atom \n$V_0$ = %.4f $\mathrm{\AA}^3$/atom \n$B_0$ = %.2f GPa \n' 
    %(E0, V0, B0)  )

    ax1[1].text(xi[0]+(xi[-1]-xi[0])*0.4, yi2.max()*0.7, \
    '$p_\mathrm{Pulay} = p_\mathrm{DFT} - p_\mathrm{true}$\n$\\approx$ %.2f GPa' 
    %( (V1/V0-1)*B0 )  )



    plt.savefig('y_post_eos.pdf')
Exemplo n.º 2
0
def write_output(V, Etot, fitres, V1, a1_pos, p_dft):
    
    qe = vf.phy_const('qe')
    E0 = fitres[0]
    V0 = fitres[1]
    B0 = fitres[2] *qe*1e21
    B1 = fitres[3]
    a1_pos_new = (V0/V1)**(1/3)*a1_pos


    f = open('y_post_eos.txt','w+')
    f.write('# VASP EOS fitting: \n' )

    f.write('%16s %16s %16s %16s \n' \
    %('E0 (eV)', 'V0 (Ang^3)', 'B0 (GPa)', 'B1') )

    f.write('%16.8f %16.8f %16.8f %16.8f \n' \
    %( E0, V0, B0, B1  ) )


    f.write('\n%16s %16s %16s \n' \
    %('R2', 'a0_fcc (Ang)', 'a0_bcc (Ang)'  ) )

    f.write('%16.8f %16.8f %16.8f \n' \
    %( fitres[-1], (V0*4)**(1/3), (V0*2)**(1/3)   ) )


    f.write('\n%16s %16s %16s \n' \
    %('V1/V0-1', '(V1/V0-1)*B0', 'V1-V0' ) )

    f.write('%16.8f %16.8f %16.8f \n' \
    %( V1/V0-1, (V1/V0-1)*B0, V1-V0 ) )


    f.write('\n%16s %16s \n' \
    %('a1_pos', 'a1_pos at V0' ) )
  
    f.write("%16.8f %16.8f \n" \
    %(a1_pos, a1_pos_new ) )


    f.write('\n%16s %16s %16s %16s\n' \
    %('V (Ang^3)', 'Etot (eV)' , 'p_dft (GPa)', 'p_dft-true' ) )
  
    for i in np.arange(len(V)):
        temp = p_dft[i] - myeosp(fitres[:-1], V[i])*qe*1e21 
        f.write('%16.8f %16.8f %16.8f %16.8f\n' \
        %(V[i], Etot[i], p_dft[i], temp) )

    f.close() 
def main():
    qe = vf.phy_const('qe')
    
    jobn, Etot, Eent, pres = vf.vasp_read_post_data()
    njobs = len(jobn)  # number of jobs

    if njobs < 1.5:
        sys.exit('==> ABORT! more structures needed. ')

    if jobn[0] != '0.00':
        sys.exit('==> ABORT! no reference state. ')
        
    latoms = vf.get_list_of_atoms()
    
    Asf = np.linalg.norm( \
        np.cross(latoms[0].cell[0, :], latoms[0].cell[1, :] ) )

    a11 = latoms[0].cell[0, 0]
    a22 = latoms[0].cell[1, 1]
    
    natoms = latoms[0].get_positions().shape[0]    
    E0bulk = Etot[0] / natoms


    dE, da33 = check_constraints(Etot, latoms)
   
    # check jobname
    k = np.array([])
    for i in np.arange(len(jobn)):
        k = np.append(k, float(jobn[i]) )
     
    if np.linalg.norm( k - da33 ) > 1e-10:
        sys.exit('==> ABORT. wrong jobname. ')


    gamma = dE/Asf *qe*1e23   #[mJ/m^2]
   
    from ase.formula import Formula
    str2 = latoms[0].get_chemical_formula()
    str2 = Formula(str2).format('latex')
    str_all = '%s\n$A =$%.4f $\\mathrm{\\AA}^2$' %(str2, Asf)

 
    #=========================
    write_output(Asf, a11, a22, E0bulk, jobn, dE, gamma, da33)
    plot_output(gamma, da33, str_all)
def read_deform_data(dirn, atoms_ref):

    x = np.array([])  # applied strain, with respect to the ref state
    e_ss_V = np.zeros(6)  # strain components

    os.chdir(dirn)
    jobn, Etot, Eent, pres = vf.vasp_read_post_data()
    latoms = vf.get_list_of_atoms()

    iref = -1  # id of the ref state

    for i in np.arange(len(jobn)):
        temp = float(jobn[i]) - 1
        x = np.append(x, temp)

        if np.abs(temp) < 1e-10:
            iref = i

        temp = vf.calc_strain(atoms_ref.get_cell()[:], latoms[i].get_cell()[:])
        e_ss_V = np.vstack([e_ss_V, temp])

    if iref < 0:
        os.exit('ABORT: no ref state. ')

    e_ss_V = np.delete(e_ss_V, 0, 0)
    np.savetxt('y_post_calc_strain_all.txt', e_ss_V)
    os.chdir('..')

    # energy density
    Etot = Etot - Etot[iref]
    ed = Etot / latoms[iref].get_volume() * vf.phy_const('qe') * 1e21

    # stress
    s = pres * (-0.1)  # GPa

    temp = s.copy()
    s[:, 3] = temp[:, 4]
    s[:, 4] = temp[:, 5]
    s[:, 5] = temp[:, 3]

    data = {}
    data['e'] = x
    data['ed'] = ed
    data['s'] = s
    data['iref'] = iref
    return data
Exemplo n.º 5
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
def calc_p_B(V, Etot, V0):
    Vp = V[0:-1].copy() + np.diff(V) / 2
    VB = Vp[0:-1].copy() + np.diff(Vp) / 2

    qe = vf.phy_const('qe')
    p = -np.diff(Etot) / np.diff(V) * qe * 1e21  #[GPa]
    B = -np.diff(p) / np.diff(Vp) * VB  #[GPa]

    fp = interp1d(Vp, p)
    fB = interp1d(VB, B)

    p0 = fp(V0)
    B0 = fB(V0)
    print('==> p0, B0:')
    print(p0, B0)

    return Vp, p, VB, B, p0, B0
def main():
    qe = vf.phy_const('qe')
    
    jobn, Etot, Eent, pres = vf.vasp_read_post_data()
    njobs = len(jobn)  # number of jobs

    if njobs < 1.5:
        sys.exit('==> ABORT! more structures needed. ')

    ibulk=-1
    for i in np.arange(njobs):
        if jobn[i] == 'bulk':
            ibulk = i 
            break

    if ibulk == -1:
        sys.exit('==> ABORT! no reference bulk state. ')
        
    latoms = vf.get_list_of_atoms()
    
    Asf = np.linalg.norm( \
        np.cross(latoms[ibulk].cell[0, :], latoms[ibulk].cell[1, :] ) )
    a11 = latoms[ibulk].cell[0, 0]
    a22 = latoms[ibulk].cell[1, 1]
    
    natoms = latoms[ibulk].get_positions().shape[0]
    E0bulk = Etot[ibulk]/natoms
    V0bulk = latoms[ibulk].get_volume()/natoms

    if np.abs( Asf-a11*a22 ) > 1e-10:
        sys.exit('ABORT: wrong Asf. ')


    dE, da3, dpos_all = check_constraints(Etot, latoms, ibulk)
   
    gamma = dE/Asf *qe*1e23   #[mJ/m^2]
    
    #=========================
    write_output(Asf, a11, a22, E0bulk, V0bulk, jobn, dE, gamma, da3)
    plot_output(jobn, latoms, dpos_all, gamma, Asf, ibulk)
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