Пример #1
0
 def test_encut(self,kw={}):
     start,end,step = kw.get('start'),kw.get('end'),kw.get('step')
     is_login_node,kw = run_vasp.clean_parse(kw,'is_login_node',False)
     kw.pop('start');kw.pop('end');kw.pop('step')
     _kw = kw.copy()
     prep_vasp.write_potcar(poscar=self.poscar,kw=_kw)
     with open('POTCAR') as f:
         lines = f.readlines()
     en_line = [i for i in lines if 'ENMAX' in i]
     enmax = max([float(i.split()[2].replace(';','')) for i in en_line])
     remove('POTCAR')
     idx = 0
     for en in np.arange(start*enmax,end*enmax,step):
         _kw = kw.copy()
         _kw.update({'ENCUT':int(en),'job_name':'test_encut'+str(idx),'NSW':0})
         prep_vasp.prep_single_vasp(poscar=self.poscar,kw=_kw)
         idx += 1
     for i in range(idx):
         run_vasp.run_single_vasp(job_name='test_encut'+str(i),is_login_node=is_login_node)
     encut_list = []
     encut = np.arange(start*enmax,end*enmax,step)
     for ii in range(len(encut)):
         EV = ExtractValue(data_folder='test_encut'+str(ii))
         encut_list.append([encut[ii],EV.get_energy(),EV.get_cpu_time()])
     with open('test_encut.txt','w') as f:
         f.writelines('ENMAX\tEnergy\tcpu_time\n')
         for line in encut_list:
             f.writelines(str(line[0])+'\t'+str(line[1])+'\t'+str(line[2])+'\n')
Пример #2
0
 def test_kpts(self,kw={}):
     start,end,step = kw.get('start'),kw.get('end'),kw.get('step')
     is_login_node,kw = run_vasp.clean_parse(kw,'is_login_node',False)
     kw.pop('start');kw.pop('end');kw.pop('step')
     kpts = Kpoints()
     kpts_list = set()
     kppa_list = []
     for kppa in range(start,end,step):
         kpts.automatic_density(structure=read_vasp(self.poscar),kppa=kppa)
         if tuple(kpts.kpts[0]) not in kpts_list:
             kpts_list.add(tuple(kpts.kpts[0]))
             kppa_list.append(kppa)
     idx = 0
     for kppa in kppa_list:
         _kw = kw.copy()
         if 'style' not in _kw:
             _kw.update({'kppa':kppa,'style':'auto','job_name':'test_kpts'+str(idx),'NSW':0})
         prep_vasp.prep_single_vasp(poscar=self.poscar,kw=_kw)
         idx += 1
     for i in range(idx):
         run_vasp.run_single_vasp(job_name='test_kpts'+str(i),is_login_node=is_login_node)
     kpts_res = []
     for ii in range(len(kppa_list)):
         EV = ExtractValue(data_folder='test_kpts'+str(ii))
         kpts_res.append([kppa_list[ii],EV.get_energy(),EV.get_cpu_time()])
     with open('test_kpts.txt','w') as f:
         f.writelines('KPTS\tEnergy\tcpu_time\n')
         for line in kpts_res:
             f.writelines(str(line[0])+'\t'+str(line[1])+'\t'+str(line[2])+'\n')
Пример #3
0
def main(wd, attribute, number):
    """
    Example:

    pyvasp main -a gap  # this can read the gap and vbm, cbm

    pyvasp main -a fermi  -w work_dir  # this can read the fermi energy, -w is your work directory

    pyvasp main -a energy  # this can read the total energy

    pyvasp main -a ele  # this can read the electrons in your OUTCAR

    pyvasp main -a ele-free  # this can get electrons number of  the defect-free system

    pyvasp main -a  Ewald  # this can get the Ewald energy of your system

    pyvasp main -a cpu  # this can get CPU time
    """

    EV = ExtractValue(wd)
    if 'gap' in attribute:
        get_gap(EV)
    elif 'fermi' in attribute:
        click.echo(EV.get_fermi())
    elif 'total' in attribute.lower() or 'energy' in attribute.lower():
        click.echo(EV.get_energy())
    elif 'ele' in attribute.lower() and 'free' in attribute.lower():
        click.echo(EV.get_Ne_defect_free())
    elif 'ele' in attribute.lower() and 'free' not in attribute.lower(
    ) and 'static' not in attribute.lower():
        click.echo(EV.get_Ne_defect())
    elif 'ima' in attribute or 'ewald' in attribute.lower():
        clikc.echo(EV.get_image())
    elif 'elect' in attribute and 'static' in attribute:
        outcar = os.path.join(wd, 'OUTCAR')
        click.echo(str(number) + ' ' + str(get_ele_sta(outcar, number)))
    elif 'cpu' in attribute.lower():
        click.echo(EV.get_cpu_time())
Пример #4
0
def energy(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_energy())
Пример #5
0
def fermi(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_fermi())
Пример #6
0
def gap(wd, vo, co):
    EV = ExtractValue(wd)
    get_gap(EV, float(vo), float(co))
