Exemplo n.º 1
0
 def __init__(self, qmout, **kwargs):
   PlanewaveOutput.__init__(self, qmout, **kwargs)
   self.info = ''
   if qmout:
     root = os.path.split(os.path.abspath(qmout))[0]
     mol_path = os.path.join(root, 'GEOMETRY.xyz')
     try:
       self.molecule = qtk.Molecule(mol_path)
     except:
       pass
     self.getEt(qmout)
Exemplo n.º 2
0
 def __init__(self, qmout, **kwargs):
   PlanewaveOutput.__init__(self, qmout, **kwargs)
   self.info = ''
   if qmout:
     root = os.path.split(os.path.abspath(qmout))[0]
     mol_path = os.path.join(root, 'GEOMETRY.xyz')
     try:
       self.molecule = qtk.Molecule(mol_path)
     except:
       pass
     self.getEt(qmout)
Exemplo n.º 3
0
    def __init__(self, qmout, **kwargs):
        PlanewaveOutput.__init__(self, qmout, **kwargs)
        out_file = open(qmout)
        data = out_file.readlines()
        out_file.close()

        EStrList = filter(lambda x: 'Etotal' in x, data)
        EList = filter(lambda x: 'ETOT' in x, data)
        self.scf_step = len(EList)
        if self.scf_step > 0:
            Et_list = [float(filter(None, s.split(' '))[2]) for s in EList]
            self.Et = Et_list[-1]
        elif len(EStrList) > 0:
            EStr = EStrList[-1]
            self.Et = float(EStr.split(' ')[-1])

        if len(EStrList) > 0:
            EStr = EStrList[-1]
            detailInd = data.index(EStr)
            self.detail = data[detailInd - 7:detailInd]

        GStr = filter(lambda x: 'G(1)' in x, data)[-1]
        ind_g = len(data) - data[::-1].index(GStr) - 1
        G_lattice = []
        for i in range(3):
            G_lattice.append(
                np.fromstring(data[ind_g + i].split('=')[-1], sep=' '))
        self.G_lattice = np.array(G_lattice)

        xangst = filter(lambda x: 'xangst' in x, data)[-1]
        angst_n = len(data) - data[::-1].index(xangst) - 1
        xcart = filter(lambda x: 'xcart' in x, data)[-1]
        cart_n = len(data) - data[::-1].index(xcart) - 1
        Rstr = copy.deepcopy(data[angst_n:cart_n])
        Rstr[0] = Rstr[0].replace('xangst', '')
        R = [[float(r) for r in filter(None, s.split(' '))] for s in Rstr]
        N = len(R)
        ZstrOriginal = filter(lambda x: ' typat' in x, data)[-1]
        Zstr = ZstrOriginal.replace('typat', '')
        Zind = [int(z) for z in filter(None, Zstr.split(' '))]
        ZindItr = data.index(ZstrOriginal)
        while len(Zind) != N:
            ZindItr += 1
            ZindNewStr = filter(None, data[ZindItr].split(' '))
            ZindNew = [int(z) for z in ZindNewStr]
            Zind.extend(ZindNew)
        NZnuc = filter(lambda x: 'ntypat' in x, data)[-1]
        NZnuc = int(filter(None, NZnuc.split(' '))[-1])
        Znuc = filter(lambda x: 'znucl ' in x, data)[-1]
        line_znuc = len(data) - data[::-1].index(Znuc)
        Znuc = filter(None, Znuc.replace('znucl', '').split(' '))
        Znuc = [float(z) for z in Znuc]
        while len(Znuc) < NZnuc:
            Znuc_new = filter(None, data[line_znuc].split(' '))
            Znuc_new = [float(z) for z in Znuc_new]
            Znuc.extend(Znuc_new)
            line_znuc = line_znuc + 1

        build = []
        for i in range(N):
            Z = [Znuc[Zind[i] - 1]]
            Z.extend(R[i])
            build.append(Z)
        self.molecule = qtk.Molecule()
        self.molecule.build(build)

        if self.scf_step > 0:
            fStr = filter(lambda x: 'tesian forces (hartree/b' in x, data)[-1]
            fInd = data.index(fStr)
            fData = data[fInd + 1:fInd + 1 + N]
            force = []
            for f in fData:
                fStr = filter(None, f.split(' '))[1:]
                force.append([float(fs) for fs in fStr])
            self.force = np.array(force)

        self.occupation = []
        try:
            r1p = re.compile(r'^[ a-z]{17} +[ 0-9.E+-]+$')
            r2p = re.compile(r'^ +[a-z]+ +.*$')
            report = filter(r2p.match, filter(r1p.match, data))
            occ_ptn_lst = filter(lambda x: ' occ ' in x, report)
            if len(occ_ptn_lst) > 0:
                occ_pattern = occ_ptn_lst[-1]
                occ_pattern_ind = len(report) - report[::-1].index(occ_pattern)
                occ_pattern_end = report[occ_pattern_ind]
                occ_ind_start = len(data) - data[::-1].index(occ_pattern) - 1
                occ_ind_end = len(data) - data[::-1].index(occ_pattern_end) - 1
                for i in range(occ_ind_start, occ_ind_end):
                    for occ in filter(None, data[i].split(' ')):
                        try:
                            self.occupation.append(float(occ))
                        except Exception as err:
                            pass
        except Exception as err:
            qtk.warning("error when extracting occupation number with" +\
              " error message: %s" % str(err))

        cell_pattern = re.compile(r'^ R.*=.* G.*=.*$')
        cell_list = filter(cell_pattern.match, data)
        cell = []
        for cstr in cell_list:
            cell.append([float(c) for c in filter(None, cstr.split(' '))[1:4]])
        self.lattice = np.array(cell) / 1.889726124993
        self.celldm = qtk.lattice2celldm(self.lattice)
        self.molecule.R_scale = qtk.xyz2fractional(self.molecule.R,
                                                   self.celldm)

        eigStr = os.path.join(os.path.split(qmout)[0], '*_EIG')
        eigFileList = sorted(glob.glob(eigStr))
        if len(eigFileList) != 0:
            if 'eig_index' in kwargs:
                eig_i = kwargs['eig_index']
            else:
                eig_i = -1
            if len(eigFileList) > 1:
                qtk.warning(
                  "more than one o_EIG files found " + \
                  "loading last file with name: %s" % eigFileList[eig_i]
                )
            eigFile = open(eigFileList[eig_i])
            eigData = eigFile.readlines()
            eigFile.close()
            unitStr = filter(lambda x: 'Eigenvalues' in x, eigData)[0]
            unitStr = unitStr.replace('(', '').replace(')', '')
            unit = filter(None, unitStr.split(' '))[1]
            spinList = filter(lambda x: 'SPIN' in x, eigData)
            if len(spinList) != 0:
                spinFactor = 2
                maxInd = eigData.index(spinList[-1])
            else:
                spinFactor = 1
                maxInd = len(eigData)
            ind = []
            for kStr in filter(lambda x: 'kpt#' in x, eigData):
                ind.append(eigData.index(kStr))
            band = []
            kpoints = []
            if spinFactor == 1:
                for i in range(len(ind)):
                    wcoord = eigData[ind[i]].split('wtk=')[-1].split(', kpt=')
                    weight = float(wcoord[0])
                    cStr = filter(None, wcoord[1].split('(')[0].split(' '))
                    coord = [float(c) for c in cStr]
                    coord.append(weight)
                    kpoints.append(coord)
                    s = ind[i] + 1
                    if i < len(ind) - 1:
                        e = ind[i + 1]
                    else:
                        e = len(eigData)
                    eig_i = filter(None, ''.join(eigData[s:e]).split(' '))
                    band.append([
                        qtk.convE(float(ew), '%s-eV' % unit)[0] for ew in eig_i
                    ])

                self.band = np.array(band)
                self.kpoints = np.array(kpoints)
                self.mo_eigenvalues = np.array(band[0]).copy()
                if len(self.occupation) > 0:
                    diff = np.diff(self.occupation)
                    ind = np.array(range(len(diff)))
                    pos = diff[np.where(abs(diff) > 0.5)]
                    mask = np.in1d(diff, pos)
                    if len(ind[mask]) > 0:
                        N_state = ind[mask][0]

                else:
                    qtk.warning("occupation number not available... " + \
                      "try to use molecule object with closed shell assumption"
                    )
                    N_state = self.molecule.getValenceElectrons() / 2 - 1

                vb = max(self.band[:, N_state])
                cb = min(self.band[:, N_state + 1])
                vb_pos = np.argmax(self.band[:, N_state])
                cb_pos = np.argmin(self.band[:, N_state + 1])
                self.Eg = cb - vb
                if vb_pos == cb_pos:
                    self.Eg_direct = True
                else:
                    self.Eg_direct = False
                self.fermi_index = N_state

            else:
                qtk.warning("spin polarized band data " +\
                            "extraction is not yet implemented")
        else:
            qtk.warning('no k-point information (o_EIG file) found')
