![]() |
QPMS
Electromagnetic multiple scattering library and toolkit.
|
The scatspec format allows one to describe a scattering system — particle shapes and materials, geometry, lattice periodicity and point group symmetry — in a compact, declarative YAML file, and load it into a QPMS qpms_scatsys_t using the pure C library, without any dependency on the Python part of QPMS. The loader lives in qpms/scatspec.{h,c}.
A minimal example (finite 30×40 rectangular array of silver nanodisks plus a single rotated and mirrored copy):
Placement transforms. A placement rotate: turns the particle by the given rotation R: the particle's T-matrix transforms as ‘T’ = W(R) T W(R)^H, whereW(R)is the VSWF coefficient transformation ofR(the active rotationE'(r) = R E(R⁻¹ r), qpms_irot3_uvswfi_dense()inqpms/symmetries.h; see also qpms_symmetrise_tmdata_irot3arr()inqpms/tmatrices.h). A placement mirror: xy(primitivez-flip),xzoryzmirrors the particle through the coordinate plane. (Before 2026-11-25 the dense matrix was stored in a conjugated convention, which silently replaced every nontrivial placement rotation by its x,z-flipped counterpart; the fix and its regression test are recorded inai_notes/11_honeycomb_hexlaser_example.md`.)
The examples directory contains runnable files: examples/scatspec/ (rect30x40.yaml, hexlattice-periodic.yaml, filetmatrix-rotated.yaml). The command line utility qpms-spec-info (built into build/apps/scatspec-info/) inspects spec files:
qpms-spec-info rect30x40.yaml --set pitch=400*nm --positions pos.txt qpms-spec-info hexlattice-periodic.yaml --build
All quantities are in SI units. Every numeric field accepts either
375e-9), or"0.4 * pitch"; in YAML, plain scalars such as 375*nm or 0.4 * pitch need no quotes).Expressions are evaluated by the small evaluator from qpms/specexpr.h: numbers, identifiers, + - * / ** (also ^), unary minus, parentheses, function calls with comma-separated arguments (the built-ins exp log ln sqrt sin cos tan abs real imag conj take one argument), and the built-in constants pi, I, c, hbar, h, e, eV, nm, um, mm, SU, eV2SU, SU2eV (values as in qpms/constants.py; I is the imaginary unit, so 1.5 + 0.02*I is a valid complex refractive index). There is no implicit multiplication: 375nm is an error.
The simspec format additionally provides the experimental Rayleigh-anomaly expressions in the periodic-system experiments: the constants rayleigh1, rayleigh2, ... (the Nth distinct ascending empty-lattice anomaly ħc·|k+G|/n_b at the experiment's Bloch vector) and the per-G-family function rayleigh(i, j) (one integer index per lattice dimension; continuous in k, and the only form parametrising the explicit contours of kind: bandstructure, where it is re-evaluated at every Bloch vector of the sweep). See qpms/rayleigh.h and ai_notes/simspec_draft.md (open question 9) for the semantics and limitations; qpms-sim --dump prints the resolved table with the contributing G vectors. YAML gotcha: inside flow mappings/sequences ({...}, [...]) a comma terminates the entry, so expressions with rayleigh(...) calls need block style.
The vars section defines named variables in document order; expressions may reference the previously defined ones. Variables can be overridden (or newly defined) at load time — overrides always take precedence over the file's vars section. This is the intended mechanism for externally scaling a geometry described by a single file:
overrides argument of qpms_scatspec_parse_file();qpms-spec-info ... --set pitch=400*nm.The document root is a mapping with the keys
| key | required | contents |
|---|---|---|
version | yes | currently must be 1 |
vars | no | named variables (see above) |
materials | no | named material definitions |
particles | no | named particle kinds |
places | yes | sequence of placements (the geometry) |
system | no | medium or layers, lattice, symmetry, default omega |
experiments, output | no | reserved for the simulation half of the unified simspec format (see ai_notes/simspec_draft.md); accepted but ignored by the system-only loaders |
Unknown keys are rejected everywhere (typo protection), duplicate mapping keys are an error, and the file must contain exactly one YAML document.
A material (used in system.medium, particles.*.material, particles.*.outside and inside the materials table) is given as
1.52 or 1.5 + 0.02*I);Ag Au Cu Al Cr Ti Be Ni Pd Pt W;n (refractive index), ld (LD model name), yaml (file path), ref (reference into the materials table);materials table (plain string that matches a name defined there; names take precedence over the LD model list).Entries of the materials table may reference each other. The relative permittivity of an index-given material is n², and the relative permeability is always 1.
Each entry of the particles table defines a reusable particle kind. Common optional key: lMax (positive integer, default 2), which defines the VSWF basis of the particle's T-matrix.
shape: sphere** — analytic Lorentz–Mie sphere. Keys: material (inside), r (radius; positive), optional outside (surrounding material, defaults to system.medium).shape: cylinder** — finite cylinder, axially symmetric particle via the arc-parametrisation machinery. Keys: material, r, h (height), optional outside, optional lMax_extend (positive integer, default 1) which enlarges the internal basis used by the generator.shape: spheroid** — spheroid (ellipsoid of revolution), axially symmetric particle via the arc-parametrisation machinery. Keys: material, radiusxy (equatorial semi-axis; positive), radiusz (polar semi-axis; positive), optional outside. The names of the dimension parameters follow Table 2 of the T-matrix community format specification. A spheroid with radiusxy == radiusz is a sphere.shape: cone** — (possibly truncated) cone with the rotational axis along z, centred in the origin, via the arc-parametrisation machinery. Keys: material, radius_top (base radius at z = +height/2; zero means an apex there), radius_bottom (base radius at z = −height/2; zero means an apex there; at least one of the two radii must be positive), height (positive; the community-format name; the original h spelling is accepted as an alias, cf. below), optional outside, optional lMax_extend (as for the cylinder).shape: cut_sphere** — cut sphere (spherical cap), axially symmetric particle via the arc-parametrisation machinery; the "cut sphere" of Table 2 in the T-matrix community format specification (cf. Doicu, Wriedt, Eremin 2006). The particle is the part of a sphere of radius r on one side of a plane perpendicular to z, such that its total height is h: it occupies z ∈ [−h/2, +h/2] with the flat circular face at the bottom (z = −h/2) and the spherical dome on top; h == 2r gives the full sphere. Keys: material, r (sphere radius; positive; radius is accepted as an alias), h (cap height; positive, at most 2r; height is accepted as an alias), optional outside, optional lMax_extend (as for the cylinder).shape: core_shell_sphere** — layered (core-shell) sphere computed with the layered-sphere (Aden–Kerker) Mie theory; the "core-shell
sphere" of Table 2 in the T-matrix community format specification. The T-matrix is diagonal. The shell radius is measured from the centre of the whole object, as accepted in the format specification. Keys: material (the outer layer material), core (the core material), radius_0 (core radius; positive), radius_N (outer radius; positive, greater than radius_0), optional outside. The names follow the community format directly (no legacy aliases). The layer materials may differ in permeability, too. For moderate size parameters the direct per-order solve is accurate; very large spheres may need a recursion-based algorithm (not implemented).shape: superellipsoid** — axially symmetric superellipsoid ("super-spheroid"), via the arc-parametrisation machinery; the surface-of-revolution case of the "superellipsoid" of Table 2 in the T-matrix community format specification (Wriedt 2002, POV-Ray superquadric nomenclature). The meridian curve is the superellipse |ρ/radiusx|^(2/n_parm) + |z/radiusz|^(2/n_parm) = 1: n_parm = 1 gives the spheroid, n_parm < 1 boxy shapes, n_parm → 0 a rounded cube. Keys: material, radiusx, radiusy, radiusz (semi-axes; positive; radiusx and radiusy must be equal), n_parm (north-south roundedness; 0 < n_parm < 2 for a smooth generatrix), e_parm (east-west roundedness; only e_parm: 1 is supported — the general triaxial superellipsoid is not axisymmetric and would have to be computed with an external solver), optional outside. The kind is mirror-symmetric with respect to the equatorial plane (D∞h).Every simple-shape particle kind accepts an optional generator key that selects how its T-matrix is computed. It is either a scalar (generator: native or generator: scuff) or a mapping with the generator name and its optional parameters:
generator: name: scuff mesh_lc: 40*nm
native — the built-in semi-analytic generators (available for sphere, cylinder, spheroid, cone, cut_sphere, core_shell_sphere and the superellipsoid of revolution). This is the default for those shapes.scuff — the external scuff-em pipeline: a gmsh-generated surface mesh of the particle is fed to scuff-tmatrix, which runs once per requested frequency. This is the default for the shapes without a native generator and covers torus, ring, ellipsoid (triaxial), cube, rectangular_cuboid, regular_prism, pyramid and wedge (Table 2 of the community format; helix and convex_polyhedron are not known to the parser at all yet, and the general (non-rotationally-symmetric) superellipsoid is parsed but rejected).The scuff generator parameters (mapping form only): mesh_lc (characteristic mesh edge length; default = the particle's maximum extent divided by 20; must be small compared to the involved material wavelengths), symmetrise (point group name; see below). The executable lookup: QPMS_GMSH_BIN and QPMS_SCUFF_TMATRIX_BIN environment variables override the plain gmsh and scuff-tmatrix names resolved through $PATH; the generated meshes and outputs are cached under $QPMS_SCUFFGEN_CACHE (default: $XDG_CACHE_HOME/qpms/scuffgen, else $HOME/.cache/qpms/scuffgen). Complex frequencies are not supported by this generator yet.
Ordinary gmsh meshing is deterministic but not equivariant: the mesh of a point-group-symmetric particle generally breaks the particle's symmetry at the discretisation level, which shows up as spurious asymmetry terms in the computed T-matrix (typically at the 1e-4–1e-5 relative level for a default-resolution mesh). With symmetrise: <GROUP> the scuff generator replaces the whole-particle mesh by an exactly group-invariant one:
Only groups generated by their mirror reflections are supported (C1h = Cs, C1v–C12v, C1h–C12h in the axial role below, D1h– D12h, Td, Oh); chiral groups (Cn, Dn, T, O, …) are rejected. The group must also be a subgroup of the shape's own point symmetry about the origin (canonical z axis):
sphere — any supported group;cylinder, spheroid, torus, ring — any of the axial mirror groups Cnv(N), Cnh(N), Dnh(N) (any N);cube — the z-axis groups with N ∈ {1, 2, 4}, plus Td and Oh;rectangular_cuboid, ellipsoid, shearless wedge — Cnv, Cnh, Dnh with N ∈ {1, 2} (C1v, C2v, C1h, C2h, D1h, D2h);regular_prism — Cnv(M), Cnh(M) or Dnh(M) with M dividing n_edges; pyramid — Cnv(M) with M dividing n_edges; shift must be a multiple of π/n_edges (the canonical orientation) and the pyramid apex_shift must be zero.Mesh order must be 1 with the symmetrisation. The T-matrix computed from the symmetrised mesh is not automatically projected onto the group symmetry: it satisfies the group constraints only to the roundoff level (the mesh is exactly invariant, so the T-matrix violates them at the 1e-10 relative level or below, vs. 1e-4–1e-5 for an unsymmetrised mesh; cf. the benchmark numbers in ai_notes/scuffgen_symmetry_benchmark.md). Exact symmetrisation of a computed T-matrix table remains available through the shape: scuff file kind's symmetrise key or qpms_symmetrise_tmdata_finite_group(). The kind is still treated as internally anisotropic by the automatic symmetry detection.
Example:
generator: {name: scuff, symmetrise: C4v, mesh_lc: 20*nm}
The T-matrix of a scuff-generated kind is treated as fully anisotropic by the automatic symmetry detection, regardless of symmetrise (a conservative default; the exact mesh symmetry does not automatically carry over to the system-symmetry machinery).
Parameter name aliases: the dimension parameter names of the T-matrix community format (Table 2 of the format specification paper) are accepted as aliases of the original names for all the kinds that use them: radius in place of r, and height in place of h (the cone kind uses height as its primary name; the original h spelling is accepted as an alias there, cf. above). The original spellings keep working; giving both spellings of the same parameter is an error.
shape: scuff** — T-matrix interpolated from an external file. Keys: file (path; relative paths are resolved against the location of the spec file), optional format (default scuff), optional symmetrise (point group name; symmetrise the loaded T-matrix table over the group) and atol (roundoff-cleanup threshold applied after symmetrisation, default 1e-16). Two file formats are supported:format: scuff** — a scuff-em .TMatrix text file (or a file in the same format). The file carries no mode list, so lMax (required in this case) defines the loaded VSWF basis.format: hdf5** — a T-matrix file in the community HDF5 format (.tmat.h5; see the "T-matrix data format" specification, storage_format_version v1). The file defines its own VSWF basis via its /modes group, so lMax is optional here; if given, it must match the maximum degree found in the file. Only square T-matrices in the parity ("electric"/"magnetic") polarisation basis are supported; cluster (local-basis) files and helicity bases are rejected.**shape: constant** — a fabricated, frequency-independent T-matrix supplied inline, acting in an explicit VSWF set (the declarative-spec counterpart of the legacy -T/-w workflow). Keys:
vswf (a sequence of raw VSWF codes — the packed indices of qpms_tmn2uvswfi(), e.g. [6, 14] for the two xy electric dipoles N(1, ±1)) or tlm (a sequence of [type, l, m] triples with the type one of M (magnetic) or N (electric), e.g. [[N, 1, -1], [N, 1, 1]]), andtmatrix — the T-matrix in the given basis: a square matrix given as a sequence of rows of complex expressions. The list order is the row/column order of the matrix.The basis — and with it the whole system basis, which does not have to be an lMax ball — is defined by the list; lMax is not valid for this kind. There are no material/embedding keys: the matrix is used verbatim at every frequency (also with a layered background, where the embedding is then the user's responsibility). Longitudinal (L-type) waves and duplicated VSWFs are rejected. For the automatic symmetry detection a fabricated T-matrix counts as fully anisotropic (like the scuff kinds); declare system.symmetry explicitly to exploit an actual symmetry — the declared group is verified against the matrix values at system build time. For the irrep block diagonalisation to be applicable, the basis has to be closed under the declared (or detected) symmetry group.
shape: dummy** — zero T-matrix (no scatterer), useful for tests.The T-matrix of a scuff particle should be evaluated within the frequency range of the file, and the refractiveindex.info interpolators within their sampled range: the C-side interpolators extrapolate silently outside it (only the Python MaterialInterpolator refuses out-of-range frequencies).
Each element of the places sequence defines one or more particles.
particle (required): the name of a kind defined in particles, or an inline mapping with the same structure as a particles entry (an anonymous kind). YAML anchors/aliases work as usual and are equivalent to repeating the definition.Placement (exactly one of):
position: [x, y, z] — a single particle ([x, y] means z = 0);positions: [[x, y, z], ...] — several particles, one per vector;array — compact regular array; mapping with keysshape: [n1, n2, ...] — 1–3 positive integers (array dimension);step: [s1, s2, ...] (diagonal basis; same length as shape) or basis: [[...], ...] (shape-length many basis vectors, one per dimension, for oblique arrays);origin: [x, y, z] (default origin), optional centered: true (shift the array so that its centre of mass sits at the origin).The array positions are origin + Σ_k i_k · basis_k with i_k = 0..n_k−1; the index of the first shape entry varies slowest.
rotate (optional): rotation applied to the particle's T-matrix (the position is not affected). Either {axis: [x, y, z], angle: a} (axis need not be normalised) or a shorthand {x: a}, {y: a} or {z: a}.mirror (optional): mirror operation applied to the particle's T-matrix; "xy" (the primitive σ_z flip), "xz", "yz", or true (equivalent to "xy").If both rotate and mirror are given, the particle is mirrored first and rotated afterwards. The T-matrix transformations are carried out by the C core (QPMS_TMATRIX_OPERATION_IROT3 operations); for axially symmetric shapes a rotation about z is a no-op. Systems built from specs with rotated or mirrored copies are subject to the same T-matrix deduplication as any other QPMS system.
medium: background material (default: vacuum).layers: a layered (stratified) background — the mutually exclusive alternative to medium. A sequence of layer mappings {material: ..., thickness: ...}, ordered bottom → top (increasing z); the first (bottom) and the last (top) layers are the semi-infinite outer half-spaces and have zero thickness (given explicitly as 0 or omitted); each intermediate layer carries its thickness. At least two layers (the two half-spaces) are required. When layers is used, every particle kind must declare outside (the medium its T-matrix is embedded in, which should match the layer the particle sits in); same-layer pairs couple through the homogeneous Ewald sums of the layer medium and cross-layer pairs through the layer-mediated Bloch-channel machinery (see ai_notes/07, esp. Apps. C, E and F; the periodic scattered-field evaluation is not implemented for layered backgrounds yet, but the mode problem, resonances and the transmission experiment are).symmetry: the point group symmetry of the system. Either a group name or auto (see below). For finite systems, the group name generates the particle orbits from the placements — the placements must then cover only the fundamental domain of the group. For periodic systems (with lattice), the placements are always the full unit-cell contents and the group is only verified against them (declared groups in their canonical orientation; the detection handles arbitrary orientation); the symmetry-adapted block diagonalisation is used at general k (little-group decomposition at named k points and irreducible k meshes; cf. ai_notes/06). For periodic systems the detection is the default: a 2D- or 3D-periodic file without system.symmetry behaves as symmetry: auto; give symmetry: trivial to opt out. Available groups: all 32 crystallographic point groups (trivial_g/C1, C2, Cs-type C1h/C1v, Ci alias of S2, C2h, D2, C2v, D2h, C3, C3i alias of S6, C3h, C3v, D3, D3d, C4, S4, C4h, D4, C4v, D2d, D4h, C6, C3h, C6h, D6, C6v, D3h, D6h, T, Th, Td, O, Oh), the axial series C_n, S_2n, C_nh, C_nv, D_n, D_nd, D_nh for n up to 12 (e.g. C5, C5v, D5h, D7, S8, D12d), the icosahedral groups I and Ih, and the auxiliary reflection groups x_and_z_flip, y_and_z_flip. All the proper point groups come from a single generated data source (finitegroups_data_ext.c); the names of the originally hand-derived groups (C2, C2v, D2h, C4, C4v, D4h, D3h) resolve to generated data verified equivalent to the old (note: C4's complex irrep pair is named E1/E1*, previously 1E/2E).
**auto**: the point group is detected automatically from the placed particles. In this mode the placements must describe the complete cluster (finite systems; not just a fundamental domain — a partial list would only reveal the symmetries of the fragment) or the complete unit cell (periodic systems; the detection uses the spglib layer dataset, so the detected operations respect the lattice, and are then verified against the cell contents including the kinds' internal symmetries and the placement transforms). One v1 restriction for periodic systems: the cell origin must be a fixed point of the detected group (otherwise the load fails with a hint to shift the origin). The detection is available for all periodic dimensionalities: 2D and 3D via the spglib layer/space group datasets, and 1D via geometric candidate enumeration (spglib has no rod-group API; the verified operation set is matched against the generated group table, whose axial series caps at N = 12 — continuous rod symmetries such as that of a single-sphere chain are reported through a crystallographic closure, e.g. a C12-type finite subgroup, which still yields valid block diagonalisations). For 1D lattices auto must be requested explicitly (it is not the default); declared group names also work.
The detection considers a candidate symmetry operation valid only if it (i) maps every particle position onto another particle of the same particles entry ("kind"), and (ii) carries each particle's T-matrix onto its partner's, taking the placement transforms (rotate, mirror) and the kind's internal symmetry into account:
sphere, core_shell_sphere and dummy kinds are invariant under every operation (the T-matrix of a sphere does not change under rotations or mirrors);cylinder, spheroid, cone and superellipsoid kinds are D∞h-symmetric (rotations about the symmetry axis, the mirrors containing or perpendicular to it; note that for the cone — and the cut_sphere below — this is an over-claim: those mirror-asymmetric shapes only have the axial symmetry C∞v, cf. ai_notes/basic_shapes_coverage.md); cut_sphere kinds are taken as D∞h-symmetric, too, although the (dome-up) cut sphere itself only has the axial symmetry C∞v — the over-claim matches the cone treatment (cf. ai_notes/basic_shapes_coverage.md);scuff kinds are taken as fully anisotropic — a loaded T-matrix is not assumed to have any internal symmetry — unless symmetrise names a group, in which case the T-matrix is known to be invariant under it.This matters: e.g. two particles of a fully anisotropic kind have no symmetry beyond the identity (a randomly shaped particle is not mapped onto itself by swapping or rotating it), while the same pair gains the mirror symmetry when the second placement carries the matching mirror transform. Undetected (but geometrically present) symmetries of scuff kinds can be declared with symmetrise.
The accepted operation set is closed under multiplication; the detected group is re-oriented to the actual arrangement and used for the irrep block diagonalisation exactly like a named group. Notes and limitations:
C5/C5v/D5h) and the icosahedral groups. For periodic systems the detection is spglib-based, so only crystallographic operations can be found: a periodic arrangement with non-crystallographic symmetry (e.g. a five-fold axis, or the continuous rod symmetry of a 1D chain) is reported with the highest generated subgroup found (the axial closures cap at N = 12), and a completely asymmetric cluster yields the trivial group (the computation then simply proceeds without block diagonalisation);symmetry_tolerance, see below — so the scale of the coordinates does not matter.Example (the group of the drawn cluster is detected and exploited; the same file with symmetry: D4h would require the placements to be trimmed to a fundamental domain):
symmetry_tolerance: optional positive number, only meaningful with symmetry: auto; the position tolerance of the symmetry detection as a fraction of the largest particle distance from the coordinate origin (finite systems; periodic systems use the longest lattice vector instead). Default 1e-4, i.e. particles are considered symmetry-equivalent if their positions match to within 0.01% of the cluster scale. Increase it for clusters built from rounded or slightly noisy coordinates (e.g. 0.001), keeping in mind that a too generous tolerance can merge genuinely different geometries.lattice: makes the system periodic. Either a sequence of 1–3 lattice basis vectors ([[x, y, z], ...]), or a mapping with type one of linear (1D), square, rectangular (keys a, optional b) and hexagonal (key a), producing the usual 2D bases. Periodic systems can have a symmetry; for 2D and 3D lattices auto is the default (trivial opts out); 1D lattices accept explicit group names and auto on request.omega: optional initial angular frequency (expression), used e.g. by qpms-spec-info --build when --omega is not given.Lifetime: the spec owns the T-matrix generators, materials and basis specifications that the built qpms_scatsys_t references. The spec must therefore be kept alive and unmodified as long as the built system is used (same constraint as the Python ScatteringSystem, which keeps references to its generator objects).
libfyaml/), parsed in YAML 1.2 mode; boolean fields only accept true/false.qpms/finitegroups_data.c (the trivial group and the two auxiliary reflection groups) is regenerated by misc/codegen_finitegroups.py from the group registry that used to live in the legacy Python module qpms/_legacy/symmetries.py — deleted with the 2026 bindings redo; restore it from git history (git show 5155153^:qpms/_legacy/symmetries.py) to regenerate, see the script header —, and qpms/finitegroups_data_ext.c (all the proper point groups) comes from misc/codegen_finitegroups_ext.py (closed-form axial irreps, spgrep for the polyhedral ones; see the script header). The hand-derived data of the originally implemented groups was verified equivalent to the generated one before being superseded (see ai_notes/04). Regenerate the files after changing the group definitions. The runtime interface (qpms_finite_group_t, name lookup in qpms/finitegroups.c) stays the same; no symmetry library is needed at runtime for the group data.tests/test_scatspec.c (also registered with CTest as scatspec).system.symmetry: auto) uses the spglib-submodule-backed detector from qpms/spgsym.{c,h} (see ai_notes/04 and ai_notes/05 for the design); the candidate symmetry operations are verified directly against the placed particles, so the detection works for arbitrarily oriented clusters. The detected metadata (space group number, point group) is shown by qpms-spec-info.ai_notes/06.)