Skip to main content

python MultiSlice Fourier-Transform toolbox

Project description

  1.0.0      ___  ___ ___________ _____
  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 preprint: https://doi.org/10.48550/arXiv.2507.22483

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.

git clone https://gitlab.uni-rostock.de/snp/pymsft.git
cd pymsft
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 .
    
  • 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:
    conda install -c conda-forge cupy==13.6.0
    
    Note that an NVIDIA GPU with the corresponding driver installed is required.
  • 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 .[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, SAXSSimulation

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:

Diffraction pattern of a silver spindle

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: https://doi.org/10.48550/arXiv.2507.22483

Project details


Download files

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

Source Distribution

pymsft-1.0.0.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymsft-1.0.0-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file pymsft-1.0.0.tar.gz.

File metadata

  • Download URL: pymsft-1.0.0.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for pymsft-1.0.0.tar.gz
Algorithm Hash digest
SHA256 93f8e6b5cb3363c1852a4991c57bf37801aa8d37d7b3bcc685fd237dc7556668
MD5 56895a49225f57189059bf3075de4022
BLAKE2b-256 e2f06b9e03f3c020edf6cc0c9adb4c28bb98c8aaef9878dcdc1bed1c06d425eb

See more details on using hashes here.

File details

Details for the file pymsft-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pymsft-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for pymsft-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86980a00a26af991b588c86711bb7f487c85449a4ce8b19d2df7bdd5072b0ac9
MD5 dacc0fcf291c0325e68d039838b7c220
BLAKE2b-256 a1840337de9bda7ec1aedade2270b04a833753425c4db0962232b05d8b8f3042

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page