Exemplo n.º 4
0
  def __init__(self, qmout, **kwargs):
    PlanewaveOutput.__init__(self, qmout, **kwargs)
    out_file = open(qmout)
    data = out_file.readlines()
    out_file.close()
    Et_pattern = re.compile("^.*total energy *=.*$")
    f_pattern = re.compile("^.*atom.*type.*force.*=.*$")
    Et_list = filter(Et_pattern.match, data)
    f_list = filter(f_pattern.match, data)
    if len(Et_list) > 0:
      Et_str = filter(Et_pattern.match, data)[-1]
      Et = float(Et_str.split()[-2])
      self.Et, self.unit = qtk.convE(Et, 'Ry-Eh')
      out_folder = os.path.split(os.path.abspath(qmout))[0]
      save = glob.glob(os.path.join(out_folder, '*.save'))

      # extract force information
      if len(f_list) > 0:
        fstr = [filter(None, fstr.split('=')[-1].split(' ')) 
                for fstr in f_list]
        # atomic unit force, HF/au, converted from Ry/au
        self.force = 0.5 * np.array(
          [[float(comp) for comp in atm] for atm in fstr]
        )

      # extract band structure from xml files
      if save:
        save = save[0]
        try:
          data_xml = os.path.join(save, 'data-file.xml')
          xml_file = open(data_xml)
          tree = ET.parse(xml_file)
          xml_file.close()
          self.xml = tree.getroot()
          kpoints = []
          band = []

          # extract celldm
          celldm = []
          cellVec = []
          for i in range(1, 4):
            cellvStr = filter(None, 
              self.xml[2][4][i].text.replace('\n', '').split(' ')
            )
            cellVec.append([float(v) for v in cellvStr])
          self.celldm = qtk.cellVec2celldm(cellVec)
    
          # extract structure
          R = []
          N = int(self.xml[3][0].text.replace('\n', ''))
          Nsp = int(self.xml[3][1].text.replace('\n', ''))
          for i in range(N):
            RiStr = self.xml[3][5+Nsp+i].get('tau')
            Ri = [float(r) * 0.529177249 for r in RiStr.split(' ')]
            ni = self.xml[3][5+Nsp+i].get('SPECIES')
            Z = [qtk.n2Z(ni)]
            Z.extend(Ri)
            R.append(Z)
          self.molecule = qtk.Molecule()
          self.molecule.build(R)

          # access data for each kpoint
          for k in self.xml[-2]:
            k_str = k[0].text
            coord = [float(c) for c in k_str.split()]
            weight = float(k[1].text.split()[0])
            coord.append(weight)
            kpoints.append(coord)
            ev_file = os.path.join(save, k[2].attrib['iotk_link'])
            k_xml_file = open(ev_file)
            k_xml = ET.parse(k_xml_file)
            k_xml_file.close()
            ev_k = k_xml.getroot()
            ev_str = ev_k[2].text.split()
            ev = [qtk.convE(float(entry), 'Eh-eV')[0]\
                  for entry in ev_str]
            band.append(ev)
            occ_str = ev_k[3].text.split()
            occ = [float(entry) for entry in occ_str]
          self.kpoints = np.array(kpoints)
          self.mo_eigenvalues = copy.deepcopy(band[0])
          self.band = np.array(band)
          self.occupation = occ
          diff = np.diff(occ)
          pos = diff[np.where(abs(diff) > 0.5)]
          mask = np.in1d(diff, pos)
          ind = np.array(range(len(diff)))
          if len(ind[mask]) > 0:
            N_state = ind[mask][0]
            vb = max(self.band[:, N_state])
            cb = min(self.band[:, N_state + 1])
            vb_pos = np.argmax(self.band[:, N_state])
            cb_pos = np.argmin(self.band[:, N_state + 1])
            self.Eg = cb - vb
            if vb_pos == cb_pos:
              self.Eg_direct = True
            else:
              self.Eg_direct = False

          cell = []
          for i in range(1, 4):
            vec = filter(
              None, 
              self.xml[2][4][i].text.replace('\n', '').split(' '))
            cell.append([float(v) for v in vec])
          self.lattice = np.array(cell) / 1.889726124993
          self.celldm = qtk.lattice2celldm(self.lattice)
          self.molecule.R_scale = qtk.xyz2fractional(
            self.molecule.R, self.celldm)
            
        except IOError:
          qtk.warning('xml file of job %s not found' % qmout)
    else:
      qtk.warning('job %s not finished' % qmout)
