def plot_gamma_slip(a_fcc=3.840):
    
    ms  = np.array([0, 0])      # mean and std 

    # from 1b to 7b              # debug
    for i in np.arange(7):       
        m1, s1 = calc_gamma_all(a_fcc=a_fcc, b_slip=i+1)
        temp = np.array([ m1, s1 ])
        ms = np.vstack([ms, temp])
        
    filename = 'SRO_gamma_slip.txt'
    np.savetxt(filename, ms)
   

    # plot ms

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

    ax1.set_position([0.2, 0.15, 0.75, 0.8])

    xi = np.arange( ms.shape[0] )
    ax1.errorbar(xi, ms[:,0], yerr=ms[:,1], \
        fmt='-o', capsize=1) 

    ax1.set_xlabel('Slip (b)')
    ax1.set_ylabel('Anti-phase boundary $\\gamma_\\mathrm{APB}$ (mJ/m$^2$)')
    
    ax1.set_xticks(xi)

    filename= 'SRO_gamma_slip.pdf' 
    plt.savefig(filename)
    plt.close('all')
Exemple #2
0
def plot_E_in_d0(sys_name, d0):

    nd = len(d0)

    if np.mod(nd, 2) == 1:
        iref = int((nd - 1) / 2)
    else:
        iref = int(nd / 2)

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

    fig_pos = np.array([0.26, 0.19, 0.71, 0.73])
    ax1.set_position(fig_pos)

    xi = np.arange(len(d0)) + 1

    ax1.plot(xi, d0 / d0[iref] - 1, '-o')

    ax1.set_xlabel('Index $i$ of interlayer distance $d_i$')

    str1 = '$d_i / d_{ %d } -1$' % (iref + 1)
    ax1.set_ylabel(str1)

    str1 = '%s' % (sys_name)

    xlim = ax1.get_xlim()
    ylim = ax1.get_ylim()
    ax1.text( xlim[0]+(xlim[1]-xlim[0])*0.5, ylim[0]+(ylim[1]-ylim[0])*0.8, \
        str1, horizontalalignment = 'center' )

    plt.savefig('y_post_E_in.d0.pdf')
    plt.close('all')
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')
def plot_output(jobn, latoms, dpos_all, gamma, Asf, ibulk):
    from ase.formula import Formula
    
    njobs = len(jobn)
    print('njobs:', njobs)

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

    fig_wh = [3.15, 3]
    fig_subp = [1, 1]

    xi = latoms[ibulk].positions[:, 2].copy()
    
    for i in np.arange(njobs):
        
        if np.linalg.norm( dpos_all[i, :] ) > 1e-10:
            fig1, ax1 = vf.my_plot(fig_wh, fig_subp)
            
            temp = np.hstack([ dpos_all[i, :], xi[:, np.newaxis] ])
            ind = np.argsort(temp[:, -1])
            temp = temp[ind, :]
    
            ax1.plot(temp[:, -1], temp[:, 0], '-s', label='$u_1$'  )
            ax1.plot(temp[:, -1], temp[:, 1], '-o', label='$u_2$'  )
            ax1.plot(temp[:, -1], temp[:, 2], '-^', label='$u_3$'  )

            ax1.legend(loc='lower center', ncol=3, framealpha=0.4)
    
            ax1.set_xlabel('Atom positions in $x_3$ ($\\mathrm{\\AA}$)')
            ax1.set_ylabel('Displacements $u_i$ ($\\mathrm{\\AA}$)')
            ax1.set_position([0.25, 0.16, 0.7, 0.76])


            if jobn[i] == 'ssf':
                str1 = '$\\gamma_\\mathrm{ssf} =$ %.0f mJ/m$^2$'  %(gamma[i])
            
            elif jobn[i] == 'usf':
                str1 = '$\\gamma_\\mathrm{usf} =$ %.0f mJ/m$^2$' %(gamma[i])
            
            elif jobn[i] == 'surf':
                str1 = '$\\gamma_\\mathrm{surf} =$ %.0f mJ/m$^2$' %(gamma[i]/2)
            
            else:
                str1 = '$\\Delta E / A =$ %.0f mJ/m$^2$'          %(gamma[i])
            
            str2 = latoms[ibulk].get_chemical_formula()
            str2 = Formula(str2).format('latex')
            
            str_all = '%s\n$A =$%.4f $\\mathrm{\\AA}^2$\n%s' \
                %(str2, Asf, str1)  
        
            ax1.text( xi.max()*0.2, dpos_all[i, :].max()*0.6, str_all )

            filename = 'y_post_planar_relaxed.%s.pdf' %(jobn[i])

            plt.savefig(filename)
