def smart_vac(strt=None,tol=0.1): """ Umbrell function for vacancy formation energies with convergence Args: strt: Structure object tol: defect energy convergence tolerance in eV Returns: def_list: list of defect energies def_header_list: list of defect names """ vac_arr=[] sg_mat = SpacegroupAnalyzer(strt) mat_cvn = sg_mat.get_conventional_standard_structure() mat_cvn.sort() cellmax=1 #int(mat_cvn.composition.num_atoms)+int(mat_cvn.ntypesp)#5 ase_atoms = AseAtomsAdaptor().get_atoms(mat_cvn) ase_atoms=ase_atoms*(cellmax,cellmax,cellmax) #if len(ase_atoms) >200: # cellmax=1 #else: # cellmax=2 #cellmax=int(mat_cvn.composition.num_atoms)+int(mat_cvn.ntypesp)#5 print ("type of trt is= celmmax",type(strt),cellmax) try: print ("int(strt.composition.num_atoms)",int(strt.composition.num_atoms)) print (int(strt.ntypesp)) except: pass #cellmax=int(strt.composition.num_atoms)+int(strt.ntypesp) vac_done=0 vac=vac_antisite_def_struct_gen(cellmax=cellmax,struct=strt) def_list=[100000 for y in range(len(vac)-1)] while vac_done !=1: vac=vac_antisite_def_struct_gen(cellmax=cellmax,struct=strt) if vac not in vac_arr: vac_arr.append(vac) print ("in smart_vac(strt=None), cellmax,vac,vac_done=",cellmax,vac,vac_done) def_list2,header_list=def_energy(vac=vac) diff=matrix(def_list)-matrix(def_list2) diff_arr=np.array(diff).flatten() print ("in smart_vac(strt=None diff_arr=",diff_arr) if any(diff_arr)>tol: # for el in diff_arr: # if abs(el)>tol : # print ("in smart_vac(strt=None abs_el=",abs(el)) vac_done=0 cellmax=cellmax+1 ase_atoms = AseAtomsAdaptor().get_atoms(mat_cvn) ase_atoms=ase_atoms*(cellmax,cellmax,cellmax) if len(ase_atoms) >100: vac_done=1 def_list=def_list2 else: vac_done=1 # cellmax=cellmax+1 return def_list,header_list
def smart_converge(mat=None,encut='',leng='',band_str=True,elast_prop=True,optical_prop=True,mbj_prop=True,spin_orb=False,phonon=False,surf_en=False,def_en=False): """ Main function to converge k-points/cut-off optimize structure, and run subsequent property calculations Args: mat: Poscar object with structure information encut: if '' then automataic convergence, else use defined fixed-cutoff leng: if '' then automataic convergence, else use defined fixed-line density band_str: if True then do band-structure calculations along high-symmetry points elast_prop: if True then do elastic property calculations using finite-difference optical_prop: if True do frequency dependent dielectric function calculations using he independent-particle (IP) approximation mbj_prop: if True do METAGGA-TBmBJ optical property calculations with IP approximation spin_orb: if True do spin-orbit calculations phonon: if True do phonon calculations using DFPT surf_en: if True do surface enrgy calculations def_en: if True do defect enrgy calculations Returns: en2: final energy mat_f: final structure """ if encut=="": encut=converg_encut(encut=500,mat=mat) if leng=="": leng= converg_kpoints(length=0,mat=mat) kpoints=Auto_Kpoints(mat=mat,length=leng) isif=2 commen=str(mat.comment) lcharg='.FALSE.' if commen.split('@')[0] =='bulk' : isif=3 lcharg='.TRUE.' if commen.split('@')[0] == 'sbulk': isif=3 incar_dict = use_incar_dict incar_dict.update({"ENCUT":encut,"EDIFFG":-1E-3,"ISIF":3,"NEDOS":5000,"NSW":500,"NELM":500,"LORBIT":11,"LVTOT":'.TRUE.',"LVHAR":'.TRUE.',"ISPIN":2,"LCHARG":'.TRUE.'}) incar = Incar.from_dict(incar_dict) try: if mat.comment.startswith('Mol'): incar.update({"ISIF": '2'}) except: print ("Mol error") pass #if commen.startswith('Surf-') : # pol=check_polar(mat_f.structure) # if pol==True: # ase_atoms = AseAtomsAdaptor().get_atoms(mat_f.structure) # COM=ase_atoms.get_center_of_mass(scaled=True) # incar.update({"LDIPOL": '.TRUE.',"IDIPOL":4,"ISYM": 0,"DIPOL":COM}) print ("running smart_converge for",str(mat.comment)+str('-')+str('MAIN-RELAX')) cwd=str(os.getcwd()) en2,contc=run_job(mat=mat,incar=incar,kpoints=kpoints,jobname=str('MAIN-RELAX')+str('-')+str(mat.comment)) os.chdir(cwd) path=str(contc.split('/CONTCAR')[0])+str('/vasprun.xml') v=open(path,"r").readlines() for line in v: if "NBANDS" in line: nbands=int(line.split(">")[1].split("<")[0]) print ("nbands=",nbands) break strt=Structure.from_file(contc) mat_f=Poscar(strt) mat_f.comment=str(mat.comment) if band_str==True: incar_dict = use_incar_dict incar_dict.update({"ISPIN":2,"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":int(nbands)+10}) incar = Incar.from_dict(incar_dict) kpath = HighSymmKpath(mat_f.structure) frac_k_points, k_points_labels = kpath.get_kpoints(line_density=20,coords_are_cartesian=False) kpoints = Kpoints(comment="Non SCF run along symmetry lines",style=Kpoints.supported_modes.Reciprocal,num_kpts=len(frac_k_points),kpts=frac_k_points, labels=k_points_labels,kpts_weights=[1] * len(frac_k_points)) try: print ("running MAIN-BAND") kpoints=mpvis.get_kpoints(mat_f.structure) en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment)) # kpoints=mpvis.get_kpoints(mat_f.structure) # en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment)) except: print ("No band str calc.") if str(os.getcwd)!=cwd: print ("Changing directory") line=str("cd ")+str(cwd) os.chdir(cwd) print (os.getcwd()) pass os.chdir(cwd) if surf_en==True: incar_dict = use_incar_dict incar_dict.update({"ENCUT":encut,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11}) incar = Incar.from_dict(incar_dict) surf=surfer(mat=mat_f.structure,layers=3) for i in surf: try: print ("running MAIN-BAND") #NSCF #chg_file=str(contc).replace('CONTCAR','CHGCAR') #print ('chrfile',chg_file) #shutil.copy2(chg_file,'./') kpoints=Auto_Kpoints(mat=i,length=leng) en2s,contcs=run_job(mat=i,incar=incar,kpoints=kpoints,jobname=str('Surf_en-')+str(i.comment)+str('-')+str(mat_f.comment)) #kpoints=mpvis.get_kpoints(mat_f.structure) #en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) if def_en==True: incar_dict = use_incar_dict incar_dict.update({"ENCUT":encut,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11}) incar = Incar.from_dict(incar_dict) #surf=surfer(mat=mat_f.structure,layers=3) vac=vac_antisite_def_struct_gen(cellmax=3,struct=mat_f.structure) for i in vac: try: print ("running MAIN-vac") kpoints=Auto_Kpoints(mat=i,length=leng) en2d,contcd=run_job(mat=i,incar=incar,kpoints=kpoints,jobname=str('Def_en-')+str(i.comment)+str('-')+str(mat_f.comment)) # kpoints=mpvis.get_kpoints(mat_f.structure) # en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) #surf=surfer(mat=strt,layers=layers) #surf=surfer(mat=strt,layers=layers) if spin_orb==True: #chg_file=str(contc).replace('CONTCAR','CHGCAR') #print ('chrfile',chg_file) #shutil.copy2(chg_file,'./') incar_dict = use_incar_dict incar_dict.update({"ENCUT":encut,"NPAR":ncores,"GGA_COMPAT":'.FALSE.',"LSORBIT":'.TRUE.',"IBRION":1,"ISYM":0,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11}) incar = Incar.from_dict(incar_dict) sg_mat = SpacegroupAnalyzer(mat_f.structure) mat_cvn = sg_mat.get_conventional_standard_structure() mat_cvn.sort() kpoints=Auto_Kpoints(mat=Poscar(mat_cvn),length=leng/2) try: en2S,contcS=run_job(mat=Poscar(mat_cvn),incar=incar,kpoints=kpoints,jobname=str('MAIN-SOC')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) if optical_prop==True: incar_dict = use_incar_dict incar_dict.update({"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":3*int(nbands),"LOPTICS":'.TRUE.'}) incar = Incar.from_dict(incar_dict) kpoints=Auto_Kpoints(mat=mat_f,length=leng) try: en2OP,contcOP=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-OPTICS')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) if mbj_prop==True: incar_dict = use_incar_dict incar_dict.update({"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":3*int(nbands),"LOPTICS":'.TRUE.','METAGGA':'MBJ','ISYM':0,"SIGMA":0.1}) incar = Incar.from_dict(incar_dict) kpoints=Auto_Kpoints(mat=mat_f,length=leng) try: en2OP,contcOP=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-MBJ')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) if elast_prop==True: incar_dict = use_incar_dict incar_dict.update({"NEDOS":5000,"IBRION":6,"ENCUT":1.3*float(encut),"ISIF":3,"POTIM":0.015,"NPAR":ncores,"ISPIN":2}) incar = Incar.from_dict(incar_dict) sg_mat = SpacegroupAnalyzer(mat_f.structure) mat_cvn = sg_mat.get_conventional_standard_structure() mat_cvn.sort() kpoints=Auto_Kpoints(mat=Poscar(mat_cvn),length=leng) try: en2E,contcE=run_job(mat=Poscar(mat_cvn),incar=incar,kpoints=kpoints,jobname=str('MAIN-ELASTIC')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) if phonon==True: incar_dict = use_incar_dict incar_dict.update({"IBRION":8,"ENCUT":float(encut),"ISYM":0,"ADDGRID":'.TRUE.','EDIFF': 1e-09,'LORBIT': 11}) incar = Incar.from_dict(incar_dict) kpoints=Auto_Kpoints(mat=mat_f,length=leng) mat_pho=make_big(poscar=mat_f,size=11.0) try: en2P,contcP=run_job(mat=mat_pho,incar=incar,kpoints=kpoints,jobname=str('MAIN-PHO8')+str('-')+str(mat_f.comment)) except: pass os.chdir(cwd) #if Raman_calc==True: # Raman(strt=mat_f,encut=encut,length=leng) os.chdir(cwd) return en2,mat_f