MieLib
MieLib is a Python library for the scattering of waves by a sphere (Mie theory) in optics and in acoustics, and for the vector spherical harmonics.
mielib.optics: an isotropic sphere, also magnetic, in a magnetic host. Mie coefficients, T-matrix, internal amplitudes and the denominators, whose zeros are the modes of the sphere.mielib.acoustics: a fluid sphere, from the Supplemental Material of Phys. Rev. Lett. 123, 183901 (2019). The same functions as in optics.- Cross sections in both physics: scattering, extinction, absorption, backscattering, radiation pressure, the asymmetry parameter, and the part of each multipole.
mielib.vsh: the complex vector spherical harmonics M, N, L, the harmonic X of Jackson, and the real harmonics of Bohren & Huffman.mielib.special: spherical Bessel, Hankel and Riccati–Bessel functions with their first and second derivatives.mielib.coordinates: spherical and cylindrical coordinates, and the components of vector fields in them.
Installation
From PyPI:
pip install --upgrade mielib
mielib needs Python 3.12 or later and SciPy 1.18 or later.
Quick start
import numpy as np
from mielib import optics
# a sphere with the radius 100 nm and eps = 16 + 0.3i in vacuum
wavelength = np.linspace(500e-9, 1100e-9, 300)
k = 2 * np.pi / wavelength # wavenumber in the host
q = optics.cross_sections(k, 100e-9, 16 + 0.3j, norm='geom')
q.sca, q.ext, q.abs # cross sections divided by pi a^2
q.sca_e[1], q.sca_m[1] # the electric and the magnetic dipole parts of q.sca
All the Mie functions take the size parameter x = k a in the host and the parameters of the particle relative to the host,
for example optics.mie_a(j, x, eps_rel, mu_rel) and acoustics.mie_a(j, x, rho_rel, beta_rel).
The harmonics take the indices in the order (j, m), for example vsh.N(j, m, rho, theta, phi, superscript=1).
Theory
The note Vector spherical harmonics and Mie scattering in optics and acoustics: conventions and explicit formulas gives all the definitions and the formulas that mielib uses. Its notation follows the PhD thesis of I. Toftul, Resonant Metaphotonics: From Optical Manipulation to Chiral Metasurfaces (Australian National University, 2026).
The main conventions:
- The time dependence is exp(−iωt).
- The electromagnetic field is the pair (√ε E, √μ H). Thus, the electromagnetic duality is √ε E → √μ H, √μ H → −√ε E, and for a sphere it swaps a_j and b_j when ε_rel and μ_rel are swapped.
- The T-matrix is the outgoing amplitude divided by the regular amplitude of the same multipole. In optics, T^e_j = −a_j and T^m_j = −b_j, with the a_j and b_j of Bohren & Huffman. In acoustics, T_j = a_j.
Examples
The examples folder has Jupyter notebooks:
- cross_sections.ipynb: the cross sections of a sphere and their multipole parts, in optics and in acoustics.
- harmonics.ipynb: the vector spherical harmonics, and a plane wave from the harmonics.
The changes between the versions are in CHANGELOG.md.
ToDo
- Search for complex poles of Mie scattering coefficients
Credits
If you use mielib, please cite it:
@misc{mielib,
author = {Ivan Toftul},
title = {{MieLib python library}},
journal = {GitHub},
year = {2023},
url = {https://github.com/toftul/mielib},
doi = {10.5281/zenodo.8008648}
}
The conventions and the theory are from the thesis:
@phdthesis{Toftul2026thesis,
author = {Ivan Toftul},
title = {{Resonant Metaphotonics: From Optical Manipulation to Chiral Metasurfaces}},
school = {Australian National University},
year = {2026},
url = {https://hdl.handle.net/1885/733812237}
}
Metadata
Release files for mielib 0.3.1
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 |
|---|---|---|---|---|
| mielib-0.3.1.tar.gz | 12.1 kB | With provenance | Details for mielib-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mielib-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for mielib-0.3.1-py3-none-any.whl |
Total release size: 26.5 kB
Release files / mielib-0.3.1.tar.gz
| Download URL | mielib-0.3.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0afb78b692ac3ba3dd00de04fdbe18fb1d0a8993ff21cdfbe75dda9a4d54887a
|
|
BLAKE2b-256 checksum How to use checksums |
f54977864b163d5764cfbeab7512776115af61945e421c078a22ed1e74e7b3d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 21, 2026.
Transparency logRelease files / mielib-0.3.1-py3-none-any.whl
| Download URL | mielib-0.3.1-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ff55ee44d36f4f08286101b8585ebb3236180d3dd1278991e65cd5a1b986ff2
|
|
BLAKE2b-256 checksum How to use checksums |
2692b1c99552cc5c6eb6fe4af22705695284a15bc736e3cfe2483b66c95619c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 21, 2026.
Transparency logSecurity for mielib 0.3.1
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
Both files in this release have been uploaded with provenance metadata.
Attestation for mielib-0.3.1.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 21, 2026.
Transparency logA 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.