Exemple #1
0
    def dynmat_modes(self, fname):
        matdynDict = io_dict.read_file(fname)
        qKeys = io_dict.find_all_keys_from_string(matdynDict, 'q =')
        qP = []
        for i in qKeys:
            qP.append([float(qi) for qi in string.split(matdynDict[i])[2:5]])
        qPoints = numpy.array(qP)

        # find number of atoms  per unit cell and dimensionality
        # get frequencies keys for the last q-point:
        fKeys = io_dict.find_all_keys_from_string_afterkey(
            matdynDict, qKeys[-1], 'omega')
        #  get sample displacement vector for the first frequency of the last q point and find its dimensionality
        #  here omegaShift = 1 means no space between displacements and frequencies (2 means 1 extra line ...)
        omegaShift = 1
        nDim = len(matdynDict[fKeys[0] + omegaShift].split()[1:-1]) / 2
        #  get number of atoms in unit cell
        nAtom = fKeys[1] - fKeys[0] - omegaShift

        # qShift = 2 means 1 exra line between q line and frequencies line
        qShift = 2

        #  create numpy array in accordance with idf format specification

        #    Pol = [ [ [ [ ] ] ] ]
        Pol = []
        Omegas = []
        for i in qKeys:
            #        Mode = [ [ [ ] ] ]
            Mode = []
            Omega = []
            for iOmega in range(
                    i + qShift,
                    nDim * nAtom * (nAtom + omegaShift) + i + qShift,
                    nAtom + omegaShift):
                # get omegas in THz:

                #            print float( matdynDict[ iOmega].split('=')[1].split()[0] )
                Omega.append(float(
                    matdynDict[iOmega].split('=')[2].split()[0]))
                #	    Atom = [ [ ] ]
                Atom = []
                for iAtom in range(iOmega + omegaShift,
                                   iOmega + omegaShift + nAtom):
                    vecStr = matdynDict[iAtom].split()[1:-1]
                    #		        vec = [  ]
                    vec = [
                        float(v1) + 1.0j * float(v2)
                        for v1, v2 in zip(vecStr[:-1:2], vecStr[1::2])
                    ]
                    Atom.append(vec)
                Mode.append(Atom)
            Pol.append(Mode)
            # assume only one q point here
            Omegas = Omega
        npOmega = numpy.array(Omegas)
        npPol = numpy.array(Pol)
        #    THz2meV = 4.1357 # meV * s
        #    output Omega in cm-1
        return (npPol, None), (npOmega, 'cm-1'), (qPoints, None)
def varnameValue(fname, var, val):
    'Dummy! Assumes no comments for a variable in question and one variable per string'
    import string
    pwscfDic = read_file(fname)
    key = find_key_from_string(pwscfDic, var)
    pwscfDic[key] = '    ' + var + ' = ' + str(val) + ',\n'
    save_dic(pwscfDic, fname)
 def getTotalEnergy(self):
     'Extract total energy value from pwscf output'
     #read Espresso output into memory:
     pwscfOut = qe_io_dict.read_file(self.pwscfOutput)
     key = qe_io_dict.find_key_from_marker_string(pwscfOut, '!', 'total energy')
     words = string.split(pwscfOut[key])
     return [float(words[4])]
Exemple #4
0
    def getLatticeParameters(self):
        'Extract lattice parameters after pwscf geometry optimization'

        def vectorLength(v):
            from math import sqrt
            s = 0.0
            for val in v:
                s = s + val**2
            return sqrt(s)

        pwscfOut = qe_io_dict.read_file(self.pwscfOutput)
        key_a_0 = qe_io_dict.find_key_from_string(pwscfOut,
                                                  'lattice parameter (a_0)')
        a_0 = float(string.split(pwscfOut[key_a_0])[4])
        keyEnd = max(
            qe_io_dict.find_all_keys_from_marker_string(
                pwscfOut, '!', 'total energy'))
        keyCellPar = qe_io_dict.find_key_from_string_afterkey(pwscfOut, keyEnd, \
                                                       'CELL_PARAMETERS (alat)') + 1
        a = vectorLength(
            [float(valstr) for valstr in string.split(pwscfOut[keyCellPar])])
        b = vectorLength([
            float(valstr) for valstr in string.split(pwscfOut[keyCellPar + 1])
        ])
        c = vectorLength([
            float(valstr) for valstr in string.split(pwscfOut[keyCellPar + 2])
        ])
        return [a * a_0, b * a_0, c * a_0]
def atomic_positions(fname, geometry):
    'Dummy! Assumes geometry description is right after "ATOMIC_POSITIONS" (no empty lines)'
    import string
    pwscfDic = read_file(fname)
    key = find_key_from_string(pwscfDic, 'ATOMIC_POSITIONS')
    for i in range(len(geometry)):
        pwscfDic[key+1+i] = geometry[i] + '\n'
    save_dic(pwscfDic, fname)
def k_points(fname, k_points):
    'Dummy! Assumes no comments and implies k-point values are in the next line after K_POINTS AUTOMATIC'
    import string
    pwscfDic = read_file(fname)
    key = find_key_from_string(pwscfDic, 'K_POINTS')
    k_string = string.join([str(v) + ' ' for v in k_points])
    pwscfDic[key+1] = k_string + '\n'
    save_dic(pwscfDic, fname)
