def dosDiff(self, vincinity): """ Difference between spin up and down DOS """ print('Running DOS difference analysis...') concentrations = [] I_dos = [] normalised = [] outFile = os.path.join(self.analysisDir, 'dos_diff.txt') normalisedFile = os.path.join(self.analysisDir, 'dos_diff_normalised.txt') checkAnalysisFiles(outFile, normalisedFile) # Define time variables for calculating time left. numData = len(self.listDataDir) numDataLeft = numData startTime = time.time() prevTime = startTime eachTimeTaken = [] # Start the analysis process. for dirname in self.listDataDir: # Get DOS data. dosUpFile = os.path.join(self.dataDir, dirname, 'dos_up.txt') dosDownFile = os.path.join(self.dataDir, dirname, 'dos_down.txt') rawFile = os.path.join(self.rawDir, dirname, 'dos.agr') dosUp = getDOS(dosUpFile, rawFile, 'up') dosDown = getDOS(dosDownFile, rawFile, 'down') # Correction to the Fermi level from the DOS data. dataLen = len(dosDown) truncated = [] for i in range(dataLen): if math.fabs(dosDown[i][0]) < vincinity: truncated.append(dosDown[i]) correction = sorted(truncated, key=itemgetter(1))[0][0] # Shift the whole dataset. # for i in range(dataLen): # dosUp[i][0] += correction # dosDown[i][0] += correction # Linearly interpolate the DOS data. dosUpInterp = nmod.getInterp1d(dosUp) dosDownInterp = nmod.getInterp1d(dosDown) # Calculate the difference between the DOS at E-E_f = 0eV. dosDiff = dosUpInterp(correction) - dosDownInterp(correction) # dosDiff = dosDownInterp(0) I_dos.append(dosDiff) concentrations.append(dirname) with open(outFile, 'a+') as f: f.write(dirname + ' ' + str(dosDiff) + '\n') # Calculate time left. eachTimeTaken.append(time.time() - prevTime) prevTime = time.time() numDataLeft -= 1 sys.stdout.write('\r' + str(numDataLeft) + '/' + str(numData) + ' - Time left: ' + nmod.seconds2str( nmod.findMean(eachTimeTaken) * numDataLeft) + ' ') sys.stdout.flush() # Normalise the data and store as a new file. normalised = nmod.normalise(I_dos) print('\nNormalising DOS difference data...') with open(normalisedFile, 'a+') as f: for i in range(len(normalised)): f.write(concentrations[i] + ' ' + str(normalised[i]) + '\n') print('DOS difference analysis completed. Time taken: ' + nmod.seconds2str(time.time() - startTime))
def bandGap(self, aInit, stripSize, stepSize): """ Band gap analysis """ print('Running band gap analysis...') iterations = int(math.fabs(aInit) / stepSize) + 1 concentrations = [] I_bg = [] normalised = [] outFile = os.path.join(self.analysisDir, 'band_gap.txt') normalisedFile = os.path.join(self.analysisDir, 'band_gap_normalised.txt') checkAnalysisFiles(outFile, normalisedFile) # Define time variables for calculating time left. numData = len(self.listDataDir) numDataLeft = numData startTime = time.time() prevTime = startTime eachTimeTaken = [] # Start the analysis process. for dirname in self.listDataDir: # Get DOS data. dosFile = os.path.join(self.dataDir, dirname, 'dos_down.txt') rawFile = os.path.join(self.rawDir, dirname, 'dos.agr') dos = getDOS(dosFile, rawFile, 'down') # Linearly interpolate the DOS data. dosInterp = nmod.getInterp1d(dos) integrals = [] # Calculate minimum integral by translating a fixed width strip. for i in range(iterations): delta = i * stepSize a = aInit + delta b = aInit + stripSize + delta integral = integrate.quad(dosInterp, a, b, limit=100)[0] integrals.append(integral) minIntegral = min(integrals) I_bg.append(-minIntegral) concentrations.append(dirname) with open(outFile, 'a+') as f: f.write(dirname + ' ' + str(minIntegral) + '\n') # Calculate time left. eachTimeTaken.append(time.time() - prevTime) prevTime = time.time() numDataLeft -= 1 sys.stdout.write('\r' + str(numDataLeft) + '/' + str(numData) + ' - Time left: ' + nmod.seconds2str( nmod.findMean(eachTimeTaken) * numDataLeft) + ' ') sys.stdout.flush() # Normalise the data and store as a new file. normalised = nmod.normalise(I_bg) print('\nNormalising band gap data...') with open(normalisedFile, 'a+') as f: for i in range(len(normalised)): f.write(concentrations[i] + ' ' + str(normalised[i]) + '\n') print('Band gap analysis completed. Time taken: ' + nmod.seconds2str(time.time() - startTime))