Exemple #1
0
def main():

    data = parse_procar(sys.argv[1])

    Ef = float(sys.argv[2])
    fig = pl.figure()
    #ax=fig.add_subplot(111)
    nkpt = data[3].shape[0]
    dE = 0.1
    sigma = 0.02
    nband = data[3].shape[1]
    E = np.arange(-5, 5, dE)
    kpt = np.arange(0, nkpt, 1)
    spect = np.zeros((nkpt, len(E)))
    for x in range(nkpt):
        for y in range(len(E)):
            result = 0
            for j in range(nband):
                result += gau(data[3][x, j, 0], E[y], sigma) * sum(
                    data[-2][x, :, j, 0, 0])
            spect[x, -1 - y] = result
    #for i in range(nkpt):
    #    spect[i]*=1.0/max(spect[i])
    #def readspect(x,y,sigma,data):
    #   result=0
    #   for j in range(nband):


#	result+=gau(data[3][x,j,0],E[y],sigma)*sum(data[-2][x,:,j,0,0])
#     return result
#  spect=readspect(X,Y,sigma,data)
#for i in range(nkpt):
#   for j in range(nband):
#   	for energy in range(NE)
#   col=sum(data[-2][i,:,:,0,0])
#   pl.scatter([i]*data[3].shape[1],data[3][i,:,0],s=15, c=col,vmin=min(col),vmax=max(col),edgecolors='none')
    pl.imshow(spect.T, alpha=.9, interpolation='bicubic')
    pl.colorbar()
    for i in range(len(E)):
        if E[i] < Ef and E[i + 1] > Ef:
            pl.axhline(y=len(E) - 1 - i, color='w')
            break
    pl.show()
def main():
    desc_str = 'Unfold bands calculated by VASP. For this, phase '\
               'information needs to be present in the PROCAR file '\
               'which means that bands need to be calculated with '\
               'the option LORBIT=12 specified in the INCAR file. '\
               'The required input consists of POSCAR file, PROCAR '\
               'file and a set of up to three fractional translations. '\
               'There is no need to specify all translations, just the '\
               'generators. The programs will generate all distinct '\
               'translations from the generators and generate all irreps. '\
               'NOTE: In cas of non-collinear spin-polarized calculations ' \
               'mx, my and mz components of orbital weights are not ' \
               'unfolded, only spin up and spin down totals.'
               
               
    parser = argparse.ArgumentParser(prog='vasp_unfold', description = desc_str)

    parser.add_argument('poscar', type=str, help='POSCAR file')     
    parser.add_argument('procar', type=str, help='PROCAR file')

    parser.add_argument('--tgen', type=translation, action='append',
                        metavar='SX,SY,SZ', help='Fractional translation '
                        'generator. No whitespaces are allowed between the '
                        'components! SX, SY and SZ can be either 0 or 1/n, '
                        'where n is an integer. Up to three linearly '
                        'independant generators can be specified.')

    parser.add_argument('--out', type=str, help='Output filename. If left '
                        'unspecified  output is writen to PROCAR.irrep.n '
                        'where PROCAR is location of the input PROCAR file. '
                        'If specified, output is written to OUT.irrep.n.')
    
    parser.add_argument('--eps', type=float, default=1e-6, help='Numerical '
                        'precision. When building permutation representation '
                        'of the fractional translations this parameter is used '
                        'to determine whether two fractional positions are '
                        'identical. For irregular structures, it may need to '
                        'be increased. If this does not help, try to tweak '
                        'the atomic positions in POSCAR to make the structure '
                        'more regular. Default is 1e-6.')
    
    parser.add_argument('--all-irreps', default=False, action='store_true',
                        help='Flag specifying that all irreps from the unfolding '
                        'will be written to the output. By default, only irrep 0 '
                        '(unit irrep) is written out.')
                        
    parser.add_argument('--check-mapping', action='store_true', default=False,
                        help='Specifies to check if supplied translation '
                        'generators generate fractional translations which are '
                        'one-to-one, ie. map every atom on exactly one other atom '
                        'in the unit cell. This MUST not be enabled for the cases '
                        'where vacancies or excess atoms are present.')
                                                                     
    args = parser.parse_args()
    
    tgens = args.tgen
    
    trans, irreps = build_translations(tgens)
    
    try:
        cell, spos, symbols = parse_poscar(args.poscar)
    except:
        post_error('Unable to parse the input POSCAR file. Please '
            'check if the file exists and is formatted properly')
    
    ops = build_operators(spos, trans, args.check_mapping, args.eps)
    
    try:
        data = parse_procar(args.procar)
    except:
        post_error(errors.poscar_parse_error)
    
    if data[-1] is None:
        post_error('Phase information has to be present in the PROCAR '
            'file. Please repeat the calculation with LORBIT=12.')

    phases = np.copy(data[-1])
    
    norbs = phases.shape[1]/len(spos)
    
    projs = build_projectors(irreps, ops, norbs)
    
    if args.out is None:
        output = args.procar
    else:
        output = args.out
    
    if args.all_irreps:
        nirrep = len(projs)
    else:
        nirrep = 1
        
    for i, p in enumerate(projs[:nirrep]):
        for s in xrange(data[-1].shape[-1]):
            try:
                data[-1][:,:,:,s] = np.dot(p, phases[:,:,:,s]).swapaxes(0, 1)
            except:
                post_error('Unable to apply projectors. Are you sure '
                    'that specified POSCAR and PROCAR file belong to '
                    'the same crystal structure?')
        
        # We update total absolute weights to correspond to
        # unfolded phases (by multiplying them by the magnitude
        # ratio of unfolded and folded phases 
        phase_ratio = np.abs(data[-1])/(np.abs(phases)+1e-4)
        
        for idim in xrange(data[-2].shape[3]):
            data[-2][:,:,:,idim,:] *= phase_ratio

        write_procar('{0}.irrep.{1}'.format(output, i), *data)