Exemple #7
0
 def getTotalEnergy(self):
     'Extract total energy value from pwscf output'
     #read Espresso output into memory:
     pwscfOut = qe_io_dict.read_file(self.pwscfOutput)
     key = qe_io_dict.find_key_from_marker_string(pwscfOut, '!',
                                                  'total energy')
     words = string.split(pwscfOut[key])
     return [float(words[4])]
Exemple #8
0
def matdyn(fname):
    matdynDict = io_dict.read_file(fname)
    qKeys = io_dict.find_all_keys_from_string(matdynDict, 'q =')
    qP = []
    for i in qKeys:
        qP.append( [ float(qi) for qi  in string.split( matdynDict[ i ] )[2:5] ] )
    qPoints = np.array(qP)
    
    
# find number of atoms  per unit cell and dimensionality       
# get frequencies keys for the last q-point:    
    fKeys = io_dict.find_all_keys_from_string_afterkey( matdynDict, qKeys[-1], 'omega')
#  get sample displacement vector for the first frequency of the last q point and find its dimensionality
#  here omegaShift = 1 means no space between displacements and frequencies (2 means 1 extra line ...)
    omegaShift = 1
    nDim =  len( matdynDict[ fKeys[0] + omegaShift  ].split()[1:-1] )/2
#  get number of atoms in unit cell    
    nAtom =  fKeys[1] - fKeys[0] - omegaShift

# qShift = 2 means 1 exra line between q line and frequencies line
    qShift = 2
    
    
#  create numpy array in accordance with idf format specification    

    
#    Pol = [ [ [ [ ] ] ] ]
    Pol = []
    Omegas = []
    for i in qKeys:
#        Mode = [ [ [ ] ] ]
        Mode = []
        Omega = []
        for iOmega in range( i + qShift, nDim*nAtom*(nAtom + omegaShift) +  i + qShift, nAtom+omegaShift):
	    # get omegas in THz:

#            print float( matdynDict[ iOmega].split('=')[1].split()[0] )
            Omega.append( float( matdynDict[ iOmega].split('=')[2].split()[0] ) )
#	    Atom = [ [ ] ]
            Atom = []
            for iAtom in range( iOmega + omegaShift, iOmega + omegaShift + nAtom ):
                vecStr = matdynDict[ iAtom ].split()[1:-1]
#		        vec = [  ]
                vec = [ float(v1) + 1.0j*float(v2) for v1,v2 in zip( vecStr[:-1:2], vecStr[1::2] ) ]
                Atom.append(vec)
            Mode.append( Atom )
        Pol.append( Mode )
        Omegas.append( Omega )
    npOmega = np.array(Omegas)
    npPol = np.array(Pol)
#    THz2meV = 4.1357 # meV * s
#    output Omega in cm-1
    return [npPol, npOmega, qPoints]
 def getSinglePhonon(self):
     'Obtain a list of phonon modes from output generated by dynmat.x'
     dynmatOut = qe_io_dict.read_file(self.dynmatOutput)
     keyStart = qe_io_dict.find_key_from_marker_string(dynmatOut, '#', 'mode')
     modeNum = 1
     key = keyStart + 1
     words = string.split(dynmatOut[key])
     modes = []
     while words[0]	 == str(modeNum):
         modes.append( float(words[1]) )
         key = key + 1
         modeNum = modeNum + 1
         words = string.split(dynmatOut[key])
     return modes
Exemple #10
0
 def getSinglePhonon(self):
     'Obtain a list of phonon modes from output generated by dynmat.x'
     dynmatOut = qe_io_dict.read_file(self.dynmatOutput)
     keyStart = qe_io_dict.find_key_from_marker_string(
         dynmatOut, '#', 'mode')
     modeNum = 1
     key = keyStart + 1
     words = string.split(dynmatOut[key])
     modes = []
     while words[0] == str(modeNum):
         modes.append(float(words[1]))
         key = key + 1
         modeNum = modeNum + 1
         words = string.split(dynmatOut[key])
     return modes
Exemple #11
0
 def getLatticeParameters(self):
     'Extract lattice parameters after pwscf geometry optimization'
     def vectorLength(v):
         from math import sqrt
         s = 0.0
         for val in v: s = s + val**2
         return sqrt( s )
     pwscfOut = qe_io_dict.read_file(self.pwscfOutput)
     key_a_0 = qe_io_dict.find_key_from_string(pwscfOut, 'lattice parameter (a_0)')
     a_0 = float( string.split( pwscfOut[key_a_0] )[4] )
     keyEnd = max( qe_io_dict.find_all_keys_from_marker_string(pwscfOut, '!', 'total energy') )
     keyCellPar = qe_io_dict.find_key_from_string_afterkey(pwscfOut, keyEnd, \
                                                    'CELL_PARAMETERS (alat)') + 1
     a =  vectorLength( [ float(valstr) for valstr in string.split( pwscfOut[keyCellPar] ) ] )
     b =  vectorLength( [ float(valstr) for valstr in string.split( pwscfOut[keyCellPar+1] ) ] )
     c =  vectorLength( [ float(valstr) for valstr in string.split( pwscfOut[keyCellPar+2] ) ] )                
     return [a*a_0, b*a_0, c*a_0]