Skip to main content

pyFaSTMM

Python bindings for FaSTMM2 (Fast Superposition T-Matrix Method), a Multi-Level Fast Multipole Method (MLFMM) accelerated solver for electromagnetic scattering from clusters of spheres.

Geometry goes in and Mueller/Jones/cross-section/T-matrix data comes out as plain NumPy arrays -- no input/output files required (unlike the upstream CLI, which reads/writes HDF5).

Installation

pip install pyfastmm
pip install "pyfastmm[dask]"   # optional: distributed wavelength sweeps

Binary wheels are published for Linux x86_64 (CPython 3.11-3.14). On other platforms pip builds from the sdist, which needs a Fortran compiler (gfortran), LAPACK/BLAS and pkg-config (e.g. on Debian/Ubuntu: apt install gfortran liblapack-dev libblas-dev pkg-config).

Quick start

from pyfastmm import FaSTMM

coords = [[-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]]  # sphere centres (um)
radii = [1.0, 1.0]                            # sphere radii (um)

cluster = FaSTMM(
    coords,
    radii,
    refractive_index=1.6 + 0.01j,          # particles, vacuum-referenced
    medium_refractive_index=1.33 + 0.0j,   # host medium (default: vacuum)
)
result = cluster.solve(
    wavelength_vacuum=0.55,  # same length unit as coords/radii
    N_theta=181,
    N_phi=32,
    n_threads=4,             # OpenMP threads for this solve (default 1)
)
print(result["c_ext"], result["c_abs"], result["c_sca"], result["asymmetry"])
print(result["mueller"].shape)   # (N_theta*N_phi, 18): phi, theta, P11..P44

Notes:

  • Cross sections in a host medium are physical by default: power per unit incident irradiance in the host. A single sphere equals Mie theory with the relative index m / n_host and the size parameter in the host. Pass cross_section_convention="mstm" to get MSTM's medium-mode values instead (normalised by the vacuum irradiance, i.e. Re(n_host) times larger). Both agree in vacuum.
  • n_threads defaults to 1 (pyfastmm 1.0.0 used all OpenMP cores). It accepts a positive count, a negative offset from os.cpu_count() (-2 leaves two CPUs free) or a float fraction (0.5). The solve releases the GIL, so independent solves can also run in Python threads.
  • Truncation: truncation_formula=0 (default, floor(ka + 3 ka^(1/3)), at least 6) or 1 (a more conservative formula, useful for touching small spheres); truncation_order=N sets an explicit per-sphere order and overrides the formula.
  • incident_polar_deg/incident_azimuthal_deg tilt the incident beam (emulated by rotating the cluster); N_ave > 0 averages over orientations; cluster.compute_tmatrix(...) returns the cluster T-matrix.

The low-level FaSTMM2 class takes permittivities (eps = m**2) and a (complex) wavenumber directly; see its docstrings.

Wavelength sweeps from TOML

# sweep.toml
[particles]
positions_file = "cluster.dat"   # columns x y z r (PyFracVAL format works)
scale = 1e-9
refractive_index = [1.5, 0.01]   # or refractive_index_file = "nk.txt"

[medium]
refractive_index = [1.33, 0.0]

[wavelengths]
start = 0.4
stop = 0.8
num = 21
scale = 1e-6

[solver]
N_theta = 181
N_phi = 32
n_threads = 1
sweep_threads = 4                       # wavelengths solved concurrently
truncation_formula = 0                  # or truncation_order = 12
cross_section_convention = "physical"   # or "mstm"
from pyfastmm import load_config

cfg = load_config("sweep.toml")
results = cfg.run(base_dir=".")   # one dict per wavelength
# Distributed over Dask (needs pyfastmm[dask]):
results = cfg.run_dask(base_dir=".", scheduler_address="tcp://127.0.0.1:8786")

Scope

