def get_x_ray_CoFe(): xdb = XrayDB() lines_Fe = xdb.xray_lines('Fe', excitation_energy=20e3) lines_Co = xdb.xray_lines('Co', excitation_energy=20e3) intensity_Ka1 = (lines_Fe['Ka1'].intensity + lines_Fe['Ka2'].intensity + lines_Fe['Ka3'].intensity) return lines_Fe, lines_Co, intensity_Ka1
def initUI(self): """ initialize the GUI components """ self.sampleFileName = self.sampleFileNameLineEdit.text() self.doubleValidator = QDoubleValidator() self.integerValidator = QIntValidator() if self.sampleFileName == '': self.sampleFileName = None self.sampleNumsChanged() self.bkgNumChanged() self.stdNumChanged() #self.sampleThicknessLineEdit.setValidator(self.doubleValidator) self.bkgThicknessLineEdit.setValidator(self.doubleValidator) self.stdThicknessLineEdit.setValidator(self.doubleValidator) self.sampleThickness = float(self.sampleThicknessLineEdit.text()) self.bkgThickness = float(self.bkgThicknessLineEdit.text()) self.energyNpts = self.energyNptsSpinBox.value() self.repeatNpts = self.repeatSpinBox.value() self.normStd = self.normStdSampleComboBox.currentText() self.stdThickness = float(self.stdThicknessLineEdit.text()) self.xMinMaxText = self.xMinMaxLineEdit.text() self.xMin, self.xMax = list(map(float, self.xMinMaxText.split(':'))) self.interpType = self.interpComboBox.currentText() self.progressBar.setMinimum(0) self.progressBar.setValue(0) self.xdb = XrayDB()
def edgenom(filels, inter): jj = inter data = EData(filels[jj]) df = data.reader(data.datain) df['diff'] = df[df.columns[1]].diff() edgelib = XrayDB() edgeid = 'pre_unkn' for z in np.linspace(15, 77, 63): if abs( edgelib.xray_edge(edgelib.symbol(int(z)), 'K')[0] - df['e'][df['diff'].idxmax()]) < 15: edgeid = edgelib.symbol(int(z)) print( edgelib.xray_edge(edgelib.symbol(int(z)), 'K')[0] - df['e'][df['diff'].idxmax()]) print(edgeid) print('K') print(jj) elif abs( edgelib.xray_edge(edgelib.symbol(int(z)), 'L3')[0] - df['e'][df['diff'].idxmax()]) < 15: edgeid = edgelib.symbol(int(z)) print(edgeid) print('L3') print(jj) print( edgelib.xray_edge(edgelib.symbol(int(z)), 'K')[0] - df['e'][df['diff'].idxmax()]) return df, edgeid, filels[jj]
def test_xray_line_strengths(): xdb = XrayDB() assert len(xdb.xray_line_strengths('Hg', excitation_energy=2800)) == 2 assert len(xdb.xray_line_strengths('Hg', excitation_energy=12000)) == 3 assert len(xdb.xray_line_strengths('Hg', excitation_energy=12500)) == 9 assert len(xdb.xray_line_strengths('Hg', excitation_energy=14300)) == 13 assert len(xdb.xray_line_strengths('Hg', excitation_energy=16000)) == 17
def __init__(self, parent=None): """ """ QWidget.__init__(self, parent) loadUi('UI_Forms/XAnoS_EnergySteps.ui', self) self.xrdb = XrayDB() self.initialize_UI() self.init_signals()
def test_ionization_potentials(): xdb = XrayDB() assert xdb.ionization_potential('air') == 33.8 assert xdb.ionization_potential('helium') == 41.3 assert xdb.ionization_potential('He') == 41.3 assert xdb.ionization_potential('Si') == 3.68 with pytest.raises(ValueError): xdb.ionization_potential('p10')
def test_xraydb_version(): xdb = XrayDB() version = xdb.get_version() assert 'XrayDB Version: 4.0, Python' in version hist = xdb.get_version(with_history=True) assert len(hist) > 350 hist = hist.split('\n') assert len(hist) > 4
def test_density(): xdb = XrayDB() assert_allclose(xdb.density('Ne'), 0.00090, rtol=0.01) assert_allclose(xdb.density('Ti'), 4.506, rtol=0.01) assert_allclose(xdb.density('Kr'), 0.00375, rtol=0.01) assert_allclose(xdb.density('Mo'), 10.28, rtol=0.01) assert_allclose(xdb.density('Pd'), 12.03, rtol=0.01) assert_allclose(xdb.density('Au'), 19.3, rtol=0.01) with pytest.raises(ValueError): xdb.density('Mx')
def __init__(self, formula=None): self.formula = formula self.xdb = XrayDB() cols = ['symbol', 'covalent_radius_cordero'] ptable = get_table('elements') x = ptable[cols] self.covalent_radius = x.set_index('symbol').T.to_dict( 'index')['covalent_radius_cordero'] if formula is not None: self.parse(self.formula)
def signoise(filels, inter, edge): jj = inter data = EData(filels[jj]) df = data.reader(data.datain) edgelib = XrayDB() edgenom = edgelib.xray_edge(edge, 'K')[0] if len(df[df['e'] > 100 + edgenom]) < 20: edgenom = edgelib.xray_edge(edge, 'L3')[0] dftrim = df[df['e'] > 100 + edgenom] xfsmean = dftrim[dftrim.columns[1]].mean() xfsstd = dftrim[dftrim.columns[1]].std() return xfsmean, xfsstd
def plotTransmission(symbol, edge="K", thickness=0.001, energies=None): """ Plots absorption in a given material as function of wavelength. :param symbol: The chemical symbol of the material. :type symbol: str :param edge: The requested absorption edge (K, L1, L2, M1, M2, ...) :type edge: str :param thickness: The material thickness in centimeters." :type thickness: float :param energies: For which energies to plot the transmission. :type energies: ndarray """ # Instantiate the database. xdb = XrayDB() # Get info on requested edge. edge_data = xdb.xray_edge(symbol, edge) edge_position = edge_data[0] edge_fyield = edge_data[1] edge_jump = edge_data[2] # Mass density (ambient). rho = xdb.density(symbol) # Fix energy range. min_energy = 0.7 * edge_position max_energy = 1.3 * edge_position # Setup arrays if energies is None: energies = numpy.linspace(min_energy, max_energy, 1024) mu = xdb.mu_chantler(symbol, energy=energies) # Convert to iterable if needed. if not hasattr(thickness, "__iter__"): thickness = [thickness] absorption = [numpy.exp(-mu * rho * th) for th in thickness] for i, abso in enumerate(absorption): pyplot.plot(energies, abso, lw=2, label=r"%3.1f $\mu$m" % (thickness[i] * 1e4)) pyplot.xlabel('Energy (eV)') pyplot.ylabel('Transmission') pyplot.legend() pyplot.title("%s %s-edge" % (symbol, edge)) pyplot.show()
def __init__(self): self.E = None self.I = None self.sI = None self.min_E = 0 self.max_E = np.inf self.xdb = XrayDB() self.lines_Fe = self.xdb.xray_lines('Fe', excitation_energy=20e3) self.lines_Co = self.xdb.xray_lines('Co', excitation_energy=20e3) self.intensity_Ka1 = (self.lines_Fe['Ka1'].intensity + self.lines_Fe['Ka2'].intensity + self.lines_Fe['Ka3'].intensity)
def __init__(self, x=0, rmin=0.0, rmax=30.0, Nr=31, Rc=10.0, strho=1.0, tst=2.0, lrho=0.5, lexp=10.0, rhosol=0.0, norm=1.0, bkg=0.0, mpar={}): """ Documentation x : independent variable in the form of a scalar or an array Rc : Radial distance in Angstroms after which the solvent contribution starts strho : Concentration of the ions of interest in the stern layer in Molar tst : Thickness of stern layer in Angstroms lrho : The maximum concentration of the diffuse layer in Molars lexp : The decay length of the diffuse layer assuming exponential decay rhosol : The surrounding bulk density norm : Density of particles in Moles/Liter bkg : Constant background """ if type(x) == list: self.x = np.array(x) else: self.x = x self.rmin = rmin self.rmax = rmax self.Nr = Nr self.Rc = Rc self.strho = strho self.tst = tst self.lrho = lrho self.lexp = lexp self.rhosol = rhosol self.norm = norm self.bkg = bkg self.__mpar__ = mpar #If there is any multivalued parameter self.choices = { } #If there are choices available for any fixed parameters self.__xrdb__ = XrayDB() self.init_params() self.output_params = {'scaler_parameters': {}}
def __init__( self, x=0, E=12.0, fname1='W:/Tianbo_Collab/Mo132.xyz', eta1=1.0, fname2='/media/sf_Mrinal_Bera/Documents/MA-Collab/XTal_data/P2W12.xyz', eta2=0.0, rmin=0.0, rmax=10.0, Nr=100, qoff=0.0, sol=18.0, sig=0.0, norm=1, bkg=0.0, mpar={}): """ Calculates the form factor for two different kinds of molecules in cm^-1 for which the XYZ coordinates of the all the atoms composing the molecules are known x scalar or array of reciprocal wave vectors E Energy of the X-rays at which the scattering pattern is measured fname1 Name with path of the .xyz file containing X, Y, Z coordinates of all the atoms of the molecule of type 1 eta1 Fraction of molecule type 1 fname2 Name with path of the .xyz file containing X, Y, Z coordinates of all the atoms of the moleucule of type 2 eta2 Fraction of molecule type 2 rmin Minimum radial distance for calculating electron density rmax Maximum radial distance for calculating electron density Nr Number of points at which electron density will be calculated qoff Q-offset may be required due to uncertainity in Q-calibration sol No of electrons in solvent molecule (Ex: H2O has 18 electrons) sig Debye-waller factor norm Normalization constant which can be the molar concentration of the particles bkg Background """ if type(x) == list: self.x = np.array(x) else: self.x = np.array([x]) if os.path.exists(fname1): self.fname1 = fname1 else: self.fname1 = None self.eta1 = eta1 if os.path.exists(fname2): self.fname2 = fname2 else: self.fname2 = None self.eta2 = eta2 self.rmin = rmin self.__rmin__ = rmin self.rmax = rmax self.__rmax__ = rmax self.Nr = Nr self.__Nr__ = Nr self.norm = norm self.bkg = bkg self.E = E self.sol = sol self.qoff = qoff self.sig = sig self.__mpar__ = mpar #If there is any multivalued parameter self.choices = { } #If there are choices available for any fixed parameters self.__fnames__ = [self.fname1, self.fname2] self.__E__ = E self.__xdb__ = XrayDB() #if self.fname1 is not None: # self.__Natoms1__,self.__pos1__,self.__f11__=self.readXYZ(self.fname1) #if self.fname2 is not None: # self.__Natoms2__,self.__pos2__,self.__f12__=self.readXYZ(self.fname2) self.__x__ = self.x self.__qoff__ = self.qoff self.output_params = {'scaler_parameters': {}}
from xraydb import XrayDB import matplotlib.pyplot as plt import operator import numpy import scipy.optimize as optimization import scipy xray = XrayDB() Energy_Value = [i for i in range(12000, 26010, 10)] dn_count = 1 #real Xray source data source_xray = numpy.loadtxt('/ufs/piao/Desktop/data_xray.txt') source_xray = source_xray.transpose() source_xray[0] = source_xray[0] * 0.01165211 - 0.147653 print source_xray #detector efficiency data detector_efficiency = numpy.loadtxt('/ufs/piao/Downloads/Default Dataset.csv', delimiter=',') detector_efficiency = detector_efficiency.transpose() detector_efficiency[1] = detector_efficiency[1] / 100 print detector_efficiency def counting_on_threshold_source_real(threshold_kev): i = 0 for element in source_xray[0]: if element > threshold_kev:
def _larch_init(_larch): """initialize xraydb""" setsym = _larch.symtable.set_symbol setsym('_xray._xraydb', XrayDB()) setsym('_xray._materials', _read_materials_db())
def test_symbol(): xdb = XrayDB() assert xdb.symbol(40) == 'Zr'
def test_atomic_number(): xdb = XrayDB() assert xdb.atomic_number('Ne') == 10 with pytest.raises(ValueError): xdb.atomic_number('Mx')
def theoretical_spectrum(element, Energy_Value): return XrayDB().mu_elam(element, Energy_Value)
def test_molar_mass(): xdb = XrayDB() assert_allclose(xdb.molar_mass('Co'), 58.932, rtol=0.001) with pytest.raises(ValueError): xdb.molar_mass('Mx')
def test_density(): xdb = XrayDB() assert_allclose(xdb.molar_mass('Pb'), 207.2, rtol=0.001) with pytest.raises(ValueError): xdb.density('Mx')
from PyQt5.uic import loadUi from PyQt5.QtWidgets import QWidget, QApplication, QMessageBox, QMainWindow, QFileDialog, QDialog, QInputDialog, QTableWidgetItem, QLineEdit from PyQt5.QtCore import pyqtSignal, Qt, QRegExp from PyQt5.QtGui import QIntValidator, QDoubleValidator, QFont, QRegExpValidator, QValidator from PyQt5.QtTest import QTest import sys import os import numpy as np import re import scipy.constants from xraydb import XrayDB xdb = XrayDB() class DoubleValidator(QDoubleValidator): def __init__(self, parent, bottom=0): QDoubleValidator.__init__(self, parent, bottom=bottom) self.bottom = bottom def validate(self, text, pos): try: if float(text) >= self.bottom: state = QDoubleValidator.Acceptable else: state = QDoubleValidator.Invalid except: state = QDoubleValidator.Invalid return state, text, pos class RegExpValidator(QRegExpValidator):
import pylab as pl print(sys.argv) if len(sys.argv) == 7: element = sys.argv[1] edge_energy = 1e3 * float(sys.argv[2]) min_energy = 1e3 * float(sys.argv[3]) steps = int(sys.argv[4]) eoff = float(sys.argv[5]) try: fname = sys.argv[6] except: fname = '/tmp/positionerFile.txt' xrdb = XrayDB() evals = np.linspace(edge_energy, min_energy, steps) efine = np.linspace(edge_energy, min_energy, 1001) f1 = xrdb.f1_chantler(element=element, energy=efine, smoothing=0) f1vals = np.linspace(f1[0], f1[-1], steps) e1vals = np.interp(f1vals, f1, efine) print(np.diff(f1vals)) print(np.diff(e1vals)) evaltxt = '' pl.figure() etemp = np.linspace(min_energy, edge_energy + (edge_energy - min_energy), 1001) f1temp = xrdb.f1_chantler(element=element, energy=etemp, smoothing=0) pl.plot(etemp, f1temp, 'r-', label=element + '-Energy Edge') print("%10s\t%10s\t%10s\t%10s\t%10s" % ("Step", "f_value", "Mono_E", "Und_E", "f_1"))