Exemplo n.º 5
0
    def __init__(self, qmout, **kwargs):
        PlanewaveOutput.__init__(self, qmout, **kwargs)
        out_file = open(qmout)
        data = out_file.readlines()
        out_file.close()
        Et_pattern = re.compile("^.*total energy *=.*$")
        f_pattern = re.compile("^.*atom.*type.*force.*=.*$")
        Et_list = filter(Et_pattern.match, data)
        f_list = filter(f_pattern.match, data)
        if len(Et_list) > 0:
            Et_str = filter(Et_pattern.match, data)[-1]
            Et = float(Et_str.split()[-2])
            self.Et, self.unit = qtk.convE(Et, 'Ry-Eh')
            out_folder = os.path.split(os.path.abspath(qmout))[0]
            save = glob.glob(os.path.join(out_folder, '*.save'))

            # extract force information
            if len(f_list) > 0:
                fstr = [
                    filter(None,
                           fstr.split('=')[-1].split(' ')) for fstr in f_list
                ]
                # atomic unit force, HF/au, converted from Ry/au
                self.force = 0.5 * np.array([[float(comp) for comp in atm]
                                             for atm in fstr])

            # extract band structure from xml files
            if save:
                save = save[0]
                try:
                    data_xml = os.path.join(save, 'data-file.xml')
                    xml_file = open(data_xml)
                    tree = ET.parse(xml_file)
                    xml_file.close()
                    self.xml = tree.getroot()
                    kpoints = []
                    band = []

                    # extract celldm
                    celldm = []
                    cellVec = []
                    for i in range(1, 4):
                        cellvStr = filter(
                            None,
                            self.xml[2][4][i].text.replace('\n',
                                                           '').split(' '))
                        cellVec.append([float(v) for v in cellvStr])
                    self.celldm = qtk.cellVec2celldm(cellVec)

                    # extract structure
                    R = []
                    N = int(self.xml[3][0].text.replace('\n', ''))
                    Nsp = int(self.xml[3][1].text.replace('\n', ''))
                    for i in range(N):
                        RiStr = self.xml[3][5 + Nsp + i].get('tau')
                        Ri = [float(r) * 0.529177249 for r in RiStr.split(' ')]
                        ni = self.xml[3][5 + Nsp + i].get('SPECIES')
                        Z = [qtk.n2Z(ni)]
                        Z.extend(Ri)
                        R.append(Z)
                    self.molecule = qtk.Molecule()
                    self.molecule.build(R)

                    # access data for each kpoint
                    for k in self.xml[-2]:
                        k_str = k[0].text
                        coord = [float(c) for c in k_str.split()]
                        weight = float(k[1].text.split()[0])
                        coord.append(weight)
                        kpoints.append(coord)
                        ev_file = os.path.join(save, k[2].attrib['iotk_link'])
                        k_xml_file = open(ev_file)
                        k_xml = ET.parse(k_xml_file)
                        k_xml_file.close()
                        ev_k = k_xml.getroot()
                        ev_str = ev_k[2].text.split()
                        ev = [qtk.convE(float(entry), 'Eh-eV')[0]\
                              for entry in ev_str]
                        band.append(ev)
                        occ_str = ev_k[3].text.split()
                        occ = [float(entry) for entry in occ_str]
                    self.kpoints = np.array(kpoints)
                    self.mo_eigenvalues = copy.deepcopy(band[0])
                    self.band = np.array(band)
                    self.occupation = occ
                    diff = np.diff(occ)
                    pos = diff[np.where(abs(diff) > 0.5)]
                    mask = np.in1d(diff, pos)
                    ind = np.array(range(len(diff)))
                    if len(ind[mask]) > 0:
                        N_state = ind[mask][0]
                        vb = max(self.band[:, N_state])
                        cb = min(self.band[:, N_state + 1])
                        vb_pos = np.argmax(self.band[:, N_state])
                        cb_pos = np.argmin(self.band[:, N_state + 1])
                        self.Eg = cb - vb
                        if vb_pos == cb_pos:
                            self.Eg_direct = True
                        else:
                            self.Eg_direct = False

                    cell = []
                    for i in range(1, 4):
                        vec = filter(
                            None,
                            self.xml[2][4][i].text.replace('\n',
                                                           '').split(' '))
                        cell.append([float(v) for v in vec])
                    self.lattice = np.array(cell) / 1.889726124993
                    self.celldm = qtk.lattice2celldm(self.lattice)
                    self.molecule.R_scale = qtk.xyz2fractional(
                        self.molecule.R, self.celldm)

                except IOError:
                    qtk.warning('xml file of job %s not found' % qmout)
        else:
            qtk.warning('job %s not finished' % qmout)
