class ImporterMock(ImporterBase): TRANSITIONS = ( pyxray.xray_transition("Ka1"), pyxray.xray_transition("La1"), pyxray.xray_transition("Ma1"), ) def __init__(self): super().__init__() self.import_analysis_methods[ PhotonIntensityAnalysis] = self._import_analysis_photonintensity self.import_analysis_methods[ KRatioAnalysis] = self._import_analysis_kratio async def _import(self, options, dirpath, erracc): return self._run_importers(options, dirpath, erracc) def _import_analysis_photonintensity(self, options, analysis, dirpath, erracc): builder = EmittedPhotonIntensityResultBuilder(analysis) number_trajectories = options.program.number_trajectories beam_energy_eV = options.beam.energy_eV overall_composition = {} for material in options.sample.materials: for z, wf in material.composition.items(): overall_composition.setdefault(z, 0.0) overall_composition[z] += wf total_wf = sum(overall_composition.values()) for z, wf in overall_composition.items(): for transition in self.TRANSITIONS: try: energy_eV = pyxray.xray_transition_energy_eV(z, transition) relative_weight = pyxray.xray_transition_relative_weight( z, transition) except pyxray.NotFound: continue if energy_eV >= beam_energy_eV: continue if relative_weight <= 0.01: continue intensity = number_trajectories * (wf / total_wf) * relative_weight error = math.sqrt(intensity) builder.add_intensity((z, transition), intensity, error) return [builder.build()] def _import_analysis_kratio(self, options, analysis, dirpath, erracc): # Do nothing return []
def __init__(self, element, line): self._element = pyxray.element(element) if not isinstance(line, (pyxray.XrayTransition, pyxray.XrayTransitionSet)): try: line = pyxray.xray_transition(line) except pyxray.NotFound: line = pyxray.xray_transitionset(line) self._line = line self._name = None # Late initialization signal = pymontecarlo.settings.preferred_xrayline_notation_changed signal.connect(self._on_settings_changed) signal = pymontecarlo.settings.preferred_xrayline_encoding_changed signal.connect(self._on_settings_changed)
class PhotonResultBuilderBase(ResultBuilderBase): _EXTRA_TRANSITIONS = ( pyxray.xray_transition("K"), pyxray.xray_transition("L"), pyxray.xray_transition("M"), pyxray.xray_transition("N"), pyxray.xray_transition("Ka"), pyxray.xray_transition("La"), pyxray.xray_transition("Ll,n"), pyxray.xray_transition("Ma"), pyxray.xray_transition("Mz"), ) def __init__(self, analysis, result_class): super().__init__(analysis) self.data = {} self.result_class = result_class def _add(self, xrayline, result): xrayline = convert_xrayline(xrayline) self.data[xrayline] = result @abc.abstractmethod def _sum_results(self, results): raise NotImplementedError def _create_extra_transitions(self): # Expand data element_transition_results = {} for xrayline, result in self.data.items(): element_transition_results.setdefault( xrayline.element, {})[xrayline.transition] = result newdata = {} for element in element_transition_results: for extra_transition in self._EXTRA_TRANSITIONS: # If the transition already exists, we skip if extra_transition in element_transition_results[element]: continue # Search for the possible transitions (i.e. expand the extra transition) try: possible_transitions = pyxray.element_xray_transitions( element, extra_transition) except pyxray.NotFound: continue # Find the results results = [ result for transition, result in element_transition_results[element].items() if transition in possible_transitions ] # If no results, do nothing if not results: continue # Add new entry try: xrayline = pyxray.xray_line(element, extra_transition) except pyxray.NotFound: continue newdata[xrayline] = self._sum_results(results) return newdata def build(self): data = self.data.copy() data.update(self._create_extra_transitions()) return self.result_class(self.analysis, data)
"""""" # Standard library modules. from operator import attrgetter # Third party modules. import pyxray # Local modules. import pymontecarlo.options.base as base # Globals and constants variables. KNOWN_XRAYTRANSITIONS = [ pyxray.xray_transition("Ka1"), pyxray.xray_transition("Kb1"), pyxray.xray_transition("La1"), pyxray.xray_transition("Lb1"), pyxray.xray_transition("Ll"), pyxray.xray_transition("Ma1"), pyxray.xray_transition("M4-N2"), # Mz ] def find_known_xray_lines(zs, minimum_energy_eV=0.0, maximum_energy_eV=float("inf")): xray_lines = [] for z in zs: for xraytransition in pyxray.element_xray_transitions(z):
(ATOMLINE_KA1, ATOMLINE_KA2, ATOMLINE_KB1, ATOMLINE_KB2, ATOMLINE_LA, ATOMLINE_LB1, ATOMLINE_LB2, ATOMLINE_LG, ATOMLINE_MA) import pyxray # Local modules. from pymontecarlo.options.program.importer import ImporterBase from pymontecarlo.options.analysis import PhotonIntensityAnalysis, KRatioAnalysis from pymontecarlo.results.photonintensity import EmittedPhotonIntensityResultBuilder from pymontecarlo_casino2.exporter import Casino2Exporter # Globals and constants variables. LINE_LOOKUP = { ATOMLINE_KA1: pyxray.xray_transition('Ka1'), ATOMLINE_KA2: pyxray.xray_transition('Ka2'), ATOMLINE_KB1: pyxray.xray_transition('Kb1'), ATOMLINE_KB2: pyxray.xray_transition('Kb3'), ATOMLINE_LA: pyxray.xray_transitionset('La'), ATOMLINE_LB1: pyxray.xray_transition('Lb1'), ATOMLINE_LB2: pyxray.xray_transition('Lb2'), ATOMLINE_LG: pyxray.xray_transition('Lg1'), ATOMLINE_MA: pyxray.xray_transitionset('Ma') } class Casino2Importer(ImporterBase): DEFAULT_CAS_FILENAME = os.path.splitext( Casino2Exporter.DEFAULT_SIM_FILENAME)[0] + '.cas'