Skip to main content

PyMieSim logo

Badge

Status

Python versions

Python

Documentation

Documentation Status

Scientific article

Scientific article

Continuous integration

Unittest Status

Test coverage

Unittest coverage

Google Colab

Google Colab

PyPI package

PyPI version

PyPI downloads

PyPI downloads

Anaconda package

Anaconda version

Anaconda downloads

Anaconda downloads

Latest Anaconda release

Latest release date

PyMieSim

PyMieSim is an open-source Python package for fast and flexible Mie scattering simulations. It supports spherical, cylindrical and core–shell particles and provides helper classes for custom sources and detectors. The project targets both quick single-scatterer studies and large parametric experiments.

Try the live web GUI: PyMieSim Parameter Sweep Lab.

Features

  • Solvers for spheres, cylinders and core–shell geometries.

  • Built-in models for plane wave and Gaussian sources.

  • Multiple detector types including photodiodes and coherent modes.

  • Simple data analysis with pandas DataFrame outputs.

Installation

PyMieSim is available on PyPI and Anaconda. Install it with:

pip install PyMieSim
conda install PyMieSim  --channels MartinPdeS

Verify the installation with the same Python interpreter that you will use for your simulations:

python -c "import PyMieSim; print(PyMieSim.__version__)"

Named optical materials use PyOptik’s provenance-preserving RefractiveIndex.INFO catalog. Initialize its local snapshot once before using constructors such as SellmeierMaterial("BK7") or TabulatedMaterial("silver"):

python -m PyOptik setup

The released wheels are the easiest option. Building from source requires a C++20 compiler, Fortran, CMake, pybind11, and OpenMP; see troubleshooting if the compiled extension cannot be imported.

First simulation

Create a source, a scatterer, and a Simulation. Physical quantities use the built-in ureg unit registry, while refractive indices are dimensionless real or complex values.

from PyMieSim import (
    Gaussian,
    PolarizationState,
    Simulation,
    Sphere,
    ureg,
)

