Exemplo n.º 1
0
def read_WAVEDERF(file='WAVEDERF'):
    '''Read the WAVEDERF file, a formatted WAVEDER file'''

    if not check_exist(file):
        print('Cannot find the %s file. Check the path:' % file)

    file = open(wavederf, "r").readlines()
    ispin, nkpts, nbands_cder = np.int32(file[0].split())

    # the last index of cder for cdum_x,cdum_y,cdum_z
    cder = np.empty([ispin, nkpts, nbands_cder, nbands_cder, 3])

    line = 1
    for spin in range(ispin):
        for kpt in range(nkpts):
            for band1 in range(nbands_cder):
                for band2 in range(nbands_cder):
                    x_real, x_imag, y_real, y_imag, z_real, z_imag = np.float64(
                        file[line].split())[-6:]
                    cdum[spin, kpt, band1, band2] = np.asarray([
                        np.complex(x_real, x_imag),
                        np.complex(y_real, y_imag),
                        np.complex(z_real, z_imag)
                    ])
                    line += 1

    return cder
Exemplo n.º 2
0
 def __init__(self, file="KPOINTS"):
     '''Read KPOINTS
        TODO: extend it to Selective dynamics
     '''
     if not check_exist(file):
         print('Cannot find the KPOINTS file. Check the path:', file)
         self.success = False
     else:
         self.kpoints = open(file, "r").readlines()
         self.success = True
Exemplo n.º 3
0
 def __init__(self, file="OUTCAR"):
     '''Read additional infomation that cannot be extracted from vasprun.xml'''
     if not check_exist(file):
         print('Cannot find the OUTCAR file (optional). Check the path:',
               file)
         self.success = False
     else:
         rungrep = subprocess.run(['grep', 'E-fermi', file],
                                  stdout=subprocess.PIPE)
         self.efermi = np.float64(str(rungrep.stdout).split()[3])
         self.success = True
Exemplo n.º 4
0
 def __init__(self, file="WAVECAR"):
     '''WAVECAR reading is modied the vaspwfc.py from QijingZheng's project
         ref: https://github.com/QijingZheng/VaspBandUnfolding/blob/master/vaspwfc.py)
     '''
     if not check_exist(file):
         print('Cannot find the WAVECAR file. Check the path:', file)
         self.success = False
     else:
         self._wavecar = open(file, 'rb')
         self.success = True
         self.read_header()
         self.get_band()
Exemplo n.º 5
0
 def __init__(self, file="POSCAR"):
     '''Read POSCAR
        TODO: extend it to Selective dynamics
     '''
     if not check_exist(file):
         print('Cannot find the POSCAR file (optional). Check the path:',
               file)
         self.success = False
     else:
         self.poscar = open(file, "r").readlines()
         self.cell = self.get_cell(self.poscar)
         self.success = True
Exemplo n.º 6
0
    def read_band(self, filename=None):
        '''Read the cp2k *.bs file'''
        if filename is None:
            filename = self.output.split(".")[0] + ".bs"

        if check_exist(filename):
            with open(filename, "r") as bs_file:
                klabel = []
                band = []
                kpath_frac = []
                for kpoint_set in SET_MATCH.finditer(bs_file.read()):
                    nkpts = np.int64(kpoint_set.groupdict()['totalpoints'])
                    set_content = kpoint_set.group('content')
                    sym_kpoint_coor = []
                    for point in SPOINTS_MATCH.finditer(set_content):
                        point_dict = point.groupdict()
                        sym_kpoint_coor.append([
                            point_dict['a'], point_dict['b'], point_dict['c']
                        ])

                    klabel.append(np.float64(sym_kpoint_coor))
                    kpts = []
                    band_alpha = []
                    band_beta = []
                    for point in POINTS_MATCH.finditer(set_content):
                        point_dict = point.groupdict()
                        spin = point_dict['spin']
                        if spin == '1':
                            energies = np.float64(point_dict['values'].split())
                            band_alpha.append(energies)
                            kpt = [
                                point_dict['a'], point_dict['b'],
                                point_dict['c']
                            ]
                            kpts.append(kpt)
                        else:
                            energies = np.float64(point_dict['values'].split())
                            band_beta.append(energies)

                    kpath_frac.append(np.float64(kpts))
                    if band_beta == []:
                        band.append(np.float64([band_alpha]))
                    else:
                        band.append(np.float64([band_alpha, band_beta]))

                self.band = band
                self.klabel = klabel
                self.kpath_frac = kpath_frac
        else:
            print('Cannot find the band structure (.bs) file. Check the path:',
                  filename)
