Exemplo n.º 1
0
def get_mp_phase_graph():
    mpr = check_apikey()
    compat = MaterialsProjectCompatibility()
    print("input the elements list")
    wait_sep()
    in_str = wait()
    elements = in_str.split()
    web = "materials.org"
    proc_str = "Reading Data From " + web + " ..."
    step_count = 1
    procs(proc_str, step_count, sp='-->>')
    unprocessed_entries = mpr.get_entries_in_chemsys(elements)
    processed_entries = compat.process_entries(unprocessed_entries)
    pd = PhaseDiagram(processed_entries)
    pdp = PDPlotter(pd, show_unstable=True)
    try:
        pdp.show()
    except:
        pass
    finally:
        step_count += 1
        filename = 'phase' + '-'.join(elements) + '.png'
        proc_str = "Writing Data to " + filename + " File..."
        procs(proc_str, step_count, sp='-->>')
        pdp.write_image(filename)
    return True
Exemplo n.º 2
0
def charge_density_diff():
   print("input the name of charge density file like this")
   print("file_A file_B, or")
   print("it means rho(A)-rho(B))")
   print("file_A file_B file_C")
   print("it means rho(A)-rho(B)-rho(C)")
   wait_sep()
   in_str=""
   while in_str=="":
         in_str=input().strip()
   filenames=in_str.split()
   len_file=len(filenames)
   chg=[None]*len_file
   if len_file>=2:
      for i in range(len_file):
          fchg=filenames[i]
          proc_str="Reading Charge Density From "+fchg+" File ..."
          procs(proc_str,i+1,sp='-->>')
          chg[i] = CHGCAR.from_file(fchg)
      diff_chg=copy(chg[0])
      for j in range(len_file-1):
          diff_chg-=chg[j+1]
      proc_str="Writing Charge Density Difference to Diff.vasp  File ..."
      procs(proc_str,i+2,sp='-->>')
      diff_chg.write_file('Diff.vasp','total')
   else:
      print("you must input at least 2 files") 
Exemplo n.º 3
0
def charge_density():
   proc_str="Reading Charge Density From CHG File ..."
   procs(proc_str,1,sp='-->>')
   chg = CHGCAR.from_file("CHG")
   proc_str="Writing Charge Density To CHARGE.vasp File ..."
   procs(proc_str,2,sp='-->>')
   chg.write_file('CHGARGE.vasp','total')
Exemplo n.º 4
0
def chg_locp_average():
   chg=False
   print("which file would like to average: CHG or LOCPOT ?")
   wait_sep()
   in_str=""
   while in_str=="":
         in_str=input().strip()
   if in_str.lower()=='chg':
      filename='CHG'
      check_file(filename)
      grid_data = CHGCAR.from_file(filename)
      head_line="#%(key1)+s %(key2)+s"%{'key1':'Distance/Ang','key2':'Average Charge/(e/Ang**3)'}
      chg=True
   elif in_str.lower()=='locpot':
      filename='LOCPOT'
      check_file(filename)
      grid_data = Locpot.from_file(filename)
      head_line="#%(key1)+s %(key2)+s"%{'key1':'Distance/Ang','key2':'Average Potential/(eV)'}
   else:
      print('unknown file file: '+in_str)
      os._exit()

   step_count=1
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   volume=grid_data.structure.volume 
   print("which direction would like to average: x y or z ?")
   wait_sep()
   in_str=""
   while in_str=="":
      in_str=input().strip().lower()
   if in_str=="x":
      selected_dir=0
   elif in_str=='y':
      selected_dir=1
   elif in_str=='z':
      selected_dir=2
   else:
       print("Unknow Direction!")
       return

   axis_grid=grid_data.get_axis_grid(selected_dir)
   if chg:
      aver_grid=grid_data.get_average_along_axis(selected_dir)/volume
   else:
      aver_grid=grid_data.get_average_along_axis(selected_dir)

   data=np.vstack((axis_grid,aver_grid)).T

   step_count+=1
   if chg:
      filename="average_CHG_"+in_str+'.dat'
   else:
      filename="average_LOCPOT_"+in_str+'.dat'

   proc_str="Writting Average Data to "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   write_col_data(filename,data,head_line)