Exemplo n.º 6
0
  def __init__(self, qmout, **kwargs):
    PlanewaveOutput.__init__(self, qmout, **kwargs)
    out_file = open(qmout)
    data = out_file.readlines()
    out_file.close()

    EStrList = filter(lambda x: 'Etotal' in x, data)
    EList = filter(lambda x: 'ETOT' in x, data)
    self.scf_step = len(EList)
    if self.scf_step > 0:
      Et_list = [float(filter(None, s.split(' '))[2]) for s in EList]
      self.Et = Et_list[-1]
    elif len(EStrList) > 0:
      EStr = EStrList[-1]
      self.Et = float(EStr.split(' ')[-1])

    if len(EStrList) > 0:
      EStr = EStrList[-1]
      detailInd = data.index(EStr)
      self.detail = data[detailInd-7:detailInd]
  
    xangst = filter(lambda x: 'xangst' in x, data)[-1]
    angst_n = len(data) - data[::-1].index(xangst) - 1
    xcart = filter(lambda x: 'xcart' in x, data)[-1]
    cart_n = len(data) - data[::-1].index(xcart) - 1
    Rstr = copy.deepcopy(data[angst_n:cart_n])
    Rstr[0] = Rstr[0].replace('xangst', '')
    R = [[float(r) for r in filter(None, s.split(' '))] for s in Rstr]
    N = len(R)
    ZstrOriginal = filter(lambda x: ' typat' in x, data)[-1]
    Zstr = ZstrOriginal.replace('typat', '')
    Zind = [int(z) for z in filter(None, Zstr.split(' '))]
    ZindItr = data.index(ZstrOriginal)
    while len(Zind) != N:
      ZindItr += 1
      ZindNewStr = filter(None, data[ZindItr].split(' '))
      ZindNew = [int(z) for z in ZindNewStr]
      Zind.extend(ZindNew)
    Znuc = filter(lambda x: 'znucl ' in x, data)[-1]
    Znuc = filter(None, Znuc.replace('znucl', '').split(' '))
    Znuc = [float(z) for z in Znuc]
    build = []
    for i in range(N):
      Z = [Znuc[Zind[i]-1]]
      Z.extend(R[i])
      build.append(Z)
    self.molecule = qtk.Molecule()
    self.molecule.build(build)

    if self.scf_step > 0:
      fStr = filter(lambda x: 'tesian forces (hartree/b' in x, data)[-1]
      fInd = data.index(fStr)
      fData = data[fInd+1:fInd+1+N]
      force = []
      for f in fData:
        fStr = filter(None, f.split(' '))[1:]
        force.append([float(fs) for fs in fStr])
      self.force = np.array(force)

    self.occupation = []
    try:
      r1p = re.compile(r'^[ a-z]{17} +[ 0-9.E+-]+$')
      r2p = re.compile(r'^ +[a-z]+ +.*$')
      report = filter(r2p.match, filter(r1p.match, data))
      occ_pattern = filter(lambda x: ' occ ' in x, report)[-1]
      occ_pattern_ind = len(report) - report[::-1].index(occ_pattern)
      occ_pattern_end = report[occ_pattern_ind]
      occ_ind_start = len(data) - data[::-1].index(occ_pattern) - 1
      occ_ind_end = len(data) - data[::-1].index(occ_pattern_end) - 1
      for i in range(occ_ind_start, occ_ind_end):
        for occ in filter(None, data[i].split(' ')):
          try:
            self.occupation.append(float(occ))
          except:
            pass
    except Exception as err:
      qtk.warning("error when extracting occupation number with" +\
        " error message: %s" % str(err))

    cell_pattern = re.compile(r'^ R.*=.* G.*=.*$')
    cell_list = filter(cell_pattern.match, data)
    cell = []
    for cstr in cell_list:
      cell.append(
        [float(c) for c in filter(None, cstr.split(' '))[1:4]])
    self.lattice = np.array(cell) / 1.889726124993
    self.celldm = qtk.lattice2celldm(self.lattice)
    self.molecule.R_scale = qtk.xyz2fractional(
      self.molecule.R, self.celldm)

    eigStr = os.path.join(os.path.split(qmout)[0], '*_EIG')
    eigFileList = glob.glob(eigStr)
    if len(eigFileList) != 0:
      if len(eigFileList) > 1:
        qtk.warning("more than one o_EIG files found")
      eigFile = open(eigFileList[0])
      eigData = eigFile.readlines()
      eigFile.close()
      spinList = filter(lambda x: 'SPIN' in x, eigData)
      if len(spinList) != 0:
        spinFactor = 2
        maxInd = eigData.index(spinList[-1])
      else:
        spinFactor = 1
        maxInd = len(eigData)
      ind = []
      for kStr in filter(lambda x: 'kpt#' in x, eigData):
        ind.append(eigData.index(kStr))
      band = []
      kpoints = []
      if spinFactor == 1:
        for i in range(len(ind)):
          wcoord = eigData[ind[i]].split('wtk=')[-1].split(', kpt=')
          weight = float(wcoord[0])
          cStr = filter(None, wcoord[1].split('(')[0].split(' '))
          coord = [float(c) for c in cStr]
          coord.append(weight)
          kpoints.append(coord)
          s = ind[i] + 1
          if i < len(ind) - 1:
            e = ind[i+1]
          else:
            e = len(eigData)
          eig_i = filter(None, ''.join(eigData[s:e]).split(' '))
          band.append([qtk.convE(float(ew), 'Eh-eV')[0]
                       for ew in eig_i])
  
        self.band = np.array(band)
        self.kpoints = np.array(kpoints)
        self.mo_eigenvalues = np.array(band[0]).copy()
        if len(self.occupation) > 0:
          diff = np.diff(self.occupation)
          ind = np.array(range(len(diff)))
          pos = diff[np.where(abs(diff) > 0.5)]
          mask = np.in1d(diff, pos)
          if len(ind[mask]) > 0:
            N_state = ind[mask][0]
            vb = max(self.band[:, N_state])
            cb = min(self.band[:, N_state + 1])
            vb_pos = np.argmax(self.band[:, N_state])
            cb_pos = np.argmin(self.band[:, N_state + 1])
            self.Eg = cb - vb
            if vb_pos == cb_pos:
              self.Eg_direct = True
            else:
              self.Eg_direct = False
  
      else:
        qtk.warning("spin polarized band data " +\
                    "extraction is not yet implemented")
    else:
      qtk.warning('no k-point information (o_EIG file) found')