Exemplo n.º 7
0
 def read_eig(self, seedname=None):  
     '''Read the seedname_band.dat and seedname.eig file'''
     if seedname is None: seedname = self.seedname
     if check_exist(seedname + '.eig'):
         with open(seedname + '.eig', "r") as file:
             lines = file.read().splitlines()
         
         eig = []
         nbands, nkpts = np.int64(lines[-1].split()[:2])
         for line in lines:
             eig.append(line.split()[-1])
         self.eig = np.asarray(eig, dtype=np.float64).reshape(nkpts, nbands)
     else:
         print('Cannot find the *.eig file. Check the path:', seedname + '.eig') 
Exemplo n.º 8
0
 def __init__(self, file="LOCPOT"):
     '''Read LOCPOT
        TODO: extend it to Selective dynamics
     '''
     if not check_exist(file):
         print('Cannot find the LOCPOT file. Check the path:', file)
         self.success = False
     else:
         self.locpot = open(file, "r").readlines()
         self.success = True
         self.cell = self.get_cell(self.locpot)
         self.natom = self.cell[2].shape[0]
         self.skip_poscar = self.natom + 9  #skip the POSCAR block in LOCPOT
         self.ngxyz, self.locpot_data = self.read_locpot(self.locpot)
Exemplo n.º 9
0
    def __init__(self, file=None):

        if file == None:  # The 1st
            proc = subprocess.Popen('/bin/ls *.cif',
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            out, err = proc.communicate()
            file = str(out).split("'")[1].split("\\")[0]
        if not misc.check_exist(file):
            print('Cannot find any cif file in the current directory', file)
        else:
            cif_raw = open(file, "r").readlines()
            self.cif = self.refine_cif(cif_raw)
            self.cell = self.make_cell()
Exemplo n.º 10
0
def read_WAVEDER(file='WAVEDER'):
    '''Read the WAVEDER file
    
        the matrix of the derivative of the cell periodic part
        of the wavefunctions with respect to i k is:      
        cder = CDER_BETWEEN_STATES(m,n,1:NK,1:ISP,j)= <u_m|  -i d/dk_j | u_n> = - <u_m| r_j |u_n>
    '''
    if not check_exist(file):
        print('Cannot find the %s file. Check the path:' % file)

    from scipy.io import FortranFile
    file = FortranFile(waveder, 'r')
    nb_tot, nbands_cder, nkpts, ispin = file.read_record(dtype=np.int32)
    nodesn_i_dielectric_function = file.read_record(dtype=np.float)
    wplasmon = file.read_record(dtype=np.float).reshape(3, 3)
    cder = file.read_record(dtype=np.complex64).reshape(
        ispin, nkpts, nbands_cder, nbands_cder, 3)

    return cder, nodesn_i_dielectric_function, wplasmon
Exemplo n.º 11
0
    def __init__(self, file="vasprun.xml"):

        if not check_exist(file):
            print('Cannot find the vasprun.xml file. Check the path:', file)
        else:
            self.vasprun = open(file, "r").readlines()

            # Read parameters:
            generator = self.copy_block(self.vasprun, 'generator', level=1)
            incar = self.copy_block(self.vasprun, 'incar', level=1)
            self.generator = self.extract_param(generator)
            self.incar = self.extract_param(incar)
            self.kpoints = self.get_kpoints()
            self.parameters = self.get_parameters()
            self.get_atominfo()
            self.get_structure()
            self.calculation_block = self.copy_block(self.vasprun,
                                                     'calculation',
                                                     level=1)
            self.lm = None
Exemplo n.º 12
0
    def read_win(self, seedname=None):  
        '''Read the seedname.win file'''
        
        if seedname is None: seedname = self.seedname
        if check_exist(seedname + '.win'):
            with open(seedname + '.win', "r") as file:
                win = file.read().splitlines()

            # Cell information
            lattice = copy_block(win, 'Unit_Cell_Cart', convert_to_float=True)
            atom_block = copy_block(win, 'atoms_cart')
            atom_sym = []
            atom_position = []
            for atm in atom_block:
                temp = atm.split()
                atom_sym.append(temp[0])
                atom_position.append(np.float64(temp[1:]))
            self.atom = atom_sym
            atom_number = utils.convert_atomtype(self.atom )
            self.cell = (lattice, atom_position, atom_number)
            
            # kmesh info
            self.kpts = np.asarray(copy_block(win, 'kpoints', convert_to_float=True))
            self.klabel = None
            kpoint_path = copy_block(win, 'kpoint_path')
            if kpoint_path is not []:
                num_kpoint = len(kpoint_path)
                high_sym_kpoints = []
                for i, kpoint in enumerate(kpoint_path):
                    if i == (num_kpoint - 1):
                        temp = kpoint.split()
                        high_sym_kpoints.append([temp[0], np.float64(temp[1:4])])
                        high_sym_kpoints.append([temp[4], np.float64(temp[5:])])
                    else:
                        temp = kpoint.split()
                        high_sym_kpoints.append([temp[0], np.float64(temp[1:4])])
                self.klabel = high_sym_kpoints
            
        else:
            print('Cannot find the *.win file. Check the path:', seedname + '.win')       
Exemplo n.º 13
0
def read_unk(path='.', spin=0, kpt=1, band=1):
    '''Export the periodic part of BF in a real space grid for plotting with wannier90
    '''
    spin = spin + 1
    file = path + '/' + 'UNK' + "%05d" % (kpt) + '.' + str(spin)
    if not check_exist(file):
        print('Cannot find the %s file. Check the path:' % file)

    from scipy.io import FortranFile
    unk_file = FortranFile(file, 'r')
    temp = unk_file.read_record(dtype=np.int32)
    ngrid, kpt, nbands = temp[:3], temp[3], temp[4]
    assert band <= nbands, 'The band index is larger than the No. of bands in the unk file'

    for i in range(band):
        temp = unk_file.read_record(dtype=np.complex128)
        if i == band - 1:
            unk = temp
        del temp

    unk_file.close()

    return unk.reshape(ngrid, order='F')
Exemplo n.º 14
0
    def read_ouput(self, filename=None):
        '''Read the cp2k output file'''
        if filename is None: filename = self.output

        assert check_exist(
            filename), "Cannot find the output. Check the path: " + filename
        with open(filename, "r") as file:
            outfile = file.read().splitlines()

        # Cell information
        cell_block = copy_block(outfile, "CELL_TOP")
        a_vec = cell_block[1].split()[4:7]
        b_vec = cell_block[2].split()[4:7]
        c_vec = cell_block[3].split()[4:7]
        lattice = np.float64([a_vec, b_vec, c_vec])

        atom_type, atom_position = get_atoms(outfile)
        self.atom = atom_type
        atom_number = utils.convert_atomtype(atom_type)
        self.cell = (lattice, atom_position, atom_number)

        self.efermi = get_value(outfile, keyword="Fermi energy")
        self.kpts = 0  # kmesh info: TODO: will test the Gamma point case first
Exemplo n.º 15
0
    def read_band(self, seedname=None):  
        '''Read the seedname_band.dat and seedname_band.kpt file'''
        if seedname is None: seedname = self.seedname
        if check_exist(seedname + '_band.dat'):
            with open(seedname + '_band.dat', "r") as file:
                lines = file.read().splitlines()
            
            band = []
            for i, line in enumerate(lines):
                if line == '  ':
                    nkpts = i + 1
                    break
                else:
                    band.append(np.float64(line.split()))
                    
            nbands = len(lines) // nkpts
            bands = [band]
            for line in range(1,nbands):
                band = []
                for point in range(nkpts):
                    band.append(lines[line*nkpts + point].split())
                bands.append(band[:-1])
            bands = np.asarray(bands, dtype=np.float64)
            self.kpath_abs = bands[0][:,0]
            self.band = bands[:,:,1].T
            
            #Get fractional kpath
            with open(seedname + '_band.kpt', "r") as file:
                lines = file.read().splitlines()

            kpath_frac = []
            for i in range(1, nkpts):
                kpath_frac.append(lines[i].split()[:-1])
            self.kpath_frac = np.asarray(kpath_frac, dtype=np.float64)
                
        else:
            print('Cannot find the *_band.dat file. Check the path:', seedname + '_band.dat')