def test_atomic_data(): assert atomic_number('zn') == 30 assert atomic_symbol(26) == 'Fe' assert atomic_mass(45) > 102.8 assert atomic_mass(45) < 103.0 assert atomic_density(29) == atomic_density('cu') assert atomic_density(22) > 4.51
def element(elem=None): edges = atomic = lines = {} if elem is not None: atomic = { 'n': xraydb.atomic_number(elem), 'mass': xraydb.atomic_mass(elem), 'density': xraydb.atomic_density(elem) } _edges = xraydb.xray_edges(elem) _lines = xraydb.xray_lines(elem) lines = OrderedDict() for k in sorted(_lines.keys()): en, inten, init, final = _lines[k] # XrayLine lines[k] = XrayLine(energy=f'{en:.1f}', intensity=f'{inten:.5f}', initial_level=init, final_level=final) edges = OrderedDict() for k in sorted(_edges.keys()): en, fy, jump = _edges[k] # XrayEdge edges[k] = XrayEdge(energy=f'{en:.1f}', fyield=f'{fy:.5f}', jump_ratio=f'{jump:.3f}') return render_template('elements.html', edges=edges, elem=elem, atomic=atomic, lines=lines, materials_dict=materials_dict)
def darwinwidth(elem=None): edges = atomic = lines = {} if elem is not None: edges= xraydb.xray_edges(elem) atomic= {'n': xraydb.atomic_number(elem), 'mass': xraydb.atomic_mass(elem), 'density': xraydb.atomic_density(elem)} lines= xraydb.xray_lines(elem) return render_template('darwinwidth.html', edges=edges, elem=elem, atomic=atomic, lines=lines, materials_dict=materials_dict)
def element(elem=None): edges = atomic = lines = {} if elem is not None: atomic= {'n': xraydb.atomic_number(elem), 'mass': xraydb.atomic_mass(elem), 'density': xraydb.atomic_density(elem)} _edges= xraydb.xray_edges(elem) _lines= xraydb.xray_lines(elem) lines = OrderedDict() for k in sorted(_lines.keys()): lines[k] = _lines[k] edges = OrderedDict() for k in sorted(_edges.keys()): edges[k] = _edges[k] return render_template('elements.html', edges=edges, elem=elem, atomic=atomic, lines=lines, materials_dict=materials_dict)
def calculate_xafs(self, phase_file=None): if F8LIB is None: raise ValueError("Feff8 Dynamic library not found") if len(self.atoms) < 1: self.read_atoms() class args: pass # strings / char*. Note fixed length to match Fortran args.phase_file = (self.phase_file + ' ' * 256)[:256] args.exch_label = ' ' * 8 args.genfmt_version = ' ' * 30 # integers, including booleans for attr in ('index', 'nleg', 'genfmt_order', 'ipol', 'nnnn_out', 'json_out', 'verbose', 'nepts'): setattr(args, attr, pointer(c_long(int(getattr(self, attr))))) # doubles for attr in ('degen', 'rs_int', 'vint', 'mu', 'edge', 'kf', 'rnorman', 'gam_ch', 'ellip'): setattr(args, attr, pointer(c_double(getattr(self, attr)))) # integer arrays args.ipot = self.ipot.ctypes.data_as(POINTER(self.ipot.size * c_int)) args.iz = self.iz.ctypes.data_as(POINTER(self.iz.size * c_int)) # double arrays # print(" Rat 0 ", self.rat) for attr in ('evec', 'xivec', 'ri', 'beta', 'eta', 'k', 'real_phc', 'mag_feff', 'pha_feff', 'red_fact', 'lam', 'rep'): arr = getattr(self, attr) cdata = arr.ctypes.data_as(POINTER(arr.size * c_double)) setattr(args, attr, cdata) # handle rat (in atomic units) rat_atomic = self.rat / BOHR args.rat = (rat_atomic).ctypes.data_as( POINTER(rat_atomic.size * c_double)) onepath = F8LIB.calc_onepath # print(" Calc with onepath ", onepath, rat_atomic) # print(" args rat = ", args.rat.contents[:]) x = onepath(args.phase_file, args.index, args.nleg, args.degen, args.genfmt_order, args.exch_label, args.rs_int, args.vint, args.mu, args.edge, args.kf, args.rnorman, args.gam_ch, args.genfmt_version, args.ipot, args.rat, args.iz, args.ipol, args.evec, args.ellip, args.xivec, args.nnnn_out, args.json_out, args.verbose, args.ri, args.beta, args.eta, args.nepts, args.k, args.real_phc, args.mag_feff, args.pha_feff, args.red_fact, args.lam, args.rep) self.exch = args.exch_label.strip() self.version = args.genfmt_version.strip() # print(" Calc with onepath done") # unpack integers/floats for attr in ('index', 'nleg', 'genfmt_order', 'degen', 'rs_int', 'vint', 'mu', 'edge', 'kf', 'rnorman', 'gam_ch', 'ipol', 'ellip', 'nnnn_out', 'json_out', 'verbose', 'nepts'): setattr(self, attr, getattr(args, attr).contents.value) # some data needs recasting, reformatting self.mu *= (2 * RYDBERG) self.nnnn_out = bool(self.nnnn_out) self.json_out = bool(self.json_out) self.verbose = bool(self.verbose) # unpck energies for attr in ('evec', 'xivec'): cdata = getattr(args, attr).contents[:] setattr(self, attr, np.array(cdata)) nleg = self.nleg nepts = self.nepts # arrays of length 'nepts' for attr in ('k', 'real_phc', 'mag_feff', 'pha_feff', 'red_fact', 'lam', 'rep'): cdata = getattr(args, attr).contents[:nepts] setattr(self, attr, np.array(cdata)) self.pha = self.real_phc + self.pha_feff self.amp = self.red_fact * self.mag_feff # unpack arrays of length 'nleg': for attr in ('ipot', 'beta', 'eta', 'ri'): cdata = getattr(args, attr).contents[:] setattr(self, attr, np.array(cdata)) # rat is sort of special, and calculate reff too: rat = args.rat.contents[:] rat = np.array(rat).reshape(2 + FEFF_maxleg, 3).transpose() self.rat = BOHR * rat _rat = self.rat.T reff = 0. for i, atom in enumerate(_rat[1:]): prev = _rat[i, :] reff += np.sqrt((prev[0] - atom[0])**2 + (prev[1] - atom[1])**2 + (prev[2] - atom[2])**2) self.reff = reff / 2.0 self.geom = [] rmass = 0. for i in range(nleg): ipot = int(self.ipot[i]) iz, sym = self.atoms[ipot] mass = atomic_mass(iz) x, y, z = _rat[i][0], _rat[i][1], _rat[i][2] self.geom.append((str(sym), iz, ipot, x, y, z)) rmass += 1.0 / max(1.0, mass) self.rmass = 1. / rmass
def __read(self, filename): try: lines = open(filename, 'r').readlines() except: print('Error reading file %s ' % filename) return self.filename = filename mode = 'header' self.potentials, self.geom = [], [] data = [] pcounter = 0 iline = 0 for line in lines: iline += 1 line = line[:-1] if line.startswith('#'): line = line[1:] line = line.strip() if iline == 1: self.title = line[:64].strip() self.version = line[64:].strip() continue if line.startswith('k') and line.endswith('real[p]@#'): mode = 'arrays' continue elif '----' in line[2:10]: mode = 'path' continue # if (mode == 'header' and line.startswith('Abs') or line.startswith('Pot')): words = line.replace('=', ' ').split() ipot, z, rmt, rnm = (0, 0, 0, 0) words.pop(0) if line.startswith('Pot'): ipot = int(words.pop(0)) iz = int(words[1]) rmt = float(words[3]) rnm = float(words[5]) self.potentials.append((ipot, iz, rmt, rnm)) elif mode == 'header' and line.startswith('Gam_ch'): words = line.replace('=', ' ').split(' ', 2) self.gam_ch = float(words[1]) self.exch = words[2] elif mode == 'header' and line.startswith('Mu'): words = line.replace('=', ' ').split() self.mu = float(words[1]) self.kf = float(words[3]) self.vint = float(words[5]) self.rs_int = float(words[7]) elif mode == 'path': pcounter += 1 if pcounter == 1: w = [float(x) for x in line.split()[:5]] self.__nleg__ = int(w.pop(0)) self.degen, self.__reff__, self.rnorman, self.edge = w elif pcounter > 2: words = line.split() xyz = [float(x) for x in words[:3]] ipot = int(words[3]) iz = int(words[4]) if len(words) > 5: lab = words[5] else: lab = atomic_symbol(iz) amass = atomic_mass(iz) geom = [lab, iz, ipot, amass] + xyz self.geom.append(tuple(geom)) elif mode == 'arrays': d = np.array([float(x) for x in line.split()]) if len(d) == 7: data.append(d) data = np.array(data).transpose() self.k = data[0] self.real_phc = data[1] self.mag_feff = data[2] self.pha_feff = data[3] self.red_fact = data[4] self.lam = data[5] self.rep = data[6] self.pha = data[1] + data[3] self.amp = data[2] * data[4] self.__rmass = None # reduced mass of path