Exemplo n.º 5
0
def get_mp_properties():
    mpr = check_apikey()
    print("input the mp-ID")
    wait_sep()
    in_str = wait()
    mp_id = in_str
    proc_str = "Reading Data From " + web + " ..."
    step_count = 1
    procs(proc_str, step_count, sp='-->>')
    data = mpr.get_data(mp_id)
    filename = mp_id + '.json'
    proc_str = "Writing Data To " + filename + " File ..."
    step_count += 1
    procs(proc_str, step_count, sp='-->>')
    dumpfn(data, filename)
    return True
Exemplo n.º 6
0
def get_mp_banddos():
    check_matplotlib()
    mpr = check_apikey()
    print("input the mp-ID")
    wait_sep()
    in_str = wait()
    mp_id = in_str
    step_count = 1
    proc_str = "Reading Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    data = mpr.get_entry_by_material_id(mp_id)
    sepline()
    print(data)
    sepline()
    step_count += 1
    proc_str = "Reading Band Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')

    band = mpr.get_bandstructure_by_material_id(mp_id)
    if band is None:
        print("No data obtained online, stop now!")
        os.exit(0)

    step_count += 1
    filename = mp_id + '_band.png'
    proc_str = "Writing Data to " + filename + " File..."
    bsp = BSPlotter(band)
    procs(proc_str, step_count, sp='-->>')
    bsp.save_plot(filename=filename, img_format="png")

    step_count += 1
    proc_str = "Reading DOS Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    dos = mpr.get_dos_by_material_id(mp_id)
    if dos is None:
        print("No data obtained online, stop now!")

    step_count += 1
    filename = mp_id + '_dos.png'
    proc_str = "Writing Data to " + filename + " File..."
    dsp = DosPlotter()
    dsp.add_dos('Total', dos)
    procs(proc_str, step_count, sp='-->>')
    dsp.save_plot(filename=filename, img_format="png")
Exemplo n.º 7
0
def get_oqmd_structure():
    print('{} >>> {}'.format('1', 'get a structure by oqmd-ID'))
    print('{} >>> {}'.format('2', 'get structures by fomular'))
    print('{} >>> {}'.format('3', 'get structures by elements'))
    print('{} >>> {}'.format('4', 'get structures by filters'))
    wait_sep()
    in_str = wait()
    choice = in_str
    qr = QMPYRester()
    if choice == "1":
        print("input the oqmd-ID")
        wait_sep()
        in_str = wait()
        oqmd_id = int(in_str)
        step_count = 1
        proc_str = "Reading Data From " + web + " ..."
        procs(proc_str, step_count, sp='-->>')
        data = qr.get_optimade_structure_by_id(oqmd_id)
        if data is None:
            print("Unknown OQMD-ID, check the OQMD-ID")
            return None
        else:
            struct = data_to_structure(data)
        filename = str(oqmd_id) + '.vasp'
        step_count += 1
        proc_str = "Writing Data to " + filename + " File..."
        procs(proc_str, step_count, sp='-->>')
        struct.to(filename=filename, fmt='POSCAR')
        return True
    elif choice == "2":
        print("Not supported now!")
        os._exit(0)
    elif choice == "3":
        print("Not supported now!")
        os._exit(0)
    elif choice == "4":
        print("Not supported now!")
        os._exit(0)
        #print("elements=O AND ( _oqmd_stability<-0.1 OR _oqmd_delta_e<-0.5)")
    else:
        print('Unknow choice')
        return None
Exemplo n.º 8
0
def spin_density():
   proc_str="Reading Spin Charge Density From CHG File ..."
   procs(proc_str,1,sp='-->>')
   chg = CHGCAR.from_file("CHG")
   assert(chg.is_spin_polarized)
   proc_str="Writing Total Charge Density To Total.vasp File ..."
   procs(proc_str,2,sp='-->>')
   chg.write_file('Total.vasp','total')
   proc_str="Writing Spin Charge Density To Spin.vasp File ..."
   procs(proc_str,3,sp='-->>')
   chg.write_file('Spin.vasp','diff')
Exemplo n.º 9
0
def spin_density_component():
   proc_str="Reading Spin Up/Down Density From CHG File ..."
   procs(proc_str,1,sp='-->>')
   chg = CHGCAR.from_file("CHG")
   assert(chg.is_spin_polarized)
   data=chg.spin_data.copy()
   chg.data={'spinup':data[Spin.up],'spindown':data[Spin.down]}
   proc_str="Writing Spin Up Density To Spinup.vasp File ..."
   procs(proc_str,2,sp='-->>')
   chg.write_file('Spinup.vasp','spinup')
   proc_str="Writing Spin Down Density To Spindown.vasp File ..."
   procs(proc_str,3,sp='-->>')
   chg.write_file('Spindown.vasp','spindown')