def main():
  '''
    return orbitals, kpoints, kweights, bands, occupancies, \
           weights[:,:,:,:dim,:], phases

    orbitals    - (norbs) string array of orbital labels (s, px, py etc...)
    kpoints     - (npoints,3) float array of k-point coordinates
    kweights    - (npoints) float array of k-point weights
    bands       - (npoints,nbands,nspin) float array of band energies
    occupancies - (npoints,nbands,nspin) float array of band occupancies
    weights     - (npoints,nions*norbs,nbands,ndim,nspin) float array
                  of orbital weights
    ndim = 1 collinear, 4 otherwise
    phases      - (npoints,nions*norbs,nbands,nspin) complex array of
                  phases of orbital weights if LORBIT=12, otherwise None
  '''
  data=parse_procar(sys.argv[1])
  idim=0
  Ef=float(sys.argv[2])
  ispin=int(sys.argv[3])
#ax=fig.add_subplot(111)
  nkpt=data[3].shape[0]
  nband=data[3].shape[1]
  band=data[3]
  kpts=data[1]
  orbitals=data[0]
  norb=len(orbitals)
  weight=data[-2]
  projorb=[['dxz','dxy','dyz','dz2','dx2'],['dxz','dxy','dyz','dz2','dx2'],\
	  ['px','py','pz']]
#  projorb=[['dxz','dxy','dyz','dz2','dx2'],['dxz','dxy','dyz','dz2','dx2'],['dxz','dxy','dyz','dz2','dx2'],\
#         ['px','py','pz'],['px','py','pz']]
  #projorb=[['dxz','dxy','dyz','dz2','dx2']]
  mycolor=['g','r','b']
  orb_index=[]
  
  for i in range(len(projorb)): # orbital index
      orb_temp=[]
      for j in projorb[i]:
          orb_temp.append(orbitals.index(j))
      orb_index.append(orb_temp)
  projion= [[2,3],\
  	    [11],[19,23]]
	    #[27,31,43,47]] #,\
  	  #  [ i for i in range(4,8)]] #,\
	   # [19,23]]
	  # [27,34,40,46]]
	  # [31,33,43,45]]
	 #  [27,34,40,46]]
	 #  [i for i in range(8,31)]+[32]+[j for j in range(33,43)]+[44]+[k for k in range(46,48)] ]
  
  if len(projion)!=len(projorb):
      print 'projected orbital are not specified clearly with projected ions'
      sys.exit(0)
  
  fig=pl.figure()
  ax=fig.add_subplot(111)
  #for i in range(band.shape[1]):
  #    ax.plot(band[:,i,ispin],c='k')
  if len(projorb)>0:
      klist=np.arange(0,nkpt,1)
      for i_at_type in range(len(projorb)):
          weight_plot=np.zeros((nkpt,nband))
      
          for i in range(nband):
      	      for ion in projion[i_at_type]:
	          for orb in  orb_index[i_at_type]:
	                  weight_plot[:,i]+=weight[:,(ion)*norb+orb,i,0,ispin]
      #for i in range(nband):
              ax.scatter(klist,band[:,i,ispin],c=mycolor[i_at_type],s=(weight_plot[:,i]*40),alpha=0.7,edgecolors='none')      
  pl.axhline(y=Ef,color='k')
  kpath=np.array([[0,0,0],[0.5,0,0],[0.5,0.5,0],[0,0,0]])
  xticker=[]
  j=0
  for i in range(len(kpts)):

    if LA.norm(kpts[i]-kpath[j])==0:
        xticker.append(i)
        j+=1
        pl.axvline(x=i,color='k')

  pl.ylabel('Energy(eV)')
  pl.xlim(0,len(klist)-1)
  pl.ylim(-3,6)
  #pl.ylim(-10,5)