Exemple #5
0
def calc_yield_strength_et_T(self):

    T_list  = np.array([77, 300, 500])
    et_list = np.arange(-10, 3, 1)

    sigmay_all = np.zeros( [len(T_list), len(et_list)] )

    for i in np.arange(len(T_list)):
        for j in np.arange(len(et_list)):

            sigmay_all[i, j] = self.calc_yield_strength(
                param = { 'T': T_list[i], 'et': 10.0**(et_list[j]) } )
        
    print('==> sigmay:', sigmay_all)



    from myvasp import vasp_func as vf 
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt

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

    fig_pos  = np.array([0.20, 0.16, 0.75, 0.8])
    ax1.set_position(fig_pos)
   
    xi = 10.0**et_list

    ax1.set_xscale('log')

    for i in np.arange( len(T_list) ):
        str1 = '%d K' %(T_list[i])
        ax1.plot(xi, sigmay_all[i,:], '-o', label = str1)
        
    ax1.legend(loc='best')  


    [ymin, ymax] = ax1.get_ylim()
    ax1.set_ylim([0, ymax])        


    ax1.set_xlabel('Loading strain rate $\\dot{\\epsilon}$ (s$^{-1}$)')        
    ax1.set_ylabel('Yield strength $\\sigma_y$ (MPa)')        

        
    
    plt.savefig('fig_sigmay_et_T.pdf')
    plt.close('all')
Exemple #6
0
def plot_convergence(ljobn, lEtot, lEent):

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

    fig_wh = [7, 7]
    fig_subp = [3, 2]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp, fig_sharex=False)

    fig_pos = np.array([0.12, 0.73, 0.35, 0.25])
    fig_dpos = np.array([0, -1 / 3, 0, 0])
    fig_dpos2 = np.array([0.5, 0, 0, 0])

    for i in np.arange(len(ljobn)):
        ax1[i, 0].set_position(fig_pos + i * fig_dpos)
        ax1[i, 1].set_position(fig_pos + i * fig_dpos + fig_dpos2)

    for i in np.arange(2):
        ax1[i, 0].plot(ljobn[i], lEtot[i], '-o')
        ax1[i, 1].plot(ljobn[i][0:-1], np.diff(lEtot[i]) * 1e3, '-o')

    ax1[2, 0].plot(ljobn[2], lEent[2], '-s')
    ax1[2, 1].plot(ljobn[2][0:-1], np.diff(lEent[2]) * 1e3, '-s')

    for j in np.arange(2):
        ax1[0, j].set_xlabel('ENCUT')
        ax1[1, j].set_xlabel('KP')
        ax1[2, j].set_xlabel('SIGMA')

        ax1[0, j].set_xlim([0, 1000])
        ax1[1, j].set_xlim([0, 150])
        ax1[2, j].set_xlim([0, 0.5])

    for i in np.arange(3):
        ax1[i, 1].set_ylim([-1, 1])

    ax1[0, 0].set_ylabel('Energy (eV/atom)')
    ax1[1, 0].set_ylabel('Energy (eV/atom)')
    ax1[2, 0].set_ylabel('EENTRO (eV/atom)')

    ax1[0, 1].set_ylabel('$\\Delta_{(i+1)-(i)}$ (meV/atom)')
    ax1[1, 1].set_ylabel('$\\Delta_{(i+1)-(i)}$ (meV/atom)')
    ax1[2, 1].set_ylabel('$\\Delta_{(i+1)-(i)}$ (meV/atom)')

    plt.savefig('y_post_convergence.pdf')
    plt.close('all')