Пример #7
0
def ewald(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_image())
Пример #8
0
def electron_number(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_Ne_defect())
Пример #9
0
def electron_defect_free(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_Ne_defect_free())
Пример #10
0
def get_defect_formation_energy(data_dir, defect_dirs):
    print('The main direcroty is: ', data_dir)
    f = open(os.path.join(data_dir, 'defect-log.txt'), 'w')
    fig, ax = plt.subplots()
    for defect_dir in defect_dirs:
        print('Reading ', defect_dir)
        f.write(defect_dir + '\n')
        SC_energy = ExtractValue(os.path.join(data_dir,
                                              'supercell/scf/')).get_energy()
        print('Energy of supcell is: ' + str(SC_energy) + ' eV')
        f.write('Energy of supcell is: ' + str(SC_energy) + ' eV\n')
        res = ExtractValue(os.path.join(data_dir, 'supercell/scf/')).get_gap()
        if len(res) == 3:
            Evbm, Ecbm, gap = res
        elif len(res) == 2:
            Evbm, Ecbm, gap = res[0]
        print('Evbm, Ecbm, gap of supcell is: ', Evbm, Ecbm, gap)
        f.write('Evbm: ' + str(Evbm) + ' eV\n' + 'Ecbm: ' + str(Ecbm) +
                ' eV\n' + 'gap: ' + str(gap) + ' eV\n')
        chg_state = []
        f.write(
            'charge\t\tenergy\t\tE_PA\t\tE_IC\tfar_atom_def_sys\tfar_atom_def_fr_system\n'
        )
        for chg_fd in os.listdir(os.path.join(defect_dir)):
            if 'charge_state_' in chg_fd:
                q = chg_fd.split('_')[-1]
                e = ExtractValue(os.path.join(defect_dir, chg_fd,
                                              'scf')).get_energy()
                no_def_poscar = os.path.join(data_dir, 'supercell',
                                             'scf/CONTCAR')
                def_poscar = os.path.join(defect_dir, chg_fd, 'POSCAR')
                num_def, num_no_def = get_farther_atom_num(
                    no_def_poscar, def_poscar)
                pa_def = get_ele_sta(
                    os.path.join(defect_dir, chg_fd, 'scf', 'OUTCAR'), num_def)
                pa_no_def = get_ele_sta(
                    os.path.join(data_dir, 'supercell', 'scf', 'OUTCAR'),
                    num_no_def)
                E_imagecor = ExtractValue(os.path.join(
                    data_dir, 'image_corr')).get_image()
                chg_state.append([
                    int(float(q)), e, pa_def - pa_no_def, E_imagecor, num_def,
                    num_no_def
                ])
        ele_in_out = read_incar('element-in-out')
        incar_para = read_incar(os.path.join(data_dir, 'defect-incar'))
        incar_para['mu_Vacc'] = 0
        if 'epsilon' in incar_para:
            epsilon = float(incar_para['epsilon'])
        else:
            epsilon = 1e10
            warnings.warn(
                "You should specify epsilon in your defect-incar, here we just ignore this correlation"
            )
        chg_state = np.asarray(chg_state)
        chg_state[:, 2] = chg_state[:, 2] * chg_state[:, 0]
        chg_state[:,
                  3] = -2 / 3 * chg_state[:, 0]**2 * chg_state[:, 3] / epsilon
        for c in chg_state:
            f.write(
                '{:2d}\t\t{:.5f}\t{:+.5f}\t{:+.5f}\t{:d}\t\t\t{:d}\n'.format(
                    int(c[0]), c[1], c[2], c[3], int(c[4]), int(c[5])))
        mu = 0
        for key, val in ele_in_out.items():
            if 'mu_' + key in incar_para:
                mu += float(incar_para['mu_' + key]) * int(val)
                f.write('chemical potential of ' + key.title() + ': ' +
                        str(incar_para['mu_' + key]) + ' eV\n')
            else:
                raise ValueError('chemical potential mu_' + key.title() +
                                 ' cannot found')
        os.system('rm element-in-out')
        for key, val in ele_in_out.items():
            if int(val) == -1:
                f.writelines(key.title() + ' has been doped\n')
            else:
                f.writelines(key.title() + ' has been removed\n')
        f.writelines('\n')
        Ef = np.linspace(Evbm, Ecbm, 1000)
        chg_state = np.asarray(chg_state)
        E = []
        for idx in range(np.shape(chg_state)[0]):
            E.append(chg_state[idx, 1] - SC_energy + mu +
                     chg_state[idx, 0] * Ef + chg_state[idx, 2] +
                     chg_state[idx, 3])
        E = np.asarray(E)
        ax.set_aspect('equal')
        ax.plot(Ef - Evbm, np.min(E, axis=0), label=defect_dir)
    f.close()
    plt.xlabel(r'$E_F$ (eV)')
    plt.ylabel(r'$\Delta E (eV)$')
    plt.legend()
    plt.savefig(os.path.join(data_dir, 'defect_formation_energy.png'), dpi=450)
Пример #11
0
def get_grd_state(job_name,start_job_num,end_job_num):
    energy = []
    for ii in range(start_job_num,end_job_num+1):
        EV = ExtractValue(data_folder=job_name+str(ii))
        energy.append(EV.get_energy())
    return np.argmin(energy)
Пример #12
0
def gap(wd):
    EV = ExtractValue(wd)
    get_gap(EV)
Пример #13
0
def cpu(wd):
    EV = ExtractValue(wd)
    click.echo(EV.get_cpu_time())