### Build and Install XMI-MSIM Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions Commands to compile the XMI-MSIM code after configuration and then install it. Avoids using '-j' with make to prevent potential Fortran compiler issues. ```bash make make install ``` -------------------------------- ### Configure XMI-MSIM Build Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions Configures the XMI-MSIM source tree to examine host system capabilities. Includes options for specifying installation prefix and Fortran compiler. ```bash ./configure ./configure --help ./configure --prefix=/path/to/install export FC=gfortran-9 ``` -------------------------------- ### Install XMI-MSIM with Homebrew Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions This command installs the XMI-MSIM package using the Homebrew package manager on macOS. It assumes you have Homebrew installed and configured. ```bash brew install tschoonj/tap/xmi-msim ``` -------------------------------- ### Install XRMC with XMI-MSIM Support via Homebrew Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions This command installs the XRMC package with XMI-MSIM support using Homebrew. XMI-MSIM will be installed as a dependency if not already present. ```bash brew install tschoonj/tap/xrmc --with-xmi-msim ``` -------------------------------- ### Generate XMI-MSIM Precompiled Dataset Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions Executes the 'xmimsim-db' utility to create the 'xmimsimdata.h5' file, which contains precomputed physical data necessary for running simulations. This process can be time-consuming. ```bash xmimsim-db ``` -------------------------------- ### Unpack and Navigate XMI-MSIM Source Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions Commands to extract the XMI-MSIM source code tarball and change into the newly created directory. Assumes the tarball is named 'xmimsim-x.y.tar.gz'. ```bash tar xvfz xmimsim-x.y.tar.gz cd xmimsim-x.y ``` -------------------------------- ### XMI-MSIM: Load from Catalog Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Describes how to load predefined compounds or layers from the XMI-MSIM catalog. The catalog includes NIST-provided compounds and user-defined layers, facilitating quick setup of common materials and configurations. ```XMI-MSIM Load from catalog - NIST Compound Catalog (GetCompoundDataNISTList) - User-defined layers ``` -------------------------------- ### Launch XMI-MSIM via Command Line Source: https://github.com/tschoonj/xmimsim/wiki/User-guide This command is used to launch the XMI-MSIM graphical user interface from the terminal on Linux systems. Ensure XMI-MSIM is installed and accessible in your system's PATH. ```Shell xmimsim-gui ``` -------------------------------- ### Set PKG_CONFIG_PATH for Dependencies Source: https://github.com/tschoonj/xmimsim/wiki/Installation-instructions Sets the PKG_CONFIG_PATH environment variable to help the configure script find packages installed in non-default locations, such as '/usr/local/lib/pkgconfig'. ```bash export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ``` -------------------------------- ### Python Custom Source for XmiMsim Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Example of a custom data source implemented in Python for XmiMsim. This class extends XmiMsimGui.SourceAbstract and implements methods to define the source's name, about text, and generate spectral data. ```Python from gi.repository import XmiMsimGui, XmiMsim, Gtk, GLib import sys import numpy as np class TestSource(XmiMsimGui.SourceAbstract): # Optional, will not affect GUI in any way if left out... __gtype_name__ = "TestSourcePython" # initialize parent first, and add GUI elements def __init__(self): XmiMsimGui.SourceAbstract.__init__(self) print("Calling __init__") button = Gtk.Button.new_with_label("Click me!") self.add(button) self.counter = 1000 # source name: this will end up in the tab label def do_get_source_name(self): return "Python Source" # the about text: will be shown in the Source About Dialog def do_get_about_text(self): return "This could very well be some clever text about this source" # this method is executed whenever "Update Spectrum" is clicked def do_generate(self): print("Calling do_generate") # if something goes wrong: initialize a new GLib.Error instance and send it along with the after-generate signal # error = GLib.Error.new_literal(XmiMsimGui.SourceAbstractError.quark(), "Error message from Python!", XmiMsimGui.SourceAbstractError.INVALID_FILENAME) # self.emit("after-generate", error) # return x = np.linspace(1.0, 50.0, num=2000, dtype=np.double) y = self.counter * np.exp(-1.0 * (x - 20.0) * (x - 20.0) / 2.0) / np.sqrt(2.0 * np.pi) y[y < 1.0] = 1.0 self.counter += 100 excitation = XmiMsim.Excitation.new(discrete=[XmiMsim.EnergyDiscrete.new(20.0, 1E9, 1E9, 0.0, 0.0, 0.0, 0.0, XmiMsim.EnergyDiscreteDistribution.MONOCHROMATIC, 0.0)]) # this updates the source internal data: raw, plot_x, and plot_y self.set_data(excitation, x.tolist(), y.tolist()) # afterwards emit after-generate with None argument to update the plot window self.emit("after-generate", None) ``` -------------------------------- ### Importing Excitation Data from ASCII Source: https://github.com/tschoonj/xmimsim/wiki/User-guide This functionality allows importing excitation spectrum data (discrete lines or continuous energy intensity densities) from ASCII files. The files can have varying column structures to define energies, intensities (total, horizontal, vertical), and source parameters. Users can specify the starting line number and the number of lines to read. ```text ASCII file format: - Two columns: Energy, Total Intensity - Three columns: Energy, Horizontally Polarized Intensity, Vertically Polarized Intensity - Seven columns: Energy, Total Intensity, Horizontally Polarized Intensity, Vertically Polarized Intensity, Source Size X, Source Size Y, Source Divergence X, Source Divergence Y (Note: The description mentions 7 columns but lists 8 parameters. Assuming the last 4 are source size x/y and divergence x/y) Import options: - Start reading at a certain line number - Read only a set number of lines ``` -------------------------------- ### XMI-MSIM: Layer Ordering Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Explains the importance of layer ordering in XMI-MSIM, where layers must be arranged from closest to furthest from the X-ray source. Users can reorder layers using 'Top', 'Up', 'Down', and 'Bottom' buttons to ensure correct simulation setup. ```XMI-MSIM Layer Management: - Select Layer - Move Layer (Top, Up, Down, Bottom) ``` -------------------------------- ### XMI-MSIM GUI Source: https://github.com/tschoonj/xmimsim/wiki/User-guide The `xmimsim-gui` executable launches the graphical user interface for XMI-MSIM. This is particularly useful for Linux or Mac OS X users who have compiled from source without `gtk-mac-integration` support. ```bash xmimsim-gui ``` -------------------------------- ### Run XMI-MSIM Simulation Source: https://github.com/tschoonj/xmimsim/wiki/User-guide The `xmimsim` executable performs the core simulation tasks. It can be controlled via command-line arguments, with detailed options available by running `xmimsim --help`. For Windows users, `xmimsim-cli.exe` is recommended to avoid console pop-ups. ```bash xmimsim --help ``` ```bash xmimsim-cli.exe --help ``` -------------------------------- ### Python XMI-MSIM Batch Simulation Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This Python script demonstrates how to use the XMI-MSIM API to set up and run a batch simulation. It varies the atomic number across the periodic table, saves the results to an XMSA archive, and opens it in the XmiMsimGui. ```Python import xraylib as xrl import sys import os import math import logging logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) import gi gi.require_version('XmiMsim', '1.0') gi.require_version('XmiMsimGui', '1.0') from gi.repository import XmiMsim, XmiMsimGui, GLib, Gio, Gtk OUTPUTFILE = 'mendeljev.xmsa' XmiMsim.xmlLoadCatalog() main_loop = GLib.MainLoop.new(None, False) input = XmiMsim.Input.init_empty() general = input.general.copy() general.n_photons_line = 100000 # 1M photons input.set_general(general) options = XmiMsim.MainOptions.new() single_data = [XmiMsim.BatchSingleData.new("/xmimsim/composition/layer[1]/element[1]/atomic_number", 1, 92, 91)] xmsi_data = list() for Z in range(1, 93): input_copy = input.copy() layer = XmiMsim.Layer.new([Z], [1.0], 1.0, 1.0) composition = XmiMsim.Composition.new([layer], reference_layer=1) input_copy.set_composition(composition) xmsi_data.append(input_copy) batch = XmiMsim.BatchSingle.new(xmsi_data, single_data, options) assert batch.is_valid_object() == True def _test_succeed_finished_cb(batch, result, buffer): logging.debug("message: {}".format(buffer)) assert result == True main_loop.quit() def _print_stdout(batch, string): logging.debug("stdout: {}".format(string)) def _print_stderr(batch, string): logging.debug("stderr: {}".format(string)) batch.connect('finished-event', _test_succeed_finished_cb) batch.connect('stdout-event', _print_stdout) batch.connect('stderr-event', _print_stderr) batch.start() main_loop.run() assert batch.was_successful() == True batch.write_archive(OUTPUTFILE) XmiMsimGui.init() archive = batch.props.archive win = XmiMsimGui.XmsaViewerWindow.new(archive) win.set_position(Gtk.WindowPosition.CENTER) win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main() ``` -------------------------------- ### Compiling Fortran Modules on macOS Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage These commands demonstrate how to compile Fortran source files into object files and then link them into a dynamically loadable module for XMI-MSIM on macOS. ```Shell gfortran-9 -I/Applications/XMI-MSIM.app/Contents/Resources/include/xmimsim -fopenmp -ffree-line-length-none -c -fno-common -o object1.o source1.f90 gfortran-9 -fopenmp -Wl,-undefined -Wl,dynamic_lookup -o module.so -bundle object1.o object2.o ... ``` -------------------------------- ### Open XMI-MSIM Simulation File from Command Line Source: https://github.com/tschoonj/xmimsim/wiki/User-guide This command allows users to open XMI-MSIM simulation output files (XMSO) directly from the command line on Linux and Windows systems. It is a convenient way to load and visualize previously generated results. ```Shell xmimsim-gui file.xmso ``` -------------------------------- ### XMI-MSIM PyMca Plugin Source: https://github.com/tschoonj/xmimsim/wiki/User-guide The `xmimsim-pymca` utility serves as the quantification plug-in utilized by PyMca, integrating XMI-MSIM's capabilities within the PyMca environment. ```python xmimsim-pymca ``` -------------------------------- ### Compile C Program with XMI-MSIM on Linux/Mac Source: https://github.com/tschoonj/xmimsim/wiki/The-XMI-MSIM-API-list-of-functions This command compiles a C program (myprogram.c) and links it with the XMI-MSIM library using pkg-config for flag retrieval. It ensures the necessary headers are included and the library is linked correctly for execution. ```Shell gcc $(pkg-config --cflags libxmimsim) myprogram.c $(pkg-config --libs libxmimsim) ``` -------------------------------- ### Link Fortran Objects to Module on Windows Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Links compiled Fortran object files to create a dynamic link library (.dll) for XMI-MSIM on Windows. Enables OpenMP and specifies library paths and dependencies. ```bash gfortran -shared -fopenmp -Wl,--enable-auto-image-base -o module.dll object1.o object2.o ... -L"xmi_msim\SDK\Lib" -lxmimsim ``` -------------------------------- ### Link C Objects to Module on Linux Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Links compiled C object files to create a shared module (.so) for XMI-MSIM on Linux. Enables OpenMP and specifies shared library properties. ```bash gcc -fopenmp -shared -fPIC -Wl,-soname -Wl,module.so -o module.so object1.o object2.o ``` -------------------------------- ### Link Fortran Objects to Module on Linux Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Links compiled Fortran object files to create a shared module (.so) for XMI-MSIM on Linux. Enables OpenMP and specifies shared library properties. ```bash gfortran -fopenmp -shared -fPIC -Wl,-soname -Wl,module.so -o module.so object1.o object2.o ... ``` -------------------------------- ### Link C Objects to Module on Windows Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Links compiled C object files to create a dynamic link library (.dll) for XMI-MSIM on Windows using MinGW-w64. Enables OpenMP and specifies library paths and dependencies. ```bash gcc -mms-bitfields -shared -fopenmp -Wl,--enable-auto-image-base -o module.dll object1.o object2.o ... -L"xmi_msim\SDK\Lib" -lxmimsim ``` -------------------------------- ### XMI-MSIM: Add to Catalog Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Details the process of adding a currently defined layer (composition, density, thickness) to the XMI-MSIM user-defined catalog. This allows for easy reuse of custom layer configurations in future projects. Existing catalog entries will be overwritten. ```XMI-MSIM Add to catalog - Choose a name for the layer - Overwrites existing entries ``` -------------------------------- ### XMI-MSIM File Conversion Utilities Source: https://github.com/tschoonj/xmimsim/wiki/User-guide A set of utilities are provided for converting XMI-MSIM files between various formats. These include converting XMSO files to XMSI, SPE, CSV, and HTML, as well as extracting XMSO files from XMSA files and converting XMSI to XRMC input files. ```bash xmso2xmsi ``` ```bash xmso2spe ``` ```bash xmso2csv ``` ```bash xmso2htm ``` ```bash xmsa2xmso ``` ```bash xmsi2xrmc ``` -------------------------------- ### XMI-MSIM Source Plugin Configuration Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This snippet shows the required INI file format for configuring a Python source plugin in XMI-MSIM. It specifies the Python module to load, the plugin's display name, and the loader to use. ```INI [Plugin] Module=test-source Name=Test source Loader=python3 ``` -------------------------------- ### Compile Fortran Source on Windows Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Compiles a Fortran source file into an object file for XMI-MSIM module building on Windows. Includes DLL export flags and specifies include paths. ```bash gfortran -I"xmi_msim\SDK\Include" -fopenmp -ffree-line-length-none -DDLL_EXPORT -c -o object1.o source1.f90 ``` -------------------------------- ### Link C Objects to Module on macOS Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Links compiled C object files together to create a dynamic module (.so) for XMI-MSIM on macOS. Handles dynamic lookup for undefined symbols. ```bash clang -Wl,-undefined -Wl,dynamic_lookup -o module.so -bundle object1.o object2.o ... ``` -------------------------------- ### Generate XRMC Input Files via Command Line Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This snippet describes how to generate input files for the XRMC simulation tool using the command-line utility 'xmsi2xrmc'. XRMC is a Monte Carlo simulation tool for X-ray imaging and spectroscopy experiments. ```CLI xmsi2xrmc ``` -------------------------------- ### XMI-MSIM: Add Layer with Multiple Compounds Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Illustrates adding a second compound (e.g., U3O8) to an existing layer in XMI-MSIM, ensuring the total weight fraction sums to 100%. This process involves defining the compound, its weight fraction, and potentially adjusting density and thickness. ```XMI-MSIM Add Layer Compound: U3O8 Weight Fraction: 50 % Density: 2.5 g/cm3 Thickness: 1 cm (Total Weight Fraction: 100 %) ``` -------------------------------- ### Compile C Source on Windows Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Compiles a C source file into an object file for XMI-MSIM module building on Windows using MinGW-w64. Includes DLL export flags and specifies include paths. ```bash gcc -mms-bitfields -I"xmi_msim\SDK\Include" -fopenmp -DDLL_EXPORT -c -o object1.o source1.c ``` -------------------------------- ### Generate XMI-MSIM Data File Source: https://github.com/tschoonj/xmimsim/wiki/User-guide The `xmimsim-db` utility is used to create the `xmimsimdata.h5` file, which stores physical data tables essential for speeding up simulations. This tool is primarily intended for users compiling XMI-MSIM from source. ```bash xmimsim-db ``` -------------------------------- ### Compile C Source on macOS Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Compiles a C source file into an object file for XMI-MSIM module building on macOS. Requires the XMI-MSIM include directory. ```bash clang -I/Applications/XMI-MSIM.app/Contents/Resources/include/xmimsim -c -fno-common -o object1.o source1.c ``` -------------------------------- ### Compile Fortran Source on Linux Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Compiles a Fortran source file into a position-independent object file for XMI-MSIM module building on Linux. Uses pkg-config for compiler flags and enables OpenMP. ```bash gfortran `pkg-config --cflags libxmimsim` -fopenmp -ffree-line-length-none -c -fPIC -o object1.o source1.f90 ``` -------------------------------- ### Compile C Source on Linux Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Compiles a C source file into a position-independent object file for XMI-MSIM module building on Linux. Uses pkg-config for compiler flags. ```bash gcc `pkg-config --cflags libxmimsim` -c -fPIC -DPIC -o object1.o source1.c ``` -------------------------------- ### XMI-MSIM: Add Layer with Compound Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Demonstrates adding a new layer to the XMI-MSIM system composition. This involves defining a compound (e.g., CuSO4) and its weight fraction, along with layer density and thickness. The interface uses xraylib's CompoundParser for formula validation. ```XMI-MSIM Add Layer Compound: CuSO4 Weight Fraction: 50 % Density: 2.5 g/cm3 Thickness: 1 cm ``` -------------------------------- ### Fortran Detector Response Function Prototype Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This is the Fortran prototype for the custom detector response function, designed to be compatible with C linkage. It specifies the arguments and their types for the subroutine. ```Fortran INTERFACE SUBROUTINE xmi_detector_convolute_all_custom( inputFPtr, channels_noconvPtr, channels_convPtr, brute_historyPtr, var_red_historyPtr, options, escape_ratiosCPtr, n_interactions_all, zero_inter) BIND(C,NAME='xmi_detector_convolute_all') IMPLICIT NONE TYPE (C_PTR), INTENT(IN), VALUE :: inputFPtr TYPE (C_PTR), INTENT(IN), VALUE :: channels_noconvPtr TYPE (C_PTR), INTENT(IN), VALUE :: channels_convPtr TYPE (C_PTR), INTENT(IN), VALUE :: var_red_historyPtr TYPE (C_PTR), INTENT(IN), VALUE :: brute_historyPtr TYPE (xmi_escape_ratiosC), INTENT(IN) :: escape_ratiosCPtr TYPE (xmi_main_options), VALUE, INTENT(IN) :: options INTEGER (C_INT), VALUE, INTENT(IN) :: n_interactions_all, zero_inter ENDSUBROUTINE ENDINTERFACE ``` -------------------------------- ### Include XMI-MSIM Header Source: https://github.com/tschoonj/xmimsim/wiki/The-XMI-MSIM-API-list-of-functions This C preprocessor directive includes the main header file for the XMI-MSIM library. This is necessary to access the exported functions and data structures provided by XMI-MSIM. ```C #include ``` -------------------------------- ### Fortran DLLEXPORT Directive Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage Fortran directives to export functions from a DLL, compatible with both gfortran and Intel Fortran compilers. ```fortran #ifdef __GFORTRAN__ !GCC$ ATTRIBUTES DLLEXPORT:: xmi_detector_convolute_all_custom #elif defined(__INTEL_COMPILER) !DEC$ ATTRIBUTES DLLEXPORT:: xmi_detector_convolute_all_custom #endif? ``` -------------------------------- ### Convert XMSO Spectra Source: https://github.com/tschoonj/xmimsim/wiki/User-guide The `xmimsim-conv` executable allows for the extraction of unconvoluted spectra from XMSO files. It also enables the application of detector response functions with different settings than those used during initial file generation. ```bash xmimsim-conv ``` -------------------------------- ### Generate X-ray Tube Spectrum (XMI-MSIM) Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This snippet describes the process of generating an X-ray tube spectrum using XMI-MSIM, based on Horst Ebel's model. It involves setting parameters like tube voltage, current, anode material, and filtration to simulate the excitation spectrum. ```Documentation The XMI-MSIM implementation of the Ebel model for X-ray tube spectra involves adjusting parameters such as: - Tube voltage (kV) - Tube current (mA) - Tube solid angle (sr) - Electron incidence angle - X-ray tube take-off angle - Interval width for Bremsstrahlung - Anode material and thickness - Window and Filter materials and thickness - Transmission tube activation - Transmission efficiency file (ASCII format) ``` -------------------------------- ### C Function to Extract Input Data Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This C function is used to convert the Fortran input data type to a C-compatible structure. It facilitates accessing simulation data within C plug-ins. ```C void xmi_input_F2C(xmi_inputFPtr Ptr, struct xmi_input **xmi_inputC); ``` -------------------------------- ### C Detector Response Function Prototype Source: https://github.com/tschoonj/xmimsim/wiki/Advanced-usage This is the C prototype for the custom detector response function that XMI-MSIM will call. It defines the parameters required for custom convolution operations. ```C void xmi_detector_convolute_all_custom(xmi_inputFPtr inputFPtr, double **channels_noconv, double **channels_conv, double *brute_history, double *var_red_history, xmi_main_options, xmi_escape_ratios *escape_ratios, int n_interactions_all, int zero_interaction); ``` -------------------------------- ### XMI-MSIM: Add Atmospheric Layer Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Shows how to add an atmospheric layer to the XMI-MSIM system. This is crucial for accurate simulations as the atmosphere affects beam attenuation and scattering. The layer can be defined manually or loaded from the NIST catalog (e.g., 'Air, Dry (near sea level)'). ```XMI-MSIM Add Layer Composition: Air, Dry (near sea level) Density: [Value] Thickness: [Value] ``` -------------------------------- ### XMI-MSIM: Compound Parsing Validation Source: https://github.com/tschoonj/xmimsim/wiki/User-guide Highlights how XMI-MSIM validates chemical formulas using xraylib's CompoundParser. Invalid formulas result in the 'Ok' button being disabled and the compound text box turning red, preventing incorrect layer definitions. ```XMI-MSIM Compound Validation: - Uses xraylib's CompoundParser - Accepts nested brackets (e.g., Ca10(PO4)3OH) - Invalid formulas: 'Ok' button greyed out, red text box ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.