def plot_output(gamma, da33, str_all):
    njobs = len(gamma)
    print(njobs)

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

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

    disp = da33.copy()
    xi = da33.copy()

    ax1[0].plot(xi, gamma, '-o')   
      
    tau = np.diff(gamma) / np.diff(disp) *1e-2  #[GPa]
    x_tau = xi[0:-1].copy() + np.diff(xi)/2
    ax1[1].plot(x_tau, tau, '-o')


    fig_pos  = np.array([0.23, 0.57, 0.70, 0.40])
    fig_dpos = np.array([0, -0.46, 0, 0])

    ax1[0].set_position(fig_pos)
    ax1[1].set_position(fig_pos + fig_dpos  )

    ax1[-1].set_xlabel('Vacuum layer thickness ($\\mathrm{\\AA}$)')
    ax1[0].set_ylabel('Decohesion energy (mJ/m$^2$)')
    ax1[1].set_ylabel('Tensile stress $\\sigma$ (GPa)')

    ax1[0].text(4, gamma.max()/2, \
        '$\\gamma_\\mathrm{surf}^\\mathrm{unrelaxed}$ \n= %.0f mJ/m$^2$' %( gamma[-1]/2 ))

    ax1[1].text(4, tau.max()/2, \
        '$\\sigma_\\mathrm{max}$ \n= %.1f GPa' %( tau.max() ))


    ax1[0].text( 2, gamma.max()*0.2, str_all )


    plt.savefig('y_post_decohesion.pdf')
def plot_hist(b_slip):

    filename='SRO_gamma_all_%d.txt' %(b_slip)
    gamma_all =  np.loadtxt( filename )

    miu = np.mean(gamma_all)
    sigma = np.std(gamma_all)


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

    ax1.set_position([0.2, 0.15, 0.75, 0.8])

    ax1.hist(x=gamma_all, bins=20, density=True) 

    ax1.set_xlabel('$\\gamma_\\mathrm{APB}$ (mJ/m$^2$)')
    ax1.set_ylabel('Probability density')
    
    xmin, xmax = ax1.get_xlim()
    ax1.set_xlim([xmin, xmax] )
    
    ymin, ymax = ax1.get_ylim()

    xi = np.linspace( xmin, xmax ) 
    yi = my_gaussian(miu, sigma, xi)

    ax1.plot(xi, yi, '--k')

    str1 = 'mean = %.3f\nstd = %.3f' %(miu, sigma )
    ax1.text( xmin+(xmax-xmin)*0.95, ymin+(ymax-ymin)*0.8, \
        str1 , horizontalalignment='right'  )


    filename = 'SRO_gamma_hist_%d.pdf' %(b_slip)
    plt.savefig(filename)
    plt.close('all')
