1.0.2 ___ ___ ___________ _____
CC-BY-4.0 | \/ |/ ___| ___|_ _|
_ __ _ _| . . |\ `--.| |_ | |
| '_ \| | | | |\/| | `--. \ _| | |
| |_) | |_| | | | |/\__/ / | | |
| .__/ \__, \_| |_/\____/\_| \_/
| | __/ | python Multi-Slice
|_| |___/ Fourier-Transforms
pyMSFT is a python toolbox for accurately and efficiently simulating wide-angle coherent diffractive imaging. For details on the physics implemented in this code, please refer to the following publication: https://doi.org/10.1002/lpor.202502001
Installation
We strongly recommend setting up a virtual environment for the installation, i.e. using conda. This code has been tested for python 3.12.
conda create -n pymsft python=3.12
conda activate pymsft
At this point you can install the package using pip with different options:
- To install the basic package without GPU support and Mie scattering support, simply run:
pip install pyMSFT - To take advantage of GPU acceleration we are using CuPy. See the installation instructions for more details. The simplest way to install it is currently via conda:
Note that an NVIDIA GPU with the corresponding driver installed is required.conda install -c conda-forge cupy==13.6.0 - To calculate the Mie solutions for spherical particles you must also install corresponding Mie solver (we are using scattnlay). This can be installed with:
pip install pyMSFT[mie]
Usage
A simple example for a multislice simulation is shown below. Note that most of these examples require matplotlib for visualization to be installed.
import numpy as np
from pyMSFT.shapes import Spindle
from pyMSFT.simulation import PMSFTSimulation
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
wavelength = 13.5e-9 # wavelength of the light in meters
Rsphere = 200e-9 # radius of the sphere in meters
refIndex = 0.89 + 1j * 0.09 # complex refractive index of Silver at 13.5 nm (92 eV)
npix_fft = 256 # number of pixels in the FFT (should be a power of 2)
npix_real = 64 # number of pixels in the real space simulation box - this will be zero padded to num_pix_fft internally
# setup the geometry and simulation
geometry = Spindle(refractive_index=refIndex, npix=npix_real, x_rotation=45 * np.pi / 180, y_rotation=30 * np.pi / 180, z_rotation=0)
simulation = PMSFTSimulation(npix_fft=npix_fft, npix_real=npix_real, wavelength=wavelength, box_size=2 * Rsphere, verbose=True)
# run the simulation and get the diffraction image
diff_image, (QX, QY) = simulation.get_diffraction_image(geometry, output_axes=True)
# visualize the result
_, axs = plt.subplots(1, 1, figsize=(6, 4))
q_extent = QX[0, 0], QX[-1, 0], QY[0, 0], QY[0, -1]
barn = 10 ** -28 # barn unit in m^2
diff_image /= barn ** 2 # convert to barn^2
img = axs.imshow(diff_image, extent=q_extent, cmap='turbo', norm=LogNorm(vmin=1e24, vmax=1e28))
plt.colorbar(img)
axs.set_title(r'differential cross section on Ewald sphere in [b$^2$]')
axs.set_xlabel('QX [1/m]')
axs.set_ylabel('QY [1/m]')
axs.set_aspect('equal')
plt.show()
This will create a diffraction pattern of a silver spindle illuminated with 13.5 nm light and should look like this:
More examples can be found in the examples folder, e.g. for:
- Comparing different simulation methods with an exact Mie solution for spheres:
examples/compare_simulation_methods.py
And more are planned and coming soon, e.g. for:
- Visualizing the experimental setup regarding the internal orientations and axes:
examples/visualize_setup.py - Comparing the performance of CPU and GPU simulations:
examples/compare_cpu_gpu.py - Compare different detector geometries:
examples/compare_detectors.py - Showcase the different available sample shapes:
examples/showcase_shapes.py
Citation
If you use this code for your research, please cite it as:
P. Tuemmler, J. Apportin, T. Fennel, and C. Peltz, “Fast Simulation of Wide-Angle Coherent Diffractive Imaging.” Laser Photonics Rev (2025): e02001. https://doi.org/10.1002/lpor.202502001
Metadata
Release files for pyMSFT 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymsft-1.0.2.tar.gz | 30.6 kB | Without provenance | Details for pymsft-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymsft-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for pymsft-1.0.2-py3-none-any.whl |
Total release size: 61.7 kB
Release files / pymsft-1.0.2.tar.gz
| Download URL | pymsft-1.0.2.tar.gz |
|---|---|
| Size | 30.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29af430d10983f856866588c6eeb5859542cde024e329c076a30cfa284eb86a9
|
|
BLAKE2b-256 checksum How to use checksums |
9787ba6a417916c069187e7b7e1517d4c6ec77901e7d6dab8d3639120d9f4a16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.10
|
Release files / pymsft-1.0.2-py3-none-any.whl
| Download URL | pymsft-1.0.2-py3-none-any.whl |
|---|---|
| Size | 31.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a60ec904f5d217203b473b305c0a85f35398955981dc944ecd296ee1dfa36c3
|
|
BLAKE2b-256 checksum How to use checksums |
e7b30f3b2e3c5c347264d586e29eca42571b6ad0e4e5ff510075de12121292b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.10
|
Security for pyMSFT 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.