def readSpectra(self): self.j = [] self.epsilon = [] self.states = defaultdict(list) filename = util.getSpectralDataDir() + self.species + '.dat' with open(filename) as dataFile: next(dataFile) for row in dataFile: if not row.strip(): continue elif row[0:5] == 'Limit': self.ionizationEnergy = float(row.rstrip('\n').split(', ')[1]) break values = row.rstrip('\n').split(', ') self.j.append(float(values[2])) self.epsilon.append(float(values[3])*constants.Cm_1ToJoules) # create new energy state for imported values state = EnergyState(values[0], values[1], values[2], values[3]) # append to dict organised by core configuration self.states[state.config].append(state)
def readProperties(self): jsonFilePath = util.getSpectralDataDir() + '/atomData.json' with open(jsonFilePath, 'r') as jsonFile: jsonData = json.load(jsonFile) speciesProperties = jsonData[self.name] self.atomicNumber = speciesProperties['atomicNumber'] self.charge = speciesProperties['charge'] self.noElectrons = speciesProperties['noElectrons'] self.Io = speciesProperties['Io'] * self.constants.eVToCm_1 self.cores = [] for key, core in speciesProperties['cores'].items(): self.cores.append(core)
def importFromFile(species): NistFilename = util.getSpectralDataDir() + species + ' NIST.dat' badSymbols = [' ', '|', '[', ']', '-', 'i', 't', '+', 'x', '?', '*'] badSymbolsTerm = [' ', '|', '-', 'i', 't', '+', 'x', '?', '*'] with open(NistFilename) as NistFile: with open(util.getSpectralDataDir() + species + '.dat', 'w') as writeFile: writeFile.write('config, term, J, epsion\n') next(NistFile) row = NistFile.readline() levelIdx = row.index('L') termIdx = row.index('T') jIdx = row.index('J') next(NistFile) next(NistFile) oldTerm = '' oldConfig = '' for row in NistFile: config = row[0:termIdx - 5] term = row[termIdx - 2:termIdx + 5] j = row[jIdx - 4:jIdx + 5] level = row[levelIdx - 5:levelIdx + 15] for symbol in badSymbols: j = j.replace(symbol, '') level = level.replace(symbol, '') for symbol in badSymbolsTerm: config = config.replace(symbol, '') term = term.replace(symbol, '') if term == '': term = oldTerm if config == '': config = oldConfig if '/' in j: j = float(j.split('/')[0]) / float(j.split('/')[1]) j = str(j) if not row[0].isalpha(): if j.strip() and level != '': writeFile.write(config + ', ') writeFile.write(term + ', ') writeFile.write(j + ', ') writeFile.write(level + '\n') else: writeFile.write('\n') else: writeFile.write('Limit, ' + level) break oldConfig = config oldTerm = term
def importFromFile(species): NistFilename = util.getSpectralDataDir() + species + ' NIST.dat' badSymbols = [' ', '|', '[', ']', '-', '+', 'x', '?', '*', 'w', 'x'] badSymbolsTerm = [' ', '|', '-', '+', 'x', '?', '*'] with open(NistFilename) as NistFile: with open(util.getSpectralDataDir() + species + '.dat', 'w') as writeFile: writeFile.write('config, term, J, epsion\n') next(NistFile) row = NistFile.readline() levelIdx = row.index('L') termIdx = row.index('T') jIdx = row.index('J') next(NistFile) next(NistFile) oldTerm = '' oldConfig = '' for row in NistFile: config = row[0:termIdx - 3] term = row[termIdx - 2:termIdx + 5] j = row[jIdx - 4:jIdx + 5] level = row[levelIdx - 5:levelIdx + 15] for symbol in badSymbols: j = j.replace(symbol, '') level = level.replace(symbol, '') for symbol in badSymbolsTerm: config = config.replace(symbol, '') term = term.replace(symbol, '') if term == '': term = oldTerm if config == '': config = oldConfig if '<' in config: openParIdx = config.index('<') closeParIdx = config.index('>') coreJ = config[openParIdx:closeParIdx + 1] config = config[:openParIdx] + str( coreJ) + config[closeParIdx + 1:] if '/' in j: j = float(j.split('/')[0]) / float(j.split('/')[1]) j = str(j) #### Removes consideration for LK coupling ####### if '[' not in term: if not row[0].isalpha(): if j.strip(): if level == '': level = 'None' writeFile.write(config + ', ') writeFile.write(term + ', ') writeFile.write(j + ', ') writeFile.write(level + '\n') else: writeFile.write('\n') oldConfig = config oldTerm = term
def readNISTSpectra(species): NIST = [] filename = util.getSpectralDataDir() + species.name + '.dat' def isNumber(string): try: int(string) return True except ValueError: return False def formatConfig(string): nStr = '' LStr = '' noElectronsStr = '' LIdx = len(string) + 1 for i, char in enumerate(string): if isNumber(char) and i < LIdx: nStr += char elif not isNumber(char): LStr += char LIdx = i if isNumber(char) and i >= LIdx: noElectronsStr += char n = int(nStr) L = util.subShellMap.index(LStr) if noElectronsStr != '': noElectrons = int(noElectronsStr) else: noElectrons = 1 return n, L, noElectrons def readConfiguration(inputStr): configs = inputStr.split('.') coreShells = [SubShell(1, 0, 2)] coreJ = None _, _, finalSubShellNoElectrons = formatConfig(configs[-1]) if finalSubShellNoElectrons == 1: coreTerm = None for config in configs[:-1]: if config[0] == '(': if '<' in config: openIdx = config.index('<') closeIdx = config.index('>') if '/' in config: slashIdx = config.index('/') num = float(config[openIdx + 1:slashIdx]) denom = float(config[slashIdx + 1:closeIdx]) coreJ = num / denom else: coreJ = float(config[openIdx + 1:closeIdx]) coreS = (float(config[1]) - 1.) / 2. coreL = util.termMap.index(config[2]) coreTerm = Term(coreL, coreS, coreShells[-1].n) else: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) core = Core(coreShells, coreTerm) n, L, noElectrons = formatConfig(configs[-1]) excitedShell = SubShell(n, L, noElectrons) excitedState = ExcitedState(excitedShell) else: for config in configs: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) core = Core(coreShells, None) excitedState = None return core, excitedState, coreJ def readTerm(inputStr): LStr = '' SStr = '' LIdx = len(inputStr) + 1 for i, char in enumerate(inputStr): if isNumber(char) and i < LIdx: SStr += char elif not isNumber(char): LStr += char LIdx = i L = util.termMap.index(LStr) S = (float(SStr) - 1.) / 2. return L, S with open(filename) as dataFile: next(dataFile) IDs = [] for row in dataFile: if not row.strip(): continue values = row.rstrip('\n').split(', ') core, excitedState, coreJ = readConfiguration(values[0]) L, S = readTerm(values[1]) if excitedState: n = excitedState.subShell.n else: n = core.maxN term = Term(L, S, n) configuration = Configuration(core, excitedState, term) if configuration.ID not in IDs: IDs.append(configuration.ID) NIST.append(configuration) else: configuration = NIST[IDs.index(configuration.ID)] for level in configuration.term.levels: if configuration.term.L == L and configuration.term.S == S and level.J == float( values[2]): if values[3] != 'None': level.setEnergy(float(values[3])) return NIST
def readNISTSpectra(species): NIST = [] filename = util.getSpectralDataDir() + species.name + '.dat' def isNumber(string): try: int(string) return True except ValueError: return False def formatConfig(string): nStr = '' LStr = '' noElectronsStr = '' LIdx = len(string) + 1 for i, char in enumerate(string): if isNumber(char) and i < LIdx: nStr += char elif not isNumber(char): LStr += char LIdx = i if isNumber(char) and i >= LIdx: noElectronsStr += char n = int(nStr) L = util.subShellMap.index(LStr) if noElectronsStr != '': noElectrons = int(noElectronsStr) else: noElectrons = 1 return n, L, noElectrons def readConfiguration(inputStr): configs = inputStr.split('.') coreShells = [SubShell(1, 0, 2)] #coreTerms = [] #cores = [] _, _, finalSubShellNoElectrons = formatConfig(configs[-1]) if finalSubShellNoElectrons == 1: for config in configs[:-1]: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) ''' maxElectrons = 2.*(L * 2. + 1.) if noElectrons < maxElectrons: coreSLs = getTerms(L, noElectrons) for coreSL in coreSLs: termObj = Term(coreSL[0], coreSL[1], n) cores.append(Core(coreShells, termObj)) ''' core = Core(coreShells, None) n, L, noElectrons = formatConfig(configs[-1]) excitedShell = SubShell(n, L, noElectrons) excitedState = ExcitedState(excitedShell) else: for config in configs: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) core = Core(coreShells, None) excitedState = None return core, excitedState def readTerm(inputStr): LStr = '' SStr = '' LIdx = len(inputStr) + 1 for i, char in enumerate(inputStr): if isNumber(char) and i < LIdx: SStr += char elif not isNumber(char): LStr += char LIdx = i L = util.termMap.index(LStr) S = (float(SStr) - 1.) / 2. return L, S with open(filename) as dataFile: next(dataFile) IDs = [] for row in dataFile: if not row.strip(): continue values = row.rstrip('\n').split(', ') core, excitedState = readConfiguration(values[0]) L, S = readTerm(values[1]) if excitedState: n = excitedState.subShell.n coreS = [S - 0.5, S + 0.5] coreL = clebschGordon(L, excitedState.L) print(core.atomicNotation, excitedState.subShell.getSubShellString(), coreS, coreL) subShellTerms = [] for subShell in core.subShells: if subShell.noElectrons != (4. * subShell.L + 2.): subShellTerms.append( getTerms(subShell.L, subShell.noElectrons)) print(subShellTerms) coreShellTerms = subShellTerms[ 0] #Will need to change this to combine multiple shells for L in coreL: for S in coreS: print([L, S]) if [L, S] in coreShellTerms: print('matched ', [L, S]) matchedL = L matchedS = S break ''' combinedTerms = [[0], [0]] for subShell in subShellTerms: LArr = [x[0] for x in subShell] SArr = [x[1] for x in subShell] maxL = max([x + y for x in LArr for y in combinedTerms[0]]) minL = min([abs(x - y) for x in LArr for y in combinedTerms[0]]) maxS = max([x + y for x in SArr for y in combinedTerms[1]]) minS = min([abs(x - y) for x in SArr for y in combinedTerms[1]]) def fRange(x, y): while x <= y: yield x x += 1. if minL != maxL: combinedTerms[0] = list(fRange(minL, maxL)) else: combinedTerms[0] = list(minS) if minS != maxS: combinedTerms[1] = list(fRange(minS, maxS)) else: combinedTerms[0] = list(minS) print(combinedTerms) for L in coreL: for S in coreS: print([L, S]) if L in combinedTerms[0] and S in combinedTerms[1]: print('matched', [L, S]) break ''' coreN = core.maxN core.term = Term(matchedL, matchedS, coreN) else: n = core.maxN core.term = Term(L, S, n) term = Term(L, S, n) if excitedState: print(excitedState.subShell.getSubShellString(), term.getTermString(), 'core - ', core.atomicNotation, core.term.getTermString()) configuration = Configuration(core, excitedState, term) if configuration.ID not in IDs: IDs.append(configuration.ID) NIST.append(configuration) else: configuration = NIST[IDs.index(configuration.ID)] for level in configuration.term.levels: if configuration.term.L == L and configuration.term.S == S and level.J == float( values[2]): level.setEnergy(float(values[3])) return NIST
def readNISTSpectra(species): NIST = [] filename = util.getSpectralDataDir() + species.name + '.dat' def isNumber(string): try: int(string) return True except ValueError: return False def formatConfig(string): nStr = '' LStr = '' noElectronsStr = '' LIdx = len(string) + 1 for i, char in enumerate(string): if isNumber(char) and i < LIdx: nStr += char elif not isNumber(char): LStr += char LIdx = i if isNumber(char) and i >= LIdx: noElectronsStr += char n = int(nStr) L = util.subShellMap.index(LStr) if noElectronsStr != '': noElectrons = int(noElectronsStr) else: noElectrons = 1 return n, L, noElectrons def readConfiguration(inputStr): configs = inputStr.split('.') coreShells = [] for config in configs[:-1]: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) core = Core(coreShells, 0) n, L, noElectrons = formatConfig(configs[-1]) excitedShell = SubShell(n, L, noElectrons) excitedState = ExcitedState(excitedShell) #print(core.atomicNotation, excitedState.subShell.getSubShellString()) return core, excitedState def readTerm(inputStr): LStr = '' SStr = '' LIdx = len(inputStr) + 1 for i, char in enumerate(inputStr): if isNumber(char) and i < LIdx: SStr += char elif not isNumber(char): LStr += char LIdx = i L = util.termMap.index(LStr) S = (float(SStr) - 1.)/2. return L, S with open(filename) as dataFile: next(dataFile) IDs = [] for row in dataFile: if not row.strip(): continue elif row[0:5] == 'Limit': ionizationEnergy = float(row.rstrip('\n').split(', ')[1]) break values = row.rstrip('\n').split(', ') core, excitedState = readConfiguration(values[0]) configuration = Configuration(core, excitedState) if configuration.ID not in IDs: IDs.append(configuration.ID) NIST.append(configuration) else: configuration = NIST[IDs.index(configuration.ID)] for term in configuration.terms: for level in term.levels: #print(term.getTermString()) #print(values[2])#, values[2], values[3]) L, S = readTerm(values[1]) #print(L, S, '\n') #term.J = values[2] ''' if term.n < 3: print('') print(configuration.ID) print(term.getTermString(), values[1]) print(term.L, L) print(term.S, S) print(level.J, values[2]) ''' if term.L == L and term.S == S and level.J == float(values[2]): #print('matched') #print(term.getTermString(), values) level.setEnergy(float(values[3])) #if term.n < 3: #print('match') #print(level.energy) #print(term.energy) #print('') #level = Level(int(values[2]), float(values[3])) #term = Term() #self.j.append(float(values[2])) #self.epsilon.append(float(values[3])*constants.Cm_1ToJoules) # create new energy state for imported values #state = EnergyState(values[0], values[1], values[2], values[3]) # append to dict organised by core configuration #self.states[state.config].append(state) return NIST
def readNISTSpectra(species): NIST = [] filename = util.getSpectralDataDir() + species.name + '.dat' def isNumber(string): try: int(string) return True except ValueError: return False def formatConfig(string): nStr = '' LStr = '' noElectronsStr = '' LIdx = len(string) + 1 for i, char in enumerate(string): if isNumber(char) and i < LIdx: nStr += char elif not isNumber(char): LStr += char LIdx = i if isNumber(char) and i >= LIdx: noElectronsStr += char n = int(nStr) L = util.subShellMap.index(LStr) if noElectronsStr != '': noElectrons = int(noElectronsStr) else: noElectrons = 1 return n, L, noElectrons def readConfiguration(inputStr): configs = inputStr.split('.') coreShells = [SubShell(1, 0, 2)] for config in configs[:-1]: n, L, noElectrons = formatConfig(config) coreShells.append(SubShell(n, L, noElectrons)) core = Core(coreShells, 0) #print(core.SMax) n, L, noElectrons = formatConfig(configs[-1]) excitedShell = SubShell(n, L, noElectrons) excitedState = ExcitedState(excitedShell) #print(core.atomicNotation, excitedState.subShell.getSubShellString()) return core, excitedState def readTerm(inputStr): LStr = '' SStr = '' LIdx = len(inputStr) + 1 for i, char in enumerate(inputStr): if isNumber(char) and i < LIdx: SStr += char elif not isNumber(char): LStr += char LIdx = i L = util.termMap.index(LStr) S = (float(SStr) - 1.)/2. return L, S with open(filename) as dataFile: next(dataFile) IDs = [] for row in dataFile: if not row.strip(): continue ''' elif row[0:5] == 'Limit': ionizationEnergy = float(row.rstrip('\n').split(', ')[1]) break ''' values = row.rstrip('\n').split(', ') #print(values) core, excitedState = readConfiguration(values[0]) #SArr = clebschGordon(core.maxS, excitedState.S) #LArr = range(0, max(clebschGordon(core.maxL, excitedState.L))+1) n = excitedState.subShell.n ''' for L in LArr: #print(L) for S in SArr: #print(L, S) termL, termS = readTerm(values[1]) term = Term(termL, termS, n) #print(term.getTermString()) configuration = Configuration(core, excitedState, term) if configuration.ID not in IDs: IDs.append(configuration.ID) NIST.append(configuration) else: configuration = NIST[IDs.index(configuration.ID)] L, S = readTerm(values[1]) for level in configuration.term.levels: if configuration.term.L == L and configuration.term.S == S and level.J == float(values[2]): level.setEnergy(float(values[3])) ''' L, S = readTerm(values[1]) term = Term(L, S, n) configuration = Configuration(core, excitedState, term) if configuration.ID not in IDs: IDs.append(configuration.ID) NIST.append(configuration) else: configuration = NIST[IDs.index(configuration.ID)] #print(configuration.term.levels) for level in configuration.term.levels: #print(level) if configuration.term.L == L and configuration.term.S == S and level.J == float(values[2]): #print(configuration.ID, level.J) level.setEnergy(float(values[3])) #print(level.energy) return NIST