def plot_MC(EPI_beta, Ef_all, T):
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt

    Ef_rand = EPI_beta[0]

    fig_wh = [3.15, 2.7]
    fig_subp = [1, 1]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp)
    ax1.set_position([0.23, 0.16, 0.72, 0.78])

    xi = np.arange(len(Ef_all)) / 1e3
    ax1.plot(xi, (Ef_all-Ef_rand)*1e3,  '-' , \
        label='$T_a$ = %d K' %(T))

    ax1.set_xlabel('MC step ($\\times 10^3$)')
    ax1.set_ylabel('$E_{f,\\mathrm{Pred}} - E^\\mathrm{rand}_{f}$ (meV/atom)')
    ax1.legend(framealpha=0.5, loc="best")

    filename = 'fig_MC_T_%04.0f_nstep_%d.pdf' % (T, len(Ef_all) - 1)
    plt.savefig(filename)
    plt.close('all')
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
def plot_cij_energy(ldata):

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

    xi = np.linspace(-0.003, 0.003, 1000)

    fig_wh = [7, 10]
    fig_subp = [5, 2]
    fig1, ax1 = vf.my_plot(fig_wh, fig_subp)

    fig_pos = np.array([0.13, 0.8, 0.35, 0.16])
    fig_dpos = np.array([0, -0.19, 0, 0])
    fig_dpos2 = np.array([0.5, 0, 0, 0])

    for i in np.arange(5):
        ax1[i, 0].set_position(fig_pos + i * fig_dpos)
        ax1[i, 1].set_position(fig_pos + i * fig_dpos + fig_dpos2)

    # plot energy-strain

    p0_tot = np.array([])  # for Cij
    e0_tot = np.array([])  # to check shift

    for i in np.arange(len(ldata)):
        e = ldata[i]['e']
        ed = ldata[i]['ed']
        s = ldata[i]['s']

        ax1[i, 0].plot(e, ed, 'o')

        param = np.polyfit(e, ed, 2)
        fun = np.poly1d(param)
        yi = fun(xi)
        p0_tot = np.append(p0_tot, param[0])

        e0 = -param[1] / (2 * param[0])
        e0_tot = np.append(e0_tot, e0)

        ax1[i, 0].plot(xi, yi, '-C1')

        str1 = '$\\epsilon_0$ = %.6f' % (e0)
        ymin, ymax = ax1[i, 0].get_ylim()
        ax1[i, 0].text(0, ymax * 0.85, str1)

    C11 = p0_tot[0] * 2
    C12 = p0_tot[1] - C11
    C33 = p0_tot[3] * 2
    C13 = p0_tot[2] - (C11 + C33) / 2
    C44 = p0_tot[4] * 2

    # plot stress-strain

    lcolor = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5']

    llegend = [
        '$\\sigma_{xx}$', '$\\sigma_{yy}$', '$\\sigma_{zz}$', '$\\sigma_{yz}$',
        '$\\sigma_{xz}$', '$\\sigma_{xy}$'
    ]

    lslope = np.array([
        [C11, C12, C13, 0, 0, 0],  # c11
        [C11 + C12, C12 + C11, C13 * 2, 0, 0, 0],  # c12
        [C11 + C13, C12 + C13, C13 + C33, 0, 0, 0],  # c13
        [C13, C13, C33, 0, 0, 0],  # c33
        [0, 0, 0, C44, 0, 0],  # c44
    ])

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

        for j in np.arange(6):
            ax1[i, 1].plot(e, s[:, j], 'o', color=lcolor[j], label=llegend[j])
            ax1[i, 1].plot(xi,
                           xi * lslope[i, j] + s[iref, j],
                           '-',
                           color=lcolor[j])

    ax1[0, 1].legend(loc='upper left', ncol=2, framealpha=0.4)

    for i in np.arange(len(ldata)):
        for j in np.arange(2):
            ax1[i, j].set_xticks(np.arange(-0.002, 0.004, 0.002))
            ax1[4, j].set_xlabel('Strain')

        ax1[i, 0].set_ylabel('Elastic energy density (GPa)')
        ax1[i, 1].set_ylabel('DFT stress (GPa)')




    str1 = '$C_{11}$, $C_{12}$, $C_{13}$, $C_{33}$, $C_{44}$ (GPa): \n%.2f,   %.2f,   %.2f,   %.2f,   %.2f ' \
        %( C11, C12, C13, C33, C44 )
    ymin, ymax = ax1[0, 0].get_ylim()
    ax1[0, 0].text(-0.003, ymax * 1.05, str1)

    plt.savefig('y_post_cij_energy.pdf')
    plt.close('all')

    write_cij_energy(np.array([C11, C12, C13, C33, C44]))
Exemple #12
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')
def plot_output(E0, Eatom, Ecoh, V0, k, Etot, Vp, p, VB, B, p0, B0, magtot):
    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.20, 0.77, 0.75, 0.205])
    fig_dpos = np.array([0, -0.24, 0, 0])

    for i in np.arange(4):
        ax1[i].set_position(fig_pos + fig_dpos * i)

    Elimd = math.floor(Etot.min() - 0.5)
    Elimu = -2 * Elimd

    plim = -math.floor(p.min() / 10) * 10

    Blimu = math.ceil(B0 * 1.2 / 50) * 50
    Blimd = math.floor(B.min() / 50) * 50

    maglimu = math.ceil(magtot.max() + 1e-6)
    maglimd = -0.1

    ax1[0].plot([1, 1], [Elimd, Elimu], '--k')
    ax1[0].plot(k, Etot, '-o')

    ax1[1].plot([0, 4], [0, 0], '--k')
    ax1[1].plot([1, 1], [-plim, plim], '--k')
    ax1[1].plot((Vp / V0)**(1 / 3), p, '-o')
    ax1[1].plot(1, p0, 's')

    ax1[2].plot([0, 4], [0, 0], '--k')
    ax1[2].plot([1, 1], [Blimd, Blimu], '--k')
    ax1[2].plot((VB / V0)**(1 / 3), B, '-o')
    ax1[2].plot(1, B0, 's')

    ax1[3].plot([1, 1], [maglimd, maglimu], '--k')
    ax1[3].plot(k, magtot, '-o')

    ax1[0].set_ylim([Elimd, Elimu])
    ax1[1].set_ylim([-plim, plim])
    ax1[2].set_ylim([Blimd, Blimu])
    ax1[3].set_ylim([maglimd, maglimu])

    plt.setp(ax1[-1], xlabel='$a/a_0$')
    plt.setp(ax1[0], ylabel='DFT energy (eV/atom)')
    plt.setp(ax1[1], ylabel='Pressure (GPa)')
    plt.setp(ax1[2], ylabel='Bulk modulus (GPa)')
    plt.setp(ax1[3], ylabel='Net magnetic moment ($\\mu_B$/atom)')


    ax1[0].text(1.5, Elimd+(Elimu-Elimd)*0.6, \
    '$E_0$ = %.4f eV \n$E_\mathrm{atom}$ = %.4f eV \n$E_\mathrm{coh}$ = %.4f eV \n\n$V_0$ = %.4f $\mathrm{\AA}^3$' \
    %(E0, Eatom, Ecoh, V0)  )


    ax1[1].text(1.5, plim*0.4, \
    'from diff: \n$p_0$ = %.1f GPa ' %(p0)  )

    ax1[2].text(1.5, Blimd+(Blimu-Blimd)*0.6, \
    'from diff: \n$B_0$ = %.1f GPa ' %(B0)  )

    plt.savefig('y_post_cohesive.pdf')
