code: def get_cbm_vbm(self, tol=0.001, abs_tol=False, spin=None):
          
          # determine tolerance
          tdos = self.get_densities(spin)
          if not abs_tol:
              tol = tol * tdos.sum() / tdos.shape[0]
  
          # find index of fermi energy
          i_fermi = 0
          while self.energies[i_fermi] <= self.efermi:
              i_fermi += 1
  
          # work backwards until tolerance is reached
          i_gap_start = i_fermi
          while i_gap_start - 1 >= 0 and tdos[i_gap_start - 1] <= tol:
              i_gap_start -= 1
  
          # work forwards until tolerance is reached
          i_gap_end = i_gap_start
          while i_gap_end < tdos.shape[0] and tdos[i_gap_end] <= tol:
              i_gap_end += 1
          i_gap_end -= 1
          return self.energies[i_gap_end], self.energies[i_gap_start]
docs: Expects a DOS object and finds the cbm and vbm.
  
          Args:
              tol: tolerance in occupations for determining the gap
              abs_tol: An absolute tolerance (True) and a relative one (False)
              spin: Possible values are None - finds the gap in the summed
                  densities, Up - finds the gap in the up spin channel,
                  Down - finds the gap in the down spin channel.
  
          Returns:
              (cbm, vbm): float in eV corresponding to the gap