Exemplo n.º 7
0
    def __init__(self, qmoutXML, **kwargs):
        PlanewaveOutput.__init__(self, qmoutXML, **kwargs)
        if qmoutXML:
            #xml_file = open(qmoutXML)
            tree = ET.parse(qmoutXML)
            #xml_file.close()
            self.xml = tree.getroot()
            self.Et, self.unit = qtk.convE(float(self.xml[-2][-5][1].text),
                                           'eV-Eh', '-')
            self.info = self.xml[0][1].text
            self.SCFStep = len(self.xml[-2]) - 9

            try:
                # kpoints and band structure data
                kpoints = []
                band = []
                occ = []

                ktag = self.xml[2]
                if ktag.tag != 'kpoints':
                    qtk.exit("vasp xml structure for kpoints unexpected")
                if ktag[0].tag == 'generation':
                    k_ind = 1
                elif ktag[0].tag == 'varray':
                    k_ind = 0
                else:
                    qtk.exit("vasp xml for kpointss has unexpected tag: %s" %
                             ktag[0].tag)
                for i in range(len(ktag[k_ind])):
                    k_str = ktag[k_ind][i].text
                    weight = float(ktag[k_ind + 1][i].text)
                    band_k = []
                    occ_k = []
                    bk_xml = self.xml[-2][-3][0][5][0][i]
                    for b_xml in bk_xml:
                        b, o = [float(c) for c in b_xml.text.split()]
                        band_k.append(b)
                        occ_k.append(o)
                    coord = [float(c) for c in k_str.split()]
                    coord.append(weight)
                    kpoints.append(coord)
                    band.append(band_k)
                    occ.append(occ_k)
                self.mo_eigenvalues = copy.deepcopy(band[0])
                self.kpoints = np.array(kpoints)
                self.band = np.array(band)
                self.occupation = occ[0]

                diff = np.diff(occ[0])
                pos = diff[np.where(abs(diff) > 0.5)]
                mask = np.in1d(diff, pos)
                ind = np.array(range(len(diff)))
                if len(ind[mask]) > 0:
                    N_state = ind[mask][0]
                    vb = max(self.band[:, N_state])
                    cb = min(self.band[:, N_state + 1])
                    vb_pos = np.argmax(self.band[:, N_state])
                    cb_pos = np.argmin(self.band[:, N_state + 1])
                    self.Eg = cb - vb
                    if vb_pos == cb_pos:
                        self.Eg_direct = True
                    else:
                        self.Eg_direct = False

                ind = np.arange(len(self.kpoints))[self.kpoints[:, -1] == 0]
                if len(ind > 0):
                    ind_w = np.arange(len(
                        self.kpoints))[self.kpoints[:, -1] != 0]
                    self.band_weighted = self.band[ind_w]
                    self.kpoints_weighted = self.kpoints[ind_w]
                    self.band = self.band[ind]
                    self.kpoints = self.kpoints[ind]

                # DOS data
                dos = []
                self.E_fermi = float(self.xml[-2][-1][0].text)
                for dos_xml in self.xml[-2][-1][1][0][5][0]:
                    dos_lst = filter(None, dos_xml.text.split(' '))
                    dos_E = [float(d) for d in dos_lst]
                    dos.append(dos_E)
                self.dos = np.array(dos)

            except Exception as err:
                qtk.warning("error when accessing kpoint data for %s with err: %s"\
                            % (self.name, err))
