예제 #1
0
def test_make_perfect_band_edge_state_from_vasp(vasp_files):
    procar = Procar(vasp_files / "MgO_2x2x2_perfect" / "PROCAR")
    vasprun = Vasprun(vasp_files / "MgO_2x2x2_perfect" / "vasprun.xml")
    outcar = Outcar(vasp_files / "MgO_2x2x2_perfect" / "OUTCAR")
    actual = make_perfect_band_edge_state_from_vasp(procar, vasprun, outcar)

    vbm_info = EdgeInfo(band_idx=127,
                        kpt_coord=(0.25, 0.25, 0.25),
                        orbital_info=OrbitalInfo(energy=2.7746,
                                                 orbitals={
                                                     'Mg':
                                                     [0.0, 0.0, 0.0, 0.0],
                                                     'O':
                                                     [0.0, 0.704, 0.0, 0.0]
                                                 },
                                                 occupation=1.0))
    cbm_info = EdgeInfo(band_idx=128,
                        kpt_coord=(0.25, 0.25, 0.25),
                        orbital_info=OrbitalInfo(energy=8.2034,
                                                 orbitals={
                                                     'Mg':
                                                     [0.192, 0.0, 0.0, 0.0],
                                                     'O':
                                                     [0.224, 0.096, 0.0, 0.0]
                                                 },
                                                 occupation=0.0))
    expected = PerfectBandEdgeState(vbm_info=vbm_info, cbm_info=cbm_info)
    assert actual == expected
예제 #2
0
def make_perfect_band_edge_state(args):
    procar = Procar(args.dir / defaults.procar)
    vasprun = Vasprun(args.dir / defaults.vasprun)
    outcar = Outcar(args.dir / defaults.outcar)
    perfect_band_edge_state = \
        make_perfect_band_edge_state_from_vasp(procar, vasprun, outcar)
    perfect_band_edge_state.to_json_file(args.dir /
                                         "perfect_band_edge_state.json")
예제 #3
0
    def setUp(self) -> None:
        procar_perfect = Procar(self.DEFECTS_MGO_DIR / "perfect" / "PROCAR")
        structure_perfect = self.get_structure_by_name("MgO64atoms")

        procar_va_o_2 = Procar(self.DEFECTS_MGO_DIR / "Va_O1_2" / "PROCAR")
        structure_va_o_2 = self.get_structure_by_name("MgO64atoms-Va_O1_2")

        # MgO vbm
        self.orbital_1 = calc_orbital_character(procar=procar_perfect,
                                                structure=structure_perfect,
                                                spin=Spin.up,
                                                band_index=127,
                                                kpoint_index=0)

        # MgO vbm
        self.orbital_2 = calc_orbital_character(procar=procar_va_o_2,
                                                structure=structure_va_o_2,
                                                spin=Spin.up,
                                                band_index=123,
                                                kpoint_index=0)
예제 #4
0
    def test_calc_participation_ratio(self):
        procar = Procar(self.DEFECTS_MGO_DIR / "Va_O1_2" / "PROCAR")

        actual = calc_participation_ratio(procar=procar,
                                          spin=Spin.up,
                                          band_index=0,
                                          atom_indices=[32, 33])
        #    33  0.051  0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.051
        #    34  0.051  0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.051
        # tot    0.732  0.001  0.001  0.001  0.000  0.000  0.000  0.000  0.000  0.736
        expected = 0.051 * 2 / 0.736
        self.assertAlmostEqual(expected, actual, 2)
예제 #5
0
def make_edge_characters(args):
    for d in args.dirs:
        logger.info(f"Parsing data in {d} ...")
        vasprun = Vasprun(d / defaults.vasprun)
        procar = Procar(d / defaults.procar)
        outcar = Outcar(d / defaults.outcar)
        calc_results = loadfn(d / "calc_results.json")
        structure_analyzer = DefectStructureAnalyzer(
            calc_results.structure, args.perfect_calc_results.structure)
        edge_characters = MakeEdgeCharacters(
            procar, vasprun, outcar,
            structure_analyzer.neighboring_atom_indices).edge_characters
        edge_characters.to_json_file(d / "edge_characters.json")
예제 #6
0
def test_band_edge_properties_orbital_contributions(test_data_files):
    procar = Procar(test_data_files / "MgO_band_PROCAR")
    structure = Structure(
        Lattice.cubic(1), species=["Mg", "O"], coords=[[0]*3, [0.5]*3])
    vbm_info = BandEdge.from_dict({'energy': 3.0663, 'spin': 1, 'band_index': 3,
                                   'kpoint_index': 0,
                                   'kpoint_coords': [0.0, 0.0, 0.0]})
    cbm_info = BandEdge.from_dict({'energy': 7.726, 'spin': 1, 'band_index': 4,
                                   'kpoint_index': 0,
                                   'kpoint_coords': [0.0, 0.0, 0.0]})
    vbm, cbm = edge_orbital_contributions(procar, structure, vbm_info, cbm_info)
    assert vbm["O"]["p"] == 0.753
    assert cbm["Mg"]["s"] == 0.238
예제 #7
0
 def _inner(_dir: Path):
     try:
         defect_entry = loadfn(_dir / "defect_entry.json")
         title = defect_entry.name
     except FileNotFoundError:
         title = "No name"
     procar = Procar(_dir / defaults.procar)
     vasprun = Vasprun(_dir / defaults.vasprun)
     str_info = loadfn(_dir / "defect_structure_info.json")
     band_edge_orb_chars = make_band_edge_orbital_infos(
         procar, vasprun, supercell_vbm, supercell_cbm, str_info)
     band_edge_orb_chars.to_json_file(_dir / "band_edge_orbital_infos.json")
     plotter = EigenvalueMplPlotter(title=title,
                                    band_edge_orb_infos=band_edge_orb_chars,
                                    supercell_vbm=supercell_vbm,
                                    supercell_cbm=supercell_cbm)
     plotter.construct_plot()
     plotter.plt.savefig(fname=_dir / "eigenvalues.pdf")
     plotter.plt.clf()
예제 #8
0
    def test_calc_orbital_character(self):
        procar = Procar(self.DEFECTS_MGO_DIR / "Va_O1_2" / "PROCAR")
        structure = self.get_structure_by_name("MgO64atoms-Va_O1_2")
        actual = calc_orbital_character(procar=procar,
                                        structure=structure,
                                        spin=Spin.up,
                                        band_index=0,
                                        kpoint_index=0)

        mg_sum = (0.002 + 0.001 + 0.001 + 0.001 + 0.002 + 0.001 + 0.001 +
                  0.001 + 0.001 + 0.001 + 0.001 + 0.001 + 0.001 + 0.001 +
                  0.001 + 0.001 + 0.002 + 0.002 + 0.001 + 0.001 + 0.001 +
                  0.001 + 0.001 + 0.001 + 0.002 + 0.001 + 0.002 + 0.001 +
                  0.001 + 0.001 + 0.001 + 0.001)
        o_sum = (0.051 + 0.051 + 0.017 + 0.051 + 0.017 + 0.017 + 0.008 +
                 0.028 + 0.024 + 0.024 + 0.028 + 0.014 + 0.014 + 0.014 +
                 0.014 + 0.024 + 0.028 + 0.014 + 0.014 + 0.028 + 0.024 +
                 0.014 + 0.014 + 0.024 + 0.014 + 0.028 + 0.014 + 0.028 +
                 0.014 + 0.024 + 0.014)

        expected = {
            'Mg': {
                's': mg_sum,
                'p': 0.0,
                'd': 0.0,
                'f': 0.0
            },
            'O': {
                's': o_sum,
                'p': 0.0,
                'd': 0.0,
                'f': 0.0
            }
        }
        self.assertAlmostEqual(expected["Mg"]["s"], actual["Mg"]["s"], 4)
        self.assertAlmostEqual(expected["O"]["s"], actual["O"]["s"], 4)
예제 #9
0
파일: vaspout.py 프로젝트: obaica/maptool-1
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) 
예제 #10
0
파일: vaspout.py 프로젝트: obaica/maptool-1
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)