A Python package for calculating X-ray diffraction (XRD) and ultrafast electron diffraction (UED) signals from molecular geometries and trajectories using the Independent Atom Model (IAM) approximation.
Authors: Jiří Suchan and Jiří Janoš
- XRD calculations with optional inelastic Compton scattering
- UED calculations with pair distribution function (PDF) analysis
- Static and time-resolved diffraction simulations
- Ensemble averaging for multiple trajectories
- Difference calculations for pump-probe experiments
- Flexible input formats (single geometries, trajectories, ensembles)
IAM-XED is available on PyPI and can be installed simply using pip:
pip install iamxedTip
For installation into an isolated Python environment, we recommend using pipx or uv.
Local installation, mainly for development purposes, can be done by cloning the repository and installing it with pip:
git clone https://github.com/blevine37/IAM-XED.git
cd IAM-XED
pip install .Editable installation can be achieved with -e flag which allows you to modify the source code without reinstalling the package:
pip install -e .IAM-XED requires Python ≥ 3.7 and several packages: numpy, scipy, matplotlib, tqdm and pytest (for testing). Installation with pip will automatically handle these dependencies. If you want to install them manually, you can use the following command:
pip install numpy scipy matplotlib tqdm pytestRun the tests to ensure everything is working correctly by launching pytest in the root directory (IAM-XED) of the repository:
pytest -vThe independent atom model (IAM) is a widely used approximation in X-ray and electron diffraction calculations. It assumes that the scattering from a molecule can be approximated as the sum of the scattering from individual atoms, neglecting interatomic interactions. The total intensity of the scattering signal within IAM is given by
where
- In XRD, the momentum transfer is usually labelled
$q$ instead of$s$ in UED but the definition is the same. - In UED, AFFs are complex functions, while they are real-valued in XRD.
In XRD, inelastic Compton scattering can be included in the IAM calculations. The modified scattering intensity is given by
where
IAM-XED defines the real-space pair distribution function (PDF) as
where
As such,
The function above is implemented in IAM-XED for both UED and XRD calculations. The definition comes from:
Centurion, M., Wolf, T. J., & Yang, J. (2022). Ultrafast imaging of molecules with electron diffraction. Annual Review of Physical Chemistry, 73, 21-42.
Warning
Some sources define PDF as
which is mathematically more convenient to compute, or as
which describes the probability density corresponding to the atom pairs. The --pdf-mode flag allows choosing between rpdf (default, pdf (second definition, 1/rpdf (third definition,
IAM-XED is called in the command line with input specified in the form of flags. Three main specifications govern the type of calculation:
- XRD or UED calculation (
--xrdor--ued) - static or time-resolved calculation (
--signal-type staticor--signal-type time-resolved) - input geometries for calculating the signal in XYZ format and Angstrom units (
--signal-geoms <path>)
Important
Input geometries must be provided as a single XYZ file or a directory containing multiple XYZ files.
Simple examples of how to use IAM-XED for different types of calculations are shown below:
# Single molecule
iamxed --xrd --signal-type static --signal-geoms molecule.xyz
# Trajectory
iamxed --ued --signal-type time-resolved --signal-geoms traj.xyz
# Averaging over a set of trajectories in a directory
iamxed --xrd --signal-type time-resolved --signal-geoms ./dir_with_trajs/Two types of calculations are supported: static and time-resolved. While static calculations average over all geometries in the input file or directory, time-resolved calculations treat the input files as trajectories. Both modes are compatible with UED and XRD (possibly with inelastic Compton scattering). Details about the modes are summarized below.
Static calculations compute the average signal over all provided geometries. This is useful for obtaining a single diffraction pattern or PDF from a static structure or an ensemble of structures. If reference geometries are provided, the difference signal is calculated as a relative change from the reference signal.
Time-resolved calculations treat the input geometries as trajectories, computing the signal for each time frame along the trajectory. In time-resolved mode, only difference signals can be calculated, comparing the signal at each time frame to the first frame (t=0). This is useful for simulating pump-probe experiments or tracking changes in the structure over time. Currently, a reference other than the first frame cannot be specified, but this feature may be added in the future.
IAM-XED requires as an input signal geometries (used for calculating the signal) and optionally reference geometries (used for calculating a reference for the difference signal).
The input geometries can be provided in various formats: a single XYZ file or a directory containing multiple XYZ files.
If a directory is provided, IAM-XED searches for all files with .xyz extension within.
Important
The geometries must be in XYZ format with coordinates in Angstroms.
- Single XYZ file: Averages all geometries in the file and calculates the static signal.
- Directory of XYZ files: Averages over the first geometries from each XYZ file in the directory and calculates the static signal.
- Single XYZ file: Treats all geometries in the file as a trajectory with
--timestepintervals. - Directory of XYZ files: Each XYZ file represents a trajectory with
--timestepintervals. The signal is an average over all geometries in each time frame. Note that trajectories shorter than the longest trajectory or the specified maximum time--tmaxwill be padded with zeros, i.e., they contribute only up to the time they reached and don't contribute to the ensemble for longer times.
Reference geometries are used for calculating the difference signal in static calculations; the reference in time-resolved calculations is always the first time frame.
- Single XYZ file: Averages all geometries in the file and calculates the static signal.
- Directory of XYZ files: Averages over the first geometries from each XYZ file in the directory and calculates the static signal.
| Option | Description | Default |
|---|---|---|
--signal-type |
static or time-resolved
|
static |
--signal-geoms |
Path to single XYZ file or directory of XYZ files. | None (required parameter) |
--reference-geoms |
Path to reference XYZ file for difference signal (available only for static). |
None |
--ued |
Enable ultrafast electron diffraction calculation. | False (mutually exclusive with --xrd) |
--xrd |
Enable X-ray diffraction calculation. | False (mutually exclusive with --ued) |
--inelastic |
Include inelastic scattering (XRD only). | False |
--timestep |
Time step (atomic time units). | 10.0 |
--tmax |
Maximum time considered (fs). | None (up to the longest trajectory) |
--fwhm |
FWHM parameter for Gaussian temporal convolution (fs). | 150.0 |
--pdf-alpha |
PDF damping parameter (Ų). | 0.04 |
--pdf-mode |
Output mode for PDF transform: rpdf, pdf, or 1/rpdf. |
rpdf |
--qmin, --qmax
|
Momentum transfer range |
0.0, 5.292 |
--npoints |
Number of |
200 |
--log-to-file-disable |
Disable logging output to a file along with the console. | False |
--plot-disable |
Disable plotting of results. | False |
--export |
Export data by providing a filename. | None |
--plot-units |
bohr-1 or angstrom-1
|
bohr-1 |
--plot-flip |
Flip x and y axis in plots. | False |
--debug |
Enable debug output. | False |
More details on each option can be found in the help message (iamxed --help).
Momentum coordinate in plots and export is labelled
Single Geometry:
iamxed --xrd --signal-geoms molecule.xyzCalculates scattering intensity
Difference Signal from Single Geometry:
iamxed --xrd --signal-geoms excited.xyz --reference-geoms ground.xyzCalculates the relative difference signal:
Including Inelastic Scattering for XRD:
iamxed --xrd --signal-geoms molecule.xyz --inelasticIncludes Compton scattering using Szaloki parameters.
Time-resolved Single Trajectory Calculation:
iamxed --xrd --signal-geoms trajectory.xyz --signal-type time-resolved --qmin 0.0 --qmax 10.0 --npoints 100 --timestep 40 --pdf-alpha 0.04Calculates the time-resolved relative difference scattering signal
Time-resolved Ensemble Calculation:
iamxed --xrd --signal-geoms ./ensemble_dir/ --signal-type time-resolved --qmin 0.0 --qmax 10.0 --npoints 100 --timestep 40 --tmax 500 --pdf-alpha 0.04Calculates the same signal as in the trajectory case, averaging over all trajectories in the ./ensemble_dir/ folder up to 500 fs.
Momentum coordinate in plots and export is labelled
Single Geometry:
iamxed --ued --signal-geoms molecule.xyzCalculates the real-space pair distribution function. The default PDF format is --pdf-mode to select different output formats.
Difference Signal from Single Trajectory:
iamxed --ued --signal-geoms excited.xyz --reference-geoms ground.xyzCalculates the relative difference signal:
Time-Resolved Single Trajectory Calculation:
iamxed --ued --signal-type time-resolved --signal-geoms trajectory.xyz --timestep 40 --fwhm 100 --pdf-alpha 0.04Calculates time-resolved relative difference signal
Time-resolved Ensemble Calculation:
iamxed --ued --signal-type time-resolved --signal-geoms ./ensemble_dir/ --timestep 40 --fwhm 100 --pdf-alpha 0.04Calculates the same signal as in the trajectory case, averaging over all trajectories in the ./ensemble_dir/ folder.
export.txt: Signal data with units in headerexport_rPDF.txt,export_PDF.txt, orexport_1_rPDF.txt: PDF data (available for both UED and XRD), filename depends on--pdf-modesetting
export.npz: Binary archive containing:times,times_smooth: Time axis (fs), smooth refers to convoluted dataq/s: Momentum transfer axis (Bohr⁻¹)signal_raw,signal_smooth: Diffraction signals, smooth refers to convoluted datar,pdf_raw,pdf_smooth: rPDF data (UED only), smooth refers to convoluted datametadata: Command and units information
The binary archive can be loaded in Python using NumPy:
# Load time-resolved data
import numpy as np
data = np.load('results.npz')
metadata = data['metadata'] # Command and units
times = data['times'] # Time points (fs)
signal = data['signal_raw'] # Raw signalsrc/iamxed/
├── iamxed.py # Main entry point and CLI
├── physics.py # Calculator classes (XRD/UED)
├── io_utils.py # File I/O and argument parsing
├── plotting.py # Visualization functions
├── XSF/ # X-ray scattering form factors
└── ESF/ # Electron scattering form factors
You can use IAM-XED as a library in your Python scripts. The input is provided instead of a list of flags in the command line as an argparse.Namespace object, which can be created from a dictionary of parameters. Note that the list of arguments must contain all the parameters; no defaults will be assumed! The main function to call is then iamxed(params). An example of how to use IAM-XED as a library is shown below:
from iamxed import iamxed
from argparse import Namespace
params = {
"signal_geoms": "./ensemble/",
"reference_geoms": None,
"signal_type": "time-resolved",
"ued": True,
"xrd": False,
"inelastic": False,
"qmin": 0,
"qmax": 4,
"npoints": 200,
"timestep": 20.0,
"fwhm": 120.0,
"pdf_alpha": 0.04,
"pdf_mode": "rpdf",
"tmax": False,
"export": "ued_ensemble",
"log_to_file_disable": False,
"plot_disable": True,
"plot_flip": False,
"plot_units": "bohr-1",
"debug": True
}
params = Namespace(**params)
iamxed(params)MIT License - see LICENSE file for details.
If you use IAM-XED in your research, please cite:
@software{iam_xed,
author = {Suchan, Jiří and Janoš, Jiří},
title = {IAM-XED: Independent Atom Model for X-ray and Electron Diffraction},
month = oct,
year = 2025,
publisher = {Zenodo},
version = {v1.1.0},
doi = {10.5281/zenodo.17350829},
url = {https://doi.org/10.5281/zenodo.17350829},
}The IAM parameters for XRD reference:
Prince, E. (Ed.). (2004). International Tables for Crystallography, Volume C: Mathematical, physical and chemical tables. Springer Science & Business Media. ISBN 1-4020-1900-9
The IAM parameters for UED were calculated using the ELSEPA program (commit 98862ff) assuming 3.7 MeV electron kinetic energy:
Salvat, F., Jablonski, A., & Powell, C. J. (2005). ELSEPA—Dirac partial-wave calculation of elastic scattering of electrons and positrons by atoms, positive ions and molecules. Computer physics communications, 165(2), 157-190.
The inelastic contribution parameters for the XRD reference:
Szalóki, I. (1996). Empirical equations for atomic form factor and incoherent scattering functions. X‐Ray Spectrometry, 25(1), 21-28.