Spherical (Lorenz-Mie) monomers only -- not the precomputed per-monomer-T-matrix ("arbitrarily-shaped constituent particles") input the upstream CLI also supports. The bundled FaSTMM2 sources carry a few patches (src/pyfastmm/_fortran/patches/), among them fixes for the far field in absorbing host media and for the solver conditioning of touching spheres at small size parameters; see CHANGELOG.md.

Development

git clone --recurse-submodules https://github.com/arunoruto/pyFaSTMM.git
cd pyFaSTMM
uv sync --extra dev   # builds the extension (needs gfortran, LAPACK/BLAS, pkg-config)
make cli              # optional: upstream CLI, for tests/test_compatibility.py (needs cmake, HDF5)
uv run pytest tests/

devenv shell (see devenv.nix) provides all build dependencies.

Citation

If you use pyFaSTMM, please cite the FaSTMM2 papers:

  • J. Markkanen and A. J. Yuffa, "Fast superposition T-matrix solution for clusters with arbitrarily-shaped constituent particles", JQSRT 189, 181-188 (2017), doi:10.1016/j.jqsrt.2016.11.004
  • J. Markkanen, "Surface-integral-equation solution for solid particles with wavelength-scale surface roughness", JQSRT 341, 109467 (2025), doi:10.1016/j.jqsrt.2025.109467

and pyFaSTMM itself (see CITATION.cff).

License

pyFaSTMM is MIT licensed. The bundled FaSTMM2 Fortran code keeps its own licences (BSD-3-Clause, MIT, and the Zhang & Jin notice), and the wheels bundle LAPACK/BLAS and the GCC runtime; see LICENSE and LICENSES/.

Metadata

Release files for pyfastmm 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfastmm 1.1.0
File Size Uploaded Provenance Actions
pyfastmm-1.1.0.tar.gz 216.4 kB With provenance Details for pyfastmm-1.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyfastmm 1.1.0
File Actions
pyfastmm-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for pyfastmm-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
pyfastmm-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for pyfastmm-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
pyfastmm-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for pyfastmm-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
pyfastmm-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for pyfastmm-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Total release size: 20.4 MB

Release files / pyfastmm-1.1.0.tar.gz

Download URL pyfastmm-1.1.0.tar.gz
Size 216.4 kB
Tags Source
SHA-256 checksum
How to use checksums
010bf7e19ce1d4426304d237fa7eecc648dfff3e408d13a4b5098744bbbfe51f
BLAKE2b-256 checksum
How to use checksums
c5cdac46a717a123202a78ebda9cc6f9bf9a1b34445e6c0ab6124ee3e1c4841d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pyfastmm-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyfastmm-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.0 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
51407db87697af0255b638d2b6b58511533d3d36c7a49641675b0a86a5d492d1
BLAKE2b-256 checksum
How to use checksums
e0ab501142c93e5ed8e1f46a4209b08c5abf87a833d41c86f6a16f0f46a72209
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pyfastmm-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyfastmm-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.0 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
db106987f959d94c3c546cf95b77ef9c557f11159b292e26d7cb7f8dcc698c0f
BLAKE2b-256 checksum
How to use checksums
93ebb497771e31499ed652741dcda024ea90785b6e38c648ddcf928c4595b089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pyfastmm-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyfastmm-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.0 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c91125825288d4d0b377fec76f9dc236bb0278fb111fc3db5ebcd71216a75b5f
BLAKE2b-256 checksum
How to use checksums
6e91a8fa6981a9d60873396fc602815899ed5f56b0a5cd9991667c34836831cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pyfastmm-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyfastmm-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.3 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ccef411cbe297406ebcac1b7b925138fd48baa96e934fd71d27d62efbd0a872e
BLAKE2b-256 checksum
How to use checksums
37435f22e05520d070343718b49fbe93a3f9837c54253fffc86b797e7377e7f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Security for pyfastmm 1.1.0

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for pyfastmm-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page