Пример #1
0
def smart_surf(strt=None, tol=0.1):
    """
    Umbrell function for surface energies with convergence

    Args:
       strt: Structure object
       tol: surface energy convergence tolerance in eV
    Returns:
          surf_list: list of surface energies
          surf_header_list: list of surface names
           
    """
    sg_mat = SpacegroupAnalyzer(strt)
    mat_cvn = sg_mat.get_conventional_standard_structure()
    mat_cvn.sort()
    layers = 2
    indices = get_symmetrically_distinct_miller_indices(mat_cvn, 1)
    ase_atoms = AseAtomsAdaptor().get_atoms(mat_cvn)
    for i in indices:
        ase_slab = surface(ase_atoms, i, layers)
        ase_slab.center(vacuum=15, axis=2)
        if len(ase_slab) < 50:
            layers = 3
    surf_arr = []
    surf_done = 0
    surf = surfer(mat=strt, layers=layers)
    surf_list = [100000 for y in range(len(surf) - 1)]
    print("in smart_surf :surf,surf_list=", surf, surf_list)
    while surf_done != 1:
        layers = layers + 1
        indices = get_symmetrically_distinct_miller_indices(mat_cvn, 1)
        ase_atoms = AseAtomsAdaptor().get_atoms(mat_cvn)
        for i in indices:
            ase_slab = surface(ase_atoms, i, layers)
            ase_slab.center(vacuum=15, axis=2)
            if len(ase_slab) > 100:
                surf_done = 1
            if (ase_slab.get_cell()[2][2]) > 40:
                surf_done = 1
        surf = surfer(mat=strt, layers=layers)
        if surf not in surf_arr:
            surf_arr.append(surf)
            surf_list2, surf_header_list = surf_energy(surf=surf)
            print("in smart_surf :surf2,surf_list2=", surf_list2,
                  surf_header_list)
            diff = matrix(surf_list) - matrix(surf_list2)
            print("in smart_surf :surf3,surf_list3=", matrix(surf_list),
                  matrix(surf_list2))
            diff_arr = np.array(diff).flatten()
            if any(diff_arr) > tol:
                #for el in diff_arr:
                #    if abs(el)>tol :
                #        print ("in smart_surf :abs el=",abs(el))
                surf_done = 0
                surf_list = surf_list2
            else:
                surf_done = 1
    return surf_list, surf_header_list
Пример #2
0
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