Exemplo n.º 8
0
  def __init__(self, qmoutXML, **kwargs):
    PlanewaveOutput.__init__(self, qmoutXML, **kwargs)
    if qmoutXML:
      #xml_file = open(qmoutXML)
      tree = ET.parse(qmoutXML)
      #xml_file.close()
      self.xml = tree.getroot()
      self.Et, self.unit = qtk.convE(float(self.xml[-2][-5][1].text),
                                     'eV-Eh', '-')
      self.info = self.xml[0][1].text
      self.SCFStep = len(self.xml[-2])-9

      try:
        # kpoints and band structure data
        kpoints = []
        band = []
        occ = []
  
        for i in range(len(self.xml[2][1])):
          k_str = self.xml[2][1][i].text
          weight = float(self.xml[2][2][i].text)
          band_k = []
          occ_k = []
          bk_xml = self.xml[-2][-3][0][5][0][i]
          for b_xml in bk_xml:
            b, o = [float(c) for c in b_xml.text.split()]
            band_k.append(b)
            occ_k.append(o)
          coord = [float(c) for c in k_str.split()]
          coord.append(weight)
          kpoints.append(coord)
          band.append(band_k)
          occ.append(occ_k)
        self.mo_eigenvalues = copy.deepcopy(band[0])
        self.kpoints = np.array(kpoints)
        self.band = np.array(band)
        self.occupation = occ[0]
  
        diff = np.diff(occ[0])
        pos = diff[np.where(abs(diff) > 0.5)]
        mask = np.in1d(diff, pos)
        ind = np.array(range(len(diff)))
        if len(ind[mask]) > 0:
          N_state = ind[mask][0]
          vb = max(self.band[:, N_state])
          cb = min(self.band[:, N_state + 1])
          vb_pos = np.argmax(self.band[:, N_state])
          cb_pos = np.argmin(self.band[:, N_state + 1])
          self.Eg = cb - vb
          if vb_pos == cb_pos:
            self.Eg_direct = True
          else:
            self.Eg_direct = False
  
        # DOS data
        dos = []
        self.E_fermi = float(self.xml[-2][-1][0].text) 
        print self.E_fermi
        for dos_xml in self.xml[-2][-1][1][0][5][0]:
          dos_lst = filter(None, dos_xml.text.split(' '))
          dos_E = [float(d) for d in dos_lst]
          dos.append(dos_E)
        self.dos = np.array(dos)

      except:
        qtk.warning("error when accessing kpoint data for %s"\
                    % self.name)