def getEigAndPar(timeSteps=None, forceReread=False): """ return the Times, Eigvalues and Partitions at selected timeSteps write two files EIG and PAR """ options = tdapOptions() systemLabel = options.label timestep = options.tdTimeStep[0] if timeSteps == None: timeSteps = getEIGSteps() time = np.array(timeSteps) * timestep eig = loadSaved('EIG') par = loadSaved('PAR') saved = ((len(eig)) != 0 and (len(par)) != 0) if (not saved) or forceReread: eig = [] par = [] for i in timeSteps: eig.append(readEigFile(systemLabel + str(i) + '.EIG')) par.append(readEigFile(systemLabel + str(i) + 'q.EIG')) eig = np.array(eig) par = np.array(par) np.save('EIG', eig) np.save('PAR', par) return time, eig, par
def getImagElectricFunction(direction, dumping=0.00): from scipy.fftpack import fft timeArray, efield = getEField() timeArray, dipole = getDipolePython() option = tdapOptions() lengthTime = option.tdTimeStep[0] timeArray = timeArray[2:] / option.tdTimeStep[0] numStep = len(timeArray) dipole = dipole[2:, direction] dipole *= np.exp(-dumping * timeArray) freqResolution = 1.0 / (lengthTime * numStep) freqArray = (timeArray - (numStep / 2.0)) * freqResolution energyArray = freqArray * 4.1356 energyArray = energyArray[numStep / 2:] epsilon = fft(dipole)[:numStep / 2] epsilon = (np.real(epsilon), np.imag(epsilon)) import pandas as pd df = pd.DataFrame({ 'x-energy': energyArray, 'y1-Im(alpha)': np.abs(epsilon[0] * energyArray / 4.1356), 'y2-Re(alpha)': np.abs(epsilon[1] * energyArray / 4.1356) }) #print df df.to_csv('DielectricFunction.csv', sep=',') return energyArray, np.abs(epsilon[0] * energyArray / 4.1356), np.abs( epsilon[1] * energyArray / 4.1356)
def getBerrySteps(): options = tdapOptions() stepLines = os.popen('ls ' + options.label + '*.Berry').readlines() steps = [ int(step.split('.')[0].replace(options.label, '')) for step in stepLines ] return np.sort(steps)
def getBerry(): options = tdapOptions() selectStep = getBerrySteps() #print selectStep timestep = options.tdTimeStep[0] selectTime = selectStep * timestep berry = np.array([readBerryFile(str(step)) for step in selectStep]) return selectTime, berry
def getDipole(): options = tdapOptions() lines = os.popen('grep -n "Electric dipole (a.u.)" result').readlines() dipole = [(float(line.split()[-3]), float(line.split()[-2]), float(line.split()[-1])) for line in lines] timestep = options.tdTimeStep[0] dipole = np.array(dipole[:-1]) time = np.arange(len(dipole)) * timestep return time, dipole
def readBerryFile(step=''): """ return the Eigenvalues read from systemLabel.EIG """ options = tdapOptions() systemLabel = options.label BerryFile = open(systemLabel + step + '.Berry') Berry = [[float(value) for value in line.split()] for line in BerryFile.readlines()] return np.array(Berry)
def getFermiEnergy(): """ return the Fermi Energy read from systemLabel.EIG if failed, return 0 rather than raise an exception """ options = tdapOptions() systemLabel = options.label if os.path.exists(systemLabel + '.EIG'): Efermi = float(open(systemLabel + '.EIG').readline().split()[0]) else: Efermi = 0.0 return Efermi
def getHomo(): """ return the index of the highest occupied molecular orbital (H**O) """ options = tdapOptions() #NumElectron=float(os.popen('grep "Total number of electrons:" result').readline().split()[-1]) NumElectron = float( pythonGrep("Total number of electrons:", 'result')[0].split()[-1]) readFile = os.popen('grep -i "SpinPolarized" ' + options.inputFile) line = readFile.readline() if line == '': nspin = 2 else: nspin = 1 h**o = int(NumElectron) / nspin return h**o
def getBands(bandType='e'): """ return the bands read from systemLabel.bands as the dimension numKpoint x numBand x numSpin returns: X, Ek, xticks, xticklabels """ import math options = tdapOptions() systemLabel = options.label band_file = open(systemLabel + '.bands') if bandType == 'e': FermiEnergy = float(band_file.readline().split()[0]) else: band_file.readline() FermiEnergy = 0.0 kmin, kmax = (float(i) for i in band_file.readline().split()) emin, emax = (float(i) for i in band_file.readline().split()) numBand, numSpin, numKpoint = (int(i) for i in band_file.readline().split()) Ek = np.zeros([numKpoint, numBand, numSpin]) X = np.zeros(numKpoint) for kpt in range(numKpoint): eigen = [] for ispin in range(numSpin): for iband in range(int(math.ceil(numBand / 10.0))): line = band_file.readline() eigen.extend([float(i) for i in line.split()]) X[kpt] = eigen[0] eigen.pop() Ek[kpt, :, :] = np.array(eigen).reshape( numBand, numSpin) - FermiEnergy #.reshape(1,-1) - EFermi numSpecK = int(band_file.readline().split()[0]) xticks = [] xticklabels = [] for i in range(numSpecK): line = band_file.readline() xticks.append(float(line.split()[0])) xticklabels.append(r'$' + line.split()[1][1:-1] + '$') return X, Ek, xticks, xticklabels
def getProjectedPartition(selectK=None): """ """ options = tdapOptions() selectStep = getEIGSteps() #print selectStep timestep = options.tdTimeStep[0] selectTime = selectStep * timestep SaveName = 'ProjectedPartition' exe = [] if len(exe) != len(selectStep): exe = [] for index, step in enumerate(selectStep): partition = readEigFile(options.label + str(step) + 'q.EIG') exe.append(partition) exe = np.array(exe) np.save(SaveName, exe) return selectTime, exe
def getAdiabaticEigenvalue(selectK=None): """ """ options = tdapOptions() selectStep = getEIGSteps() #print selectStep timestep = options.tdTimeStep[0] selectTime = selectStep * timestep SaveName = 'AdiabaticEigenvalue' exe = loadSaved(SaveName) if len(exe) != len(selectStep): exe = [] for index, step in enumerate(selectStep): partition = readEigFile(options.label + str(step) + '.EIG') exe.append(partition) exe = np.array(exe) np.save(SaveName, exe) return selectTime, exe
def getEnergyTemperaturePressure(ave=False): """ return the Temperature, KS Energy and Total Energy as the dimension of Nstep read from systemLabel.MDE returns the Temperature, KS Energy, Total Energy, Volume, Pressure """ options = tdapOptions() systemLabel = options.label if options.mdTimeStep[0] < 1E-10: timestep = options.tdTimeStep[0] start = 2 else: start = 0 timestep = options.mdTimeStep[0] if (os.path.exists(systemLabel + '.MDE')): energy_file = open(systemLabel + '.MDE') data = [] for i in energy_file.readlines(): if i.split()[0] == '#': continue data.append([float(j.replace('*', '0')) for j in i.split()]) data = np.array(data) if ave: numAtom = getNumOfAtoms() #print numAtom data[start:, 2:4] /= numAtom #print data X = data[:, 0] * timestep return X[start:], data[start:, 1], data[start:, 2], data[start:, 3], data[start:, 4], data[start:, 5] else: time, msd = readMSD() f = os.popen('grep "Ekin + Etot (const)" result') energy = np.array([float(line.split()[-2]) for line in f.readlines()]) * 13.6 #data=np.array([energy,energy,energy,energy,energy]).T return time, energy, energy, energy, energy, energy
def getTDEig(timeSteps=None, forceReread=False): """ return the Times, Eigvalues and Partitions at selected timeSteps write two files EIG and PAR """ options = tdapOptions() systemLabel = options.label timestep = options.tdTimeStep[0] steps = np.arange(3, options.mdFinalStep) time = np.array(steps) * timestep eig = loadSaved('TDEIG') saved = ((len(eig)) != 0) if (not saved) or forceReread: eig = np.array([ readEigFile(systemLabel + str(i) + 'td.EIG', sep=False) for i in steps ]) np.save('TDEIG', eig) return time, eig
def getDipolePython(): options = tdapOptions() context = [] for line in open('result').readlines(): if len(line) == 1: continue #print line, if 'Electric' in line.split() and 'TDAP' in line.split(): context.append(line[:-1]) #for line in context: # print line.split()[-3:] dipole = [[ float(line.split()[-3]), float(line.split()[-2]), float(line.split()[-1]) ] for line in context] #print context #dipole = [(float(line.split()[-3]),float(line.split()[-2]),float(line.split()[-1])) for line in lines] timestep = options.tdTimeStep[0] dipole = np.array(dipole) time = np.arange(len(dipole)) * timestep return np.array(time), np.array(dipole)