#xlabels = ["$\Gamma$","Z","T",'Y',"$\Gamma$",'X','S','R','U']
  xlabels= [r"$\Gamma$","X","M",r'$\Gamma$']
  ax.set_xticks(xticker)
  ax.set_xticklabels(xlabels)
  
  
  pl.show()
  fig.savefig('./band_int.png')

desc_str = '''Simple program used to quickly plot the orbital weights
of the band structure contained in the specified PROCAR file.
'''

parser = argparse.ArgumentParser(prog='plotprocar', description=desc_str)

arguments.add_io_arguments(parser)
arguments.add_fig_arguments(parser)
arguments.add_plot_arguments(parser)

args = parser.parse_args()

struct = parse.parse_poscar(args.poscar)
orbitals, kpt, kweights, energy, occupancies, weights, phases = parse.parse_procar(
    args.procar)
kpt = np.matrix(kpt)
kpt = kpt * struct._reciprocal_cell()

nspin = int(os.popen('grep ISPIN OUTCAR').readline().split()[2])
if os.popen('grep LNONCOLLINEAR OUTCAR').readline().split()[2] == 'T':
    print 'noncollinear spin polarized calculations'
    nspin = 2
nelect = float(os.popen('grep NELECT OUTCAR').readline().split()[2])
nelect = int(nelect)
print 'energy.shape:', energy.shape
print 'weights.shape:', weights.shape
#get_bandgap(nspin,energy,nelect)

if args.efermi == 0:
    try:
Exemple #5
0
def main():
    data = parse_procar(sys.argv[1])
    print "PROCAR read successfully"
    idim = 0
    Ef = float(sys.argv[2])
    ispin = int(sys.argv[3])
    #ax=fig.add_subplot(111)
    nkpt = data[3].shape[0]
    nband = data[3].shape[1]
    band = data[3]
    kpts = data[1]
    orbitals = data[0]
    norb = len(orbitals)
    weight = data[-2]
    phases = data[-1]
    orb_index = []

    WF_map = np.loadtxt(wfmap_file)
    nband_s, dum = WF_map.shape
    nband_p = int(nband_s * V_p / V_s)
    #    evals=np.zeros((nband,nkpt,2)) # evals and weights

    for j in range(len(projorb)):  # orbital index
        temp = []
        for i in projorb[j]:
            temp.append(orbitals.index(i))
        orb_index.append(temp)

#    projion=[ i for i in range(2,4)] # the ions that should be focus on
# read projion from unfold_in

    fig = pl.figure(figsize=(4, 6))
    ax = fig.add_subplot(111)
    #    for i in range(nband):
    #      ax.plot(band[:,i,ispin],c='k')
    if len(projorb) > 0:
        klist = np.arange(0, nkpt, 1)
        for i_at_type in range(len(projorb)):
            weight_plot = np.zeros((nkpt, nband), dtype=complex)

            for i in range(nband):
                for orb in orb_index[i_at_type]:
                    for ii, ion in enumerate(projion[i_at_type]):

                        #weight_plot[:,i]+=weight[:,(ion)*norb+orb,i,0,ispin] \
                        weight_plot[:,i]+=phases[:,(ion)*norb+orb,i,ispin] \
                               * (np.exp(-2j*np.pi*np.dot(kpath[:],WF_map[ii,2:])))
                ax.scatter(klist,
                           band[:, i, ispin],
                           c=mycolor[i_at_type],
                           s=(abs(weight_plot[:, i])**2 * 40),
                           alpha=0.7,
                           edgecolors='none')