def plot_output(latoms2, jobn):
    try:
        shutil.rmtree('./y_post_mag/')
    except:
        print('==> no folder')
    os.mkdir('./y_post_mag/')


    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
     
    fig_wh = [3.15, 3]
    fig_subp = [1, 1]

    mag0_all = np.array([])
    
    for i in np.arange( len(jobn) ):
        magmom = latoms2[i].get_magnetic_moments()
        mag0 = latoms2[i].get_magnetic_moment() \
            / len(latoms2[i].get_positions())

        mag0_all = np.append(mag0_all, mag0)

        chem_sym = latoms2[i].get_chemical_symbols()
        elem_sym = pd.unique( chem_sym )
        
        atom_num = latoms2[i].get_atomic_numbers()
        elem_num = pd.unique( atom_num )
        nelem = len(elem_num)
        print('elem_sym, elem_num, nelem:', \
            elem_sym, elem_num, nelem)

        ymax = np.ceil( max([1.5, abs(max(magmom, key=abs)) ]) )

        fig1, ax1 = vf.my_plot(fig_wh, fig_subp)

        for j in np.arange(nelem):
            mask = (atom_num == elem_num[j])
            yi = magmom[mask]
            temp = np.linspace(-0.2, 0.2, len(yi)+2 ) + j
            xi = temp[1:-1]
            ax1.plot( xi , yi, 'o' )

            ax1.text(j, ymax/4*5.0, '%.2f' %( yi.mean() ), \
                horizontalalignment='center' )
            ax1.text(j, ymax/4*4.5, '%.2f' %( yi.std() ), \
                horizontalalignment='center' )

            
        ax1.text(-0.5, ymax/4*5.0, 'mean:', \
            horizontalalignment='right' )
        ax1.text(-0.5, ymax/4*4.5, 'std:', \
            horizontalalignment='right' )
        ax1.text(-0.5, ymax/4*(-5.3), 'Supercell mean= %.2f' %(mag0), \
            horizontalalignment='left' )
            
        ax1.plot( [-0.5, nelem-0.5], [0, 0], '--k' )

        ax1.set_position([0.23, 0.15, 0.72, 0.70])

        ax1.set_xlim([-0.5, nelem-0.5])
        ax1.set_ylim([-ymax, ymax])
        ax1.set_xticks(np.arange(nelem))
        ax1.set_xticklabels(elem_sym)
        ax1.set_ylabel('Atomic magnetic moment ($\\mu_B$)')

        filename = './y_post_mag/y_post_mag_%s.pdf' %(jobn[i])
        plt.savefig(filename)
        plt.close('all')


    mag0_all = np.abs( mag0_all )
    f = open('./y_post_mag/y_post_mag_note.txt', 'w+')
    f.write('# VASP magnetic moment , supercell mean (mu_B/atom): \n' )
    
    f.write('\n%8s %8s %8s \n' \
        %('mean', 'max', 'min' ) )
    f.write('%8.2f %8.2f %8.2f \n\n' \
        %(mag0_all.mean(), mag0_all.max(), mag0_all.min() ) )
    
    for i in np.arange( len(jobn) ):
        f.write('%20s %8.2f \n' \
            %(jobn[i], mag0_all[i]  ) )
    f.close()