source = Gaussian(
    wavelength=633 * ureg.nanometer,
    polarization=PolarizationState(angle=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)

scatterer = Sphere(
    diameter=200 * ureg.nanometer,
    material=1.5 + 0.01j,
    medium=1.0,
)

simulation = Simulation(scatterer=scatterer, source=source)
qsca = simulation.run("Qsca")
print(qsca)

This prints a dimensionless scattering efficiency, approximately:

0.2080989068292113 dimensionless

Inspect the measures supported by the configured simulation with:

print(simulation.available_measures)

For explicit measure and unit metadata, request a typed result:

result = simulation.run("Qsca", as_result=True)
print(result.measure, result.quantity, result.units)

Units and material conventions

Always attach units to wavelengths, lengths, powers, and angles:

633 * ureg.nanometer
200 * ureg.nanometer
1e-3 * ureg.watt
0 * ureg.degree

Refractive indices are dimensionless. A complex index such as 1.5 + 0.01j represents an absorbing material under PyMieSim’s optical convention. Built-in and tabulated materials have supported wavelength ranges; use load_material and validate_wavelength when working with real material data.

Parameter sweeps

Use Experiment when you want to evaluate several wavelengths, particle sizes, or material parameters. Results retain named dimensions and coordinates, and can be converted to NumPy or pandas explicitly.

import numpy as np
from PyMieSim import (
    Experiment,
    GaussianSet,
    PolarizationSet,
    SphereSet,
    ureg,
)

source = GaussianSet(
    wavelength=np.linspace(500, 700, 5) * ureg.nanometer,
    polarization=PolarizationSet(angles=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)
scatterer = SphereSet(
    diameter=np.linspace(100, 500, 9) * ureg.nanometer,
    material=1.5,
    medium=1.0,
)

experiment = Experiment(scatterer_set=scatterer, source_set=source)
result = experiment.get("Qsca")
values = result.as_numpy()
dataframe = result.as_dataframe()

The experiment grid has five wavelength values and nine diameter values, so values.shape is (5, 9). See the parameter sweep guide for multiple measures and plotting.

Detector coupling

Add a detector when you need collected or coupled power rather than only a scatterer property:

from PyMieSim import (
    Gaussian,
    Photodiode,
    PolarizationState,
    Simulation,
    Sphere,
    ureg,
)

single_source = Gaussian(
    wavelength=633 * ureg.nanometer,
    polarization=PolarizationState(angle=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)
single_scatterer = Sphere(
    diameter=200 * ureg.nanometer,
    material=1.5 + 0.01j,
    medium=1.0,
)

detector = Photodiode(
    sampling=500,
    numerical_aperture=0.2,
    phi_offset=0 * ureg.degree,
    gamma_offset=0 * ureg.degree,
    medium=1.0,
)
simulation = Simulation(
    scatterer=single_scatterer,
    source=single_source,
    detector=detector,
)
coupling = simulation.run("coupling")
print(coupling)

coupling requires a detector. Other available detector types include CoherentMode and IntegratingSphere; see the detector coupling guide.

Common issues

  • If import PyMieSim fails, run python -m pip show PyMieSim and check that it uses the same Python executable as your script.

  • If a constructor reports a unit error, check that every dimensional input has units and convert it with .to(...) when necessary.

  • If coupling is unavailable, add a detector and inspect simulation.available_measures.

  • For slow or memory-heavy sweeps, print experiment.array_shape and experiment.total_iterations before requesting a result.

  • On servers or in CI, select a non-interactive Matplotlib backend such as Agg before importing plotting code.

See the online documentation for theory, performance guidance, runnable examples, and advanced near-field and far-field workflows.

Scattering efficiency of a 200 nm sphere with refractive index 4.0.

Code structure

Here is the architecture for a standard workflow using PyMieSim:

Code structure of a standard workflow using PyMieSim.

Building from source

For development or manual compilation, clone the repository and run:

git submodule update --init
mkdir build && cd build
cmake ../ -G"Unix Makefiles"
sudo make install
cd ..
python -m pip install .

Testing

Run the unit tests with:

pip install PyMieSim[testing]
pytest

Citing PyMieSim

If you use PyMieSim in academic work, please cite:

@article{PoinsinetdeSivry-Houle:23,
    author = {Martin Poinsinet de Sivry-Houle and Nicolas Godbout and Caroline Boudoux},
    journal = {Opt. Continuum},
    title = {PyMieSim: an open-source library for fast and flexible far-field Mie scattering simulations},
    volume = {2},
    number = {3},
    pages = {520--534},
    year = {2023},
    doi = {10.1364/OPTCON.473102},
}

Contact

For questions or contributions, contact martin.poinsinet.de.sivry@gmail.com.

Metadata

Release files for PyMieSim 5.6.4

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

Built distributions (wheels)

Table of built distributions (wheels) for PyMieSim 5.6.4
File
pymiesim-5.6.4-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pymiesim-5.6.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pymiesim-5.6.4-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
pymiesim-5.6.4-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pymiesim-5.6.4-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
pymiesim-5.6.4-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details
pymiesim-5.6.4-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pymiesim-5.6.4-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
pymiesim-5.6.4-cp311-cp311-macosx_26_0_arm64.whl CPython 3.11 CPython 3.11 macOS 26.0+ ARM64 Details

Total release size: 73.3 MB

Release files / pymiesim-5.6.4-cp313-cp313-win_amd64.whl

Download URL pymiesim-5.6.4-cp313-cp313-win_amd64.whl
Size 13.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f7334dbd29986db2d5a01e70d96e7b7cef71541d95c34faad419930eee9235bc
BLAKE2b-256 checksum
How to use checksums
19cb50939f431373b9a67d2c9f6a20b4fa43a190334d8c7772dbce56b105b5fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.6.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.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
0ce259ddd56dfd8bd5c71a5f02f0ea72fed13cceb3c7bd5d10adc8c50d3bd688
BLAKE2b-256 checksum
How to use checksums
d04665a8feb16f69aaa1c09193b69fea3824fd72a8e4e326cb01bc3235ad556d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp313-cp313-macosx_26_0_arm64.whl

Download URL pymiesim-5.6.4-cp313-cp313-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
fea47d977fec53dfb19fbe52a40563cd02c13d02f080ec8dfc1a4b3ff688d2d7
BLAKE2b-256 checksum
How to use checksums
f581136bcadca87af85a9bce6d2ec1bb887e9974b92ddb3de5005b48a71f2c93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp312-cp312-win_amd64.whl

Download URL pymiesim-5.6.4-cp312-cp312-win_amd64.whl
Size 13.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
fb6dff4ae68d0d8fbb5cb8d9f7e54524a157144eec75d960e6e0e3c6dc5f543c
BLAKE2b-256 checksum
How to use checksums
3c055a70545a773f2f3937cb2dfacbd05d6ebe95b0a6360fa6b016a54c185dc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.6.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.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
3f63c85606085aa57bb279eaf800f84b4536aa158f0d4622d6d7fb3b7657880c
BLAKE2b-256 checksum
How to use checksums
d97a5fea6572acedc15b14b8ac86aaaf44b318dfa65a16fe3e04794d1f8c562e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp312-cp312-macosx_26_0_arm64.whl

Download URL pymiesim-5.6.4-cp312-cp312-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
02d8b1970737d4e830ed4b6127f9f77fdc438d8d0beb09138154395c3de2441f
BLAKE2b-256 checksum
How to use checksums
fdb9cee6a1e1fb6657ead7dcce2ab3e3ca2805460f00ee797aea43843077e90e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp311-cp311-win_amd64.whl

Download URL pymiesim-5.6.4-cp311-cp311-win_amd64.whl
Size 13.6 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
46b55fe5e33d297abc32555d362a22f278899217ee623e92ed048af67f8b4a9f
BLAKE2b-256 checksum
How to use checksums
2f7911cb28f427aefdbf58df6146cc4d2c1a11ebac5b9c76bd520370725f72f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.6.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.0 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9a4e49ebef0605bf9a1c6fa64a43c61291f75a3030437453bf6e6ad5cf06ba9d
BLAKE2b-256 checksum
How to use checksums
890968552743e734840c72c61eeaaa9160ab114f14875b4702974130714c6abc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pymiesim-5.6.4-cp311-cp311-macosx_26_0_arm64.whl

Download URL pymiesim-5.6.4-cp311-cp311-macosx_26_0_arm64.whl
Size 4.7 MB
Tags CPython 3.11 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
4540bf79529471bc78150d70896464fc535d66368f2fe1b8a6a3fa1205a6f3ff
BLAKE2b-256 checksum
How to use checksums
1dbc1240110a170465756f15643fb83fb847926d959e715340af2a8f50c98d82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

5.7.1

9 release files

This release

5.6.4 This release

9 release files

5.6.0

9 release files

5.3.0

9 release files

5.2.2

9 release files

5.2.1

9 release files

5.2.0

9 release files

5.1.13

9 release files

5.1.12

9 release files

5.1.11

9 release files

5.1.10

9 release files

5.1.9

9 release files

5.1.8

9 release files

5.1.7

9 release files

5.1.6

9 release files

5.1.5

9 release files

5.1.4

9 release files

5.1.3

9 release files

5.1.2

9 release files

5.1.1

9 release files

5.1.0

9 release files

5.0.4

9 release files

5.0.3

9 release files

5.0.2

9 release files

5.0.1

9 release files

5.0.0

9 release files

4.0.2

9 release files

4.0.0

9 release files

3.9.0

9 release files

3.8.6

9 release files

3.8.5

9 release files

3.8.2

12 release files

3.8.0

12 release files

3.7.0

12 release files

3.6.3

12 release files

3.6.2

12 release files

3.6.1

12 release files

3.6.0

12 release files

3.5.4

9 release files

3.5.3

9 release files

3.5.2

9 release files

3.5.1

9 release files

3.5.0

9 release files

3.4.0

9 release files

3.3.4

9 release files

3.3.1

9 release files

3.2.7

9 release files

3.2.6

9 release files

3.2.5

9 release files

3.2.4

9 release files

3.2.3

9 release files

3.2.2

9 release files

3.2.1

9 release files

3.0.1

9 release files

3.0.0

9 release files

2.6.3

9 release files

1.10.4

1 release file

1.10.3

4 release files

1.9.4

15 release files

1.9.3

15 release files

1.9.0

15 release files

1.8.3

15 release files

1.8.2

15 release files

1.8.1

15 release files

1.8.0

15 release files

1.7.3

15 release files

1.7.2

15 release files

1.7.1

15 release files

1.7.0

15 release files

1.5.3

3 release files

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