#-------------------------------------------
    pl.axhline(y=Ef, color='k')
    xticker = []
    j = 0
    for i in range(len(kpts)):

        if LA.norm(kpts[i] - Kpts[j]) == 0:
            xticker.append(i)
            j += 1
            pl.axvline(x=i, color='k')

    pl.ylabel('Energy(eV)')
    pl.xlim(0, len(klist) - 1)
    pl.ylim(-1, 3.5)
    #pl.ylim(-10,5)
    #xlabels = ["$\Gamma$","Z","T",'Y',"$\Gamma$",'X','S','R','U']
    ax.set_xticks(xticker)
    ax.set_xticklabels(xlabels)
    pl.legend(loc='best')

    pl.tight_layout()
    pl.show()
    fig.savefig('./band_int.png')
Exemple #6
0
def main():
    '''
    return orbitals, kpoints, kweights, bands, occupancies, \
           weights[:,:,:,:dim,:], phases

    orbitals    - (norbs) string array of orbital labels (s, px, py etc...)
    kpoints     - (npoints,3) float array of k-point coordinates
    kweights    - (npoints) float array of k-point weights
    bands       - (npoints,nbands,nspin) float array of band energies
    occupancies - (npoints,nbands,nspin) float array of band occupancies
    weights     - (npoints,nions*norbs,nbands,ndim,nspin) float array
                  of orbital weights
    ndim = 1 collinear, 4 otherwise
    phases      - (npoints,nions*norbs,nbands,nspin) complex array of
                  phases of orbital weights if LORBIT=12, otherwise None
  '''
    data = parse_procar(sys.argv[1])
    idim = 0
    Ef = float(sys.argv[2])
    ispin = int(sys.argv[3])
    #ax=fig.add_subplot(111)
    nkpt = data[3].shape[0]
    nband = data[3].shape[1]
    band = data[3]
    kpts = data[1]
    orbitals = data[0]
    norb = len(orbitals)
    weight = data[-2]
    projorb = [['dxz', 'dxy', 'dyz'], ['dx2', 'dz2']]
    colors = ['b', 'r']
    orb_index = []
    for j in range(len(projorb)):  # orbital index
        temp = []
        for i in projorb[j]:
            temp.append(orbitals.index(i))
        orb_index.append(temp)

    projion = [i for i in range(8, 12)]
    fig = pl.figure()
    ax = fig.add_subplot(111)
    for i in range(band.shape[1]):
        ax.plot(band[:, i, ispin], c='k')
    for iatom in range(len(projorb)):

        weight_plot = np.zeros((nkpt, nband))
        for i in range(nband):
            for ion in projion:
                for orb in orb_index[iatom]:
                    weight_plot[:, i] += weight[:, (ion) * norb + orb, i, 0,
                                                ispin]
        klist = np.arange(0, nkpt, 1)

        for i in range(nband):
            ax.scatter(klist,
                       band[:, i, ispin],
                       c=colors[iatom],
                       s=(weight_plot[:, i] * 50),
                       edgecolors='none')

    kpath = np.array([[0, 0, 0], [0.5, 0., 0], [0.5, 0.5, 0.], [0, 0, 0]])
    xticker = []
    j = 0
    for i in range(len(kpts)):
        if LA.norm(kpts[i] - kpath[j]) == 0:
            xticker.append(i)
            j += 1
            pl.axvline(x=i, color='k')

    pl.ylabel('Energy(eV)')
    pl.xlim(0, len(klist) - 1)
    #xlabels = ["$\Gamma$","Z","T",'Y',"$\Gamma$",'X','S','R','U']
    #pl.ylim(0,11)
    pl.ylim(-3, 6)
    xlabels = ["$\Gamma$", "X", "S", '$\Gamma$']
    ax.set_xticks(xticker)
    ax.set_xticklabels(xlabels)

    pl.axhline(y=Ef, color='k')

    pl.show()
Exemple #7
0
    if contrast:
       ldos=ldos**contrast
    return ldos


if args.efermi==0:
   try:
      line=os.popen("grep fermi OUTCAR|tail -1").readline()
      efermi=float(line.split()[2])
      print 'fermi energy is',efermi
   except:
      print "Note: The fermi energy is 0!"
      efermi=args.efermi

struct = parse.parse_poscar(args.poscar)
orbitals, kpt, kweights, eigenval, occupancies, weights, phases = parse.parse_procar(args.procar,efermi=efermi)
kpt=np.matrix(kpt)
kpt=kpt*struct._reciprocal_cell()


'''
efermi=0
filename='band.dat'
v = np.fromfile(filename,sep=' ')
ncol=4
v = v.reshape(v.shape[0]/ncol,ncol)
nkpt=len(set(v[:,0]))
nrow=v.shape[0]/nkpt
print " {0:8d} bands, {1:8d} k-points".format(nrow,nkpt)

kpt = v[:,0].reshape(nkpt,nrow)