Skip to main content

Toolkit for making and processing X-ray fluoresence simulations via XMI-MSIM

Project description


XMIMSIM (the python package) is a front-end to XMI-MSIM, XRF open-source simulation software, for running in python.



On mac, acquire XMIMSIM through homebrew. To install do not use the brewsci/science tap

brew tap tschoonj/tap
brew cask install tschoonj/tap/xmi-msim


Follow the instructions here.


Install the python utility with

pip install xmimsim

Getting started

The examples folder contains the following example:

import xmimsim as xmi    

There is only one class currently in xmimsim, so one could just as easily use from xmimsim import model.

From there, the parameters can be defined as a dictionary:

parameters = {'n_photons_interval' : 1,'n_photons_line' : 100000,'n_interactions_trajectory' : 1,
       'reference_layer' : 2,'d_sample_source' : 100,'area_detector' : 0.5,
       'collimator_height' : 0,'collimator_diameter' : 0,'d_source_slit' : 100,
       'slit_size_x' : 0.001,'slit_size_y' : 0.001,'detector_type' : 'SiLi',
       'detector_live_time' : 1500,'detector_pulse_width' : 1e-05,'detector_nchannels' : 2048,
       'detector_gain' : 0.0182138,'detector_zero' : 0,'detector_fano' : 0.12,'detector_noise' : 0.1}

to be injected into the code. The model is initialized with:

xm = xmi.model()

from there the model, xm, can be added to, e.g.:

    energy = 13.5,
    horizontal_intensity = '1e+012',
    vertical_intensity = '1e+009',

All these classes return self, so one can actually do this all with one line, i.e. xm.set_parameters(**parameters).add_source(....)

The beampath layers are added:

xm.add_excitation_path_layer(atomic_numbers=[4], masses=[100], density=1.85, thickness=0.02)
xm.add_detector_path_layer(atomic_numbers=[4], masses=[100], density=1.85, thickness=0.0025)
xm.add_crystal_layer(atomic_numbers=[14], masses=[100], density=2.33, thickness=0.35)

Which behave like regular analyte layers:


Orientations are defined:


The filename is defined for this, although this is not strictly necessary:


And the calculation is run, discarding the massive xmso in favor of the csv file (default):

xm.calculate(M_lines=False, auger_cascade=True,radiative_cascade=False)

We can print out the number of photons from each of the following bands.


xm.get_spectrum() also returns a plottable spectrum from the xmi file.

If you simply copy the blocks of code together into one file and run it it should give you an output.



  • Initial Release


  • Fixed windows command, but it requires some changing of environment variables to make it run.
  • Fixed some header issues with the readme
  • Cleaned up file


  • Fixing the windows problem broke *nix versions. Fixed.


  • Added default of no collimator or detector offset
  • Fixed a minor bug in the code (should not change any answers) with element arrays normalizations


  • Fixed Readme document type so PyPI handles it correctly


  • Allowed larger numbers of interaction counts (greater than 1) in get_spectrum() method


Thanks to Tom Schoonjans for creating XMI-MSIM. Special thanks to the vapory package, which some of the inspiration for this code comes from (also a python interface for a third-party utility).

Report problems to my gmail: nsgeorgescu

NGeorgescu :

Github :

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xmimsim, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size xmimsim-0.1.3-py3-none-any.whl (12.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size xmimsim-0.1.3.tar.gz (13.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page