Exemplo n.º 10
0
def optics_analysis():

   filename='vasprun.xml'
   step_count=1
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   vsr=Vasprun(filename,parse_eigen=False)
   try:
     energy=np.array(vsr.dielectric[0])
     freq=energy/H
     real=np.array(vsr.dielectric[1])
     imag=np.array(vsr.dielectric[2])
   except:
     print('extracing data failed ')
     return

   head_line="#%(key1)+12s%(key2)+12s%(key3)+12s%(key4)+12s%(key5)+12s%(key6)+12s%(key7)+12s"%\
    {'key1':'Energy','key2':'xx','key3':'yy','key4':'zz','key5':'xy','key6':'yz','key7':'zx'}
   step_count+=1
   filename="AbsorbSpectrum.dat"
   proc_str="Writing Data To "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   Absorb=np.zeros((len(freq),6))
   for i in range(6): 
       Absorb[:,i]=1.4142*freq*(np.sqrt(-real[:,i]+np.sqrt(imag[:,i]*imag[:,i]+real[:,i]*real[:,i])))/(C0*100)
   data=np.vstack((energy,Absorb.T)).T
   write_col_data(filename,data,head_line,e_fmt=True)

   step_count+=1
   filename="RefractiveSpectrum.dat"
   proc_str="Writing Data To "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   Refrac=np.zeros((len(freq),6))
   for i in range(6): 
       Refrac[:,i]=(np.sqrt(real[:,i]+np.sqrt(imag[:,i]*imag[:,i]+real[:,i]*real[:,i])))/1.4142
   data=np.vstack((energy,Refrac.T)).T
   write_col_data(filename,data,head_line,e_fmt=True)

   step_count+=1
   filename="EnergyLossSpectrum.dat"
   proc_str="Writing Data To "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   EnergyLoss=np.zeros((len(freq),6))
   for i in range(6): 
       EnergyLoss[:,i]=imag[:,i]/(imag[:,i]*imag[:,i]+real[:,i]*real[:,i])
   data=np.vstack((energy,EnergyLoss.T)).T
   write_col_data(filename,data,head_line,e_fmt=True)

   step_count+=1
   filename="ExtictionSpectrum.dat"
   proc_str="Writing Data To "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   Extic=np.zeros((len(freq),6))
   for i in range(6): 
       Extic[:,i]=(np.sqrt(-real[:,i]+np.sqrt(imag[:,i]*imag[:,i]+real[:,i]*real[:,i])))/1.4142
   data=np.vstack((energy,Extic.T)).T
   write_col_data(filename,data,head_line,e_fmt=True)

   step_count+=1
   filename="ReflectivitySpectrum.dat"
   proc_str="Writing Data To "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   Reflect=np.zeros((len(freq),6))
   for i in range(6): 
       Reflect[:,i]=((Refrac[:,i]-1)*(Refrac[:,i]-1)+Extic[:,i]*Extic[:,i])/((Refrac[:,i]+1)*(Refrac[:,i]+1)+Extic[:,i]*Extic[:,i])
   data=np.vstack((energy,Reflect.T)).T
   write_col_data(filename,data,head_line,e_fmt=True)
Exemplo n.º 11
0
def select_one_band_structure():
   check_matplotlib()
   step_count=1
   filename='vasprun.xml'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   vsr=Vasprun(filename)

   step_count+=1
   filename='KPOINTS'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   bands = vsr.get_band_structure(filename, line_mode=True, efermi=vsr.efermi)
   nelect=vsr.parameters['NELECT']
   nbands=bands.nb_bands
   if vsr.is_spin:
      proc_str="This Is a Spin-polarized Calculation."
      procs(proc_str,0,sp='-->>')
      ISPIN=2
   else:
      if vsr.parameters['LNONCOLLINEAR']:
         proc_str="This Is a Non-Collinear Calculation."
         procs(proc_str,0,sp='-->>')
         ISPIN=3
      else:
         proc_str="This Is a Non-Spin Calculation."
         procs(proc_str,0,sp='-->>')
         ISPIN=1
   proc_str="Total band number is "+str(nbands)
   procs(proc_str,0,sp='-->>')
   proc_str="Total electron number is "+str(nelect)
   procs(proc_str,0,sp='-->>')

   print("which band would like to select ?")
   wait_sep()
   in_str=""
   while in_str=="":
         in_str=input().strip()
   selected_band=int(in_str)

   step_count+=1
   filename="BAND_"+str(selected_band)+'.dat'
   proc_str="Writting Selected Band Structure Data to "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   if ISPIN==1 or ISPIN==3:
      band_data=bands.bands[Spin.up][selected_band-1]-vsr.efermi
      data=np.vstack((bands.distance,band_data)).T
      head_line="#%(key1)+12s%(key2)+13s"%{'key1':'K-Distance','key2':'Energy(ev)'}
      write_col_data(filename,data,head_line,len(band_data))
   else:
      band_data_up=bands.bands[Spin.up][selected_band-1]-vsr.efermi
      band_data_down=bands.bands[Spin.down][selected_band-1]-vsr.efermi
      data=np.vstack((bands.distance,band_data_up,band_data_down)).T
      head_line="#%(key1)+12s%(key2)+13s%(key3)+15s"%{'key1':'K-Distance','key2':'UpEnergy(ev)','key3':'DownEnergy(ev)'}
      write_col_data(filename,data,head_line,len(band_data_up))
   return
Exemplo n.º 12
0
def projected_band_structure():
   step_count=1
   filename='vasprun.xml'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   vsr=Vasprun(filename)

   filename='PROCAR'
   check_file(filename)
   step_count+=1
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   procar=Procar(filename)
   nbands=procar.nbands
   nions=procar.nions
   norbitals=len(procar.orbitals)
   nkpoints=procar.nkpoints

   step_count+=1
   filename='KPOINTS'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   bands = vsr.get_band_structure(filename, line_mode=True, efermi=vsr.efermi)
   struct=vsr.final_structure
   (atom_index,in_str)=atom_selection(struct)
   
   if len(atom_index)==0:
      print("No atoms selected!")
      return
#   print(atom_index)

   if vsr.is_spin:
      proc_str="This Is a Spin-polarized Calculation."
      procs(proc_str,0,sp='-->>')
      ISPIN=2
      contrib=np.zeros((nkpoints,nbands,norbitals,2))
      for i in atom_index:
          contrib[:,:,:,0]=contrib[:,:,:,0]+procar.data[Spin.up][:,:,i,:]
          contrib[:,:,:,1]=contrib[:,:,:,1]+procar.data[Spin.down][:,:,i,:]

      for ispin in range(2):
          proj_band=contrib[:,:,:,ispin].reshape(nkpoints*nbands,norbitals)
          step_count+=1
          if ispin==0:
              filename="PBAND_Up.dat"
          else:
              filename="PBAND_Down.dat"
          proc_str="Writting Projected Band Structure Data to "+ filename +" File ..."
          procs(proc_str,step_count,sp='-->>')
          band_data=bands.bands[Spin.up]
          y_data=band_data.reshape(1,nbands*nkpoints)[0]-vsr.efermi #shift fermi level to 0
          x_data=np.array(bands.distance*nbands)
          data=np.vstack((x_data,y_data,proj_band.T)).T
          tmp1_str="#%(key1)+12s%(key2)+12s"
          tmp2_dic={'key1':'K-Distance','key2':'Energy(ev)'}
          for i in range(norbitals):
              tmp1_str+="%(key"+str(i+3)+")+12s"
              tmp2_dic["key"+str(i+3)]=procar.orbitals[i]

#          print(tmp1_str)
          atom_index_str=[str(x+1) for x in atom_index]
          head_line1="#String: "+in_str+'\n#Selected atom: ' +' '.join(atom_index_str)+'\n'
          head_line2=tmp1_str % tmp2_dic
          head_line=head_line1+head_line2
          write_col_data(filename,data,head_line,nkpoints)

   else:
      if vsr.parameters['LNONCOLLINEAR']:
         proc_str="This Is a Non-Collinear Calculation."
         procs(proc_str,0,sp='-->>')
         ISPIN=3
      else:
         proc_str="This Is a Non-Spin Calculation."
         procs(proc_str,0,sp='-->>')
         ISPIN=1

      contrib=np.zeros((nkpoints,nbands,norbitals))
      for i in atom_index:
          contrib[:,:,:]=contrib[:,:,:]+procar.data[Spin.up][:,:,i,:]
 
      proj_band=contrib.reshape(nkpoints*nbands,norbitals)        
      step_count+=1
      filename="PBAND.dat"
      proc_str="Writting Projected Band Structure Data to "+ filename +" File ..."
      procs(proc_str,step_count,sp='-->>')
      band_data=bands.bands[Spin.up]
      y_data=band_data.reshape(1,nbands*nkpoints)[0]-vsr.efermi #shift fermi level to 0
      x_data=np.array(bands.distance*nbands)
      data=np.vstack((x_data,y_data,proj_band.T)).T
      tmp1_str="#%(key1)+12s%(key2)+12s"
      tmp2_dic={'key1':'K-Distance','key2':'Energy(ev)'}
      for i in range(norbitals):
          tmp1_str+="%(key"+str(i+3)+")+12s"
          tmp2_dic["key"+str(i+3)]=procar.orbitals[i]

#      print(tmp1_str)
      atom_index_str=[str(x+1) for x in atom_index]
      head_line1="#String: "+in_str+'\n#Selected atom: ' +' '.join(atom_index_str)+'\n'
      head_line2=tmp1_str % tmp2_dic
      head_line=head_line1+head_line2
      write_col_data(filename,data,head_line,nkpoints)

   step_count+=1
   bsp=BSPlotter(bands)
   filename="HighSymmetricPoints.dat"
   proc_str="Writting Label infomation to "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'index','key2':'label','key3':'position'}
   line=head_line+'\n'
   for i,label in enumerate(bsp.get_ticks()['label']):
       new_line="%(key1)12d%(key2)+12s%(key3)12f\n"%{'key1':i,'key2':label,'key3':bsp.get_ticks()['distance'][i]}
       line+=new_line
   write_col_data(filename,line,'',str_data=True) 
Exemplo n.º 13
0
def total_dos():
   check_matplotlib()
   filename='vasprun.xml'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,1,sp='-->>')
   vsr=Vasprun(filename,parse_eigen=False)
   tdos=vsr.tdos
   idos=vsr.idos
   E=tdos.energies-tdos.efermi
   if vsr.is_spin:
      proc_str="This Is a Spin-polarized Calculation."
      procs(proc_str,0,sp='-->>')
      proc_str="Writting TDOS.dat File ..."
      TDOSUP=tdos.densities[Spin.up]
      TDOSDOWN=tdos.densities[Spin.down]
      ETDOS=np.vstack((E,TDOSUP,TDOSDOWN))
      head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'Energy(eV)','key2':'SpinUp','key3':'SpinDown'}
      write_col_data('TDOS.dat',ETDOS.T,head_line)

      proc_str="Writting IDOS.dat File ..."
      procs(proc_str,3,sp='-->>')
      IDOSUP=idos.densities[Spin.up]
      IDOSDOWN=idos.densities[Spin.down]
      EIDOS=np.vstack((E,IDOSUP,IDOSDOWN))
      head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'Energy(eV)','key2':'IntSpinUp','key3':'IntSpinDown'}
      write_col_data('IDOS.dat',EIDOS.T,head_line)

      plt1=DosPlotter()
      plt2=DosPlotter()
      plt1.add_dos('Total DOS',tdos)
      plt2.add_dos('Total DOS',idos)
      try:
       # plt1.show()
        plt1.save_plot('TotalDOS.png', img_format="png")
       # plt2.show()
        plt2.save_plot('IntegratedDOS.png', img_format="png")
      except:
        print("pls use gnuplot to plot TDOS.dat and IDOS.dat")
   else:
      if vsr.parameters['LNONCOLLINEAR']:
         proc_str="This Is a Non-Collinear Calculation."
      else:
          proc_str="This Is a Non-Spin Calculation."
      procs(proc_str,0,sp='-->>')
      proc_str="Writting TDOS.dat File ..."
      procs(proc_str,2,sp='-->>')
      
      TDOS=tdos.densities[Spin.up]
      ETDOS=np.vstack((E,TDOS))
      head_line="#%(key1)+12s%(key2)+12s"%{'key1':'Energy(eV)','key2':'TotalDOS'}
      write_col_data('TDOS.dat',ETDOS.T,head_line)

      proc_str="Writting IDOS.dat File ..."
      procs(proc_str,3,sp='-->>')
      IDOS=idos.densities[Spin.up]
      EIDOS=np.vstack((E,IDOS))
      head_line="#%(key1)+12s%(key2)+13s"%{'key1':'Energy(eV)','key2':'IntegratedDOS'}
      write_col_data('IDOS.dat',EIDOS.T,head_line)

      plt1=DosPlotter()
      plt2=DosPlotter()
      plt1.add_dos('Total DOS',tdos)
      plt2.add_dos('Integrated DOS',idos)
      filename4="TotalDOS.png IntegratedDOS.png"
      proc_str="Saving Plot to "+ filename4 +" File ..."
      procs(proc_str,4,sp='-->>')

      try:
       # plt1.show()
        plt1.save_plot('TotalDOS.png', img_format="png")
       # plt2.show()
        plt2.save_plot('IntegratedDOS.png', img_format="png")
      except:
        print("pls use gnuplot to plot TDOS.dat and IDOS.dat")
Exemplo n.º 14
0
def band_structure():
    check_matplotlib()
    step_count=1

    filename='vasprun.xml'
    check_file(filename)
    proc_str="Reading Data From "+ filename +" File ..."
    procs(proc_str,step_count,sp='-->>')
    vsr=Vasprun(filename)

    step_count+=1
    filename='KPOINTS'
    check_file(filename)
    proc_str="Reading Data From "+ filename +" File ..."
    procs(proc_str,step_count,sp='-->>')
    bands = vsr.get_band_structure(filename, line_mode=True, efermi=vsr.efermi)

    step_count+=1
    filename='OUTCAR'
    check_file(filename)
    proc_str="Reading Data From "+ filename +" File ..."
    procs(proc_str,step_count,sp='-->>')
    outcar=Outcar('OUTCAR')
    mag=outcar.as_dict()['total_magnetization']

    if vsr.is_spin:
       proc_str="This Is a Spin-polarized Calculation."
       procs(proc_str,0,sp='-->>')
       tdos=vsr.tdos
       SpinUp_gap=tdos.get_gap(spin=Spin.up) 
       cbm_vbm_up=tdos.get_cbm_vbm(spin=Spin.up)
       SpinDown_gap=tdos.get_gap(spin=Spin.down) 
       cbm_vbm_down=tdos.get_cbm_vbm(spin=Spin.up)

       if SpinUp_gap > min_gap and SpinDown_gap > min_gap:
          is_metal=False
          is_semimetal=False
       elif SpinUp_gap > min_gap and SpinDown_gap < min_gap:
          is_metal=False
          is_semimetal=True
       elif SpinUp_gap < min_gap and SpinDown_gap > min_gap:
          is_metal=False
          is_semimetal=True
       elif SpinUp_gap < min_gap and SpinDown_gap < min_gap:
          is_metal=True
          is_semimetal=False
          
       if is_metal:   
          proc_str="This Material Is a Metal."
          procs(proc_str,0,sp='-->>')
       if not is_metal and is_semimetal:
          proc_str="This Material Is a Semimetal."
          procs(proc_str,0,sp='-->>')
       else:
          proc_str="This Material Is a Semiconductor."
          procs(proc_str,0,sp='-->>')
          proc_str="Total magnetization is "+str(mag)
          procs(proc_str,0,sp='-->>')
          if mag > min_mag:
             proc_str="SpinUp  : vbm=%f eV cbm=%f eV gap=%f eV"%(cbm_vbm_up[1],cbm_vbm_up[0],SpinUp_gap)
             procs(proc_str,0,sp='-->>')
             proc_str="SpinDown: vbm=%f eV cbm=%f eV gap=%f eV"%(cbm_vbm_down[1],cbm_vbm_down[0],SpinUp_gap)
             procs(proc_str,0,sp='-->>')
          else:
             proc_str="SpinUp  : vbm=%f eV cbm=%f eV gap=%f eV"%(cbm_vbm_up[1],cbm_vbm_up[0],SpinUp_gap)
             procs(proc_str,0,sp='-->>')
       step_count+=1
       filename="BAND.dat"
       proc_str="Writting Band Structure Data to "+ filename +" File ..."
       procs(proc_str,step_count,sp='-->>')
       band_data_up=bands.bands[Spin.up]
       band_data_down=bands.bands[Spin.down]
       y_data_up=band_data_up.reshape(1,band_data_up.shape[0]*band_data_up.shape[1])[0]-vsr.efermi #shift fermi level to 0
       y_data_down=band_data_down.reshape(1,band_data_down.shape[0]*band_data_down.shape[1])[0]-vsr.efermi #shift fermi level to 0
       x_data=np.array(bands.distance*band_data_up.shape[0])
       data=np.vstack((x_data,y_data_up,y_data_down)).T
       head_line="#%(key1)+12s%(key2)+13s%(key3)+15s"%{'key1':'K-Distance','key2':'UpEnergy(ev)','key3':'DownEnergy(ev)'}
       write_col_data(filename,data,head_line,band_data_up.shape[1])
 
    else:
       if vsr.parameters['LNONCOLLINEAR']:
          proc_str="This Is a Non-Collinear Calculation."
       else:
           proc_str="This Is a Non-Spin Calculation."
       procs(proc_str,0,sp='-->>')
       cbm=bands.get_cbm()['energy']
       vbm=bands.get_vbm()['energy']
       gap=bands.get_band_gap()['energy']
       if not bands.is_metal():
          proc_str="This Material Is a Semiconductor."
          procs(proc_str,0,sp='-->>')
          proc_str="vbm=%f eV cbm=%f eV gap=%f eV"%(vbm,cbm,gap)
          procs(proc_str,0,sp='-->>')
       else:
          proc_str="This Material Is a Metal."
          procs(proc_str,0,sp='-->>')
       
       step_count+=1
       filename3="BAND.dat"
       proc_str="Writting Band Structure Data to "+ filename3 +" File ..."
       procs(proc_str,step_count,sp='-->>')
       band_data=bands.bands[Spin.up]
       y_data=band_data.reshape(1,band_data.shape[0]*band_data.shape[1])[0]-vsr.efermi #shift fermi level to 0
       x_data=np.array(bands.distance*band_data.shape[0])
       data=np.vstack((x_data,y_data)).T
       head_line="#%(key1)+12s%(key2)+13s"%{'key1':'K-Distance','key2':'Energy(ev)'}
       write_col_data(filename3,data,head_line,band_data.shape[1])
       step_count+=1
       bsp=BSPlotter(bands)
       filename4="HighSymmetricPoints.dat"
       proc_str="Writting Label infomation to "+ filename4 +" File ..."
       procs(proc_str,step_count,sp='-->>')
       head_line="#%(key1)+12s%(key2)+12s%(key3)+12s"%{'key1':'index','key2':'label','key3':'position'}
       line=head_line+'\n'
       for i,label in enumerate(bsp.get_ticks()['label']):
           new_line="%(key1)12d%(key2)+12s%(key3)12f\n"%{'key1':i,'key2':label,'key3':bsp.get_ticks()['distance'][i]}
           line+=new_line
       line+='\n'
       write_col_data(filename4,line,'',str_data=True) 
    try:
       step_count+=1
       filename5="BAND.png"
       proc_str="Saving Plot to "+ filename5 +" File ..."
       procs(proc_str,step_count,sp='-->>')
       bsp.save_plot(filename5, img_format="png")
    except:
       print("Figure output fails !!!")   
Exemplo n.º 15
0
def projected_dos():
   step_count=1
   filename='vasprun.xml'
   check_file(filename)
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   vsr=Vasprun(filename)
   nedos=vsr.parameters['NEDOS']
   struct=vsr.final_structure
   pdos=vsr.pdos

   filename='PROCAR'
   check_file(filename)
   step_count+=1
   proc_str="Reading Data From "+ filename +" File ..."
   procs(proc_str,step_count,sp='-->>')
   procar=Procar(filename)
   nbands=procar.nbands
   nions=procar.nions
   norbitals=len(procar.orbitals)
   nkpoints=procar.nkpoints

   (atom_index,in_str)=atom_selection(struct)

   if len(atom_index)==0:
      print("No atoms selected!")
      return
#   print(atom_index)

   if vsr.is_spin:
      proc_str="This Is a Spin-polarized Calculation."
      procs(proc_str,0,sp='-->>')

      contrib=np.zeros((nedos,norbitals+1,2))
      energies=vsr.tdos.energies-vsr.efermi
      for ispin in [0,1]:
          if ispin==0:
              spin=Spin.up
              s_name='Up'
          else:
              spin=Spin.down
              s_name='Down'

          contrib[:,0,ispin]=energies  
          for i in atom_index:
                for j in range(norbitals):
                     contrib[:,j+1,ispin]=contrib[:,j+1,ispin]+pdos[i][Orbital(j)][spin]

          step_count+=1
          filename="PDOS_"+s_name+".dat"
          proc_str="Writting Projected DOS Data to "+ filename +" File ..."
          procs(proc_str,step_count,sp='-->>')
          tmp1_str="#%%(key1)+12s"
          tmp2_dic={'key1':'Energy(ev)'}
          for i in range(norbitals):
              tmp1_str+="%(key"+str(i+2)+")+12s"
              tmp2_dic["key"+str(i+2)]=procar.orbitals[i]

#          print(tmp1_str)
          atom_index_str=[str(x+1) for x in atom_index]
          head_line1="#String: "+in_str+'\n#Selected atom: ' +' '.join(atom_index_str)+'\n'
          head_line2=tmp1_str % tmp2_dic
          head_line=head_line1+head_line2
          write_col_data(filename,contrib[:,:,ispin],head_line)

   else:
      if vsr.parameters['LNONCOLLINEAR']:
         proc_str="This Is a Non-Collinear Calculation."
         procs(proc_str,0,sp='-->>')
      else:
         proc_str="This Is a Non-Spin Calculation."
         procs(proc_str,0,sp='-->>')

      contrib=np.zeros((nedos,norbitals+1))
      energies=vsr.tdos.energies-vsr.efermi
      contrib[:,0]=energies
      for i in atom_index:
            for j in range(norbitals):
                 contrib[:,j+1]=contrib[:,j+1]+pdos[i][Orbital(j)][Spin.up]

      step_count+=1
      filename="PDOS.dat"
      proc_str="Writting Projected DOS Data to "+ filename +" File ..."
      procs(proc_str,step_count,sp='-->>')
      tmp1_str="#%(key1)+12s%(key2)+12s"
      tmp2_dic={'key1':'K-Distance','key2':'Energy(ev)'}
      for i in range(norbitals):
          tmp1_str+="%(key"+str(i+3)+")+12s"
          tmp2_dic["key"+str(i+3)]=procar.orbitals[i]

#      print(tmp1_str)
      atom_index_str=[str(x+1) for x in atom_index]
      head_line1="#String: "+in_str+'\n#Selected atom: ' +' '.join(atom_index_str)+'\n'
      head_line2=tmp1_str % tmp2_dic
      head_line=head_line1+head_line2
      write_col_data(filename,contrib,head_line)
Exemplo n.º 16
0
def get_mp_structure():
    mpr = check_apikey()
    print('your choice ?')
    print('{} >>> {}'.format('1', 'get a structure by mp-ID'))
    print('{} >>> {}'.format('2', 'get a structure by fomular'))
    print('{} >>> {}'.format('3', 'get a structure by elements'))
    wait_sep()
    in_str = wait()
    choice = int(in_str)
    if choice == 1:
        print("input the mp-ID")
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        mp_id = in_str
        struct = mpr.get_structure_by_material_id(mp_id)
        if isinstance(struct, Structure):
            pass
        else:
            print("Unknown mp-ID, check the mp-ID")
            return None
        web = "materials.org"
        step_count = 1
        proc_str = "Reading Data From " + web + " ..."
        procs(proc_str, step_count, sp='-->>')
        filename = mp_id + '.vasp'
        step_count += 1
        proc_str = "Writing Data to " + filename + " File..."
        procs(proc_str, step_count, sp='-->>')
        struct.to(filename=filename, fmt='POSCAR')
        return True
    elif choice == 2:
        print("input the formula of structure")
        wait_sep()
        in_str = wait()
        formula = in_str
        mpid = mpr.query(criteria={'pretty_formula': formula},
                         properties=['material_id'])
        web = "materials.org"
        proc_str = "Reading Data From " + web + " ..."
        step_count = 1
        procs(proc_str, step_count, sp='-->>')
        for i in range(len(mpid)):
            sid = mpid[i]['material_id']
            struct = mpr.get_structure_by_material_id(sid)
            filename = sid + '.cif'
            step_count += 1
            proc_str = "Writing Data to " + filename + " File..."
            procs(proc_str, step_count, sp='-->>')
            struct.to(fmt='cif', filename=filename)
        return True
    elif choice == 3:
        print("input the elements list")
        wait_sep()
        in_str = wait()
        elements = in_str.split()
        data = mpr.get_entries_in_chemsys(elements=elements)
        web = "materials.org"
        proc_str = "Reading Data From " + web + " ..."
        step_count = 1
        procs(proc_str, step_count, sp='-->>')
        for i in range(len(data)):
            if len(data[i].composition) == len(elements):
                sid = data[i].entry_id
                struct = mpr.get_structure_by_material_id(sid)
                filename = sid + '.cif'
                step_count += 1
                proc_str = "Writing Data to " + filename + " File..."
                procs(proc_str, step_count, sp='-->>')
                struct.to(fmt='cif', filename=filename)
        return True
    else:
        print('unknow choice')
        return None