code: def _get_bandgap_doscar(filename):
          
          with open(filename) as fp:
              for i in range(6):
                  l = fp.readline()
              efermi = float(l.split()[3])
              step1 = fp.readline().split()[0]
              step2 = fp.readline().split()[0]
              step_size = float(step2)-float(step1)
              not_found = True
              while not_found:
                  l = fp.readline().split()
                  e = float(l.pop(0))
                  dens = 0.0
                  for i in range(int(len(l)/2)):
                      dens += float(l[i])
                  if e < efermi and dens > 1e-3:
                      bot = e
                  elif e > efermi and dens > 1e-3:
                      top = e
                      not_found = False
              if top - bot < step_size*2:
                  bandgap = 0.0
              else:
                  bandgap = float(top - bot)
  
          return bandgap
docs: Get the bandgap from the DOSCAR file