Skip to main content

midas-pdf

Differentiable, error-propagating total-scattering / pair-distribution-function (PDF, G(r)) pipeline.

midas-pdf is a deliberately thin layer. Almost everything it needs already exists elsewhere in MIDAS and is reused rather than reimplemented:

Stage Provided by Status
detector geometry + wavelength (+ covariance) midas-calibrate-v2 existing
pixels → I(Q) with σ (polygon-exact, pol/solid-angle/dark) midas-integrate-v2 existing
atomic form factors f(Q), anomalous f′,f″ (differentiable) midas-hkls existing
Compton / incoherent subtraction midas-integrate-v2.corrections.compton existing
S(Q) → G(r) sine FT with σ propagation midas-integrate-v2.pdf existing
polyatomic Faber-Ziman normalization ⟨f²⟩, ⟨f⟩² midas-pdf (new) this package
Δ-PDF (difference PDF) for time-resolved/operando midas-pdf (new) this package

The single piece that did not exist anywhere was the composition layer: the existing midas_integrate_v2.pdf.normalize_to_S is monoatomic (it divides by a single ⟨f²⟩). Real total scattering of a polyatomic sample needs the Faber-Ziman form, which requires both ⟨f²⟩(Q) and ⟨f⟩²(Q) built from the sample composition. That bridge — and the Δ-PDF helper — is all midas-pdf adds.

What is novel

Every arrow in the chain is a torch operation carrying a 1σ uncertainty, so the pipeline is end-to-end differentiable and end-to-end error-propagating — a combination no production total-scattering tool (PDFgetX3 / PDFgetN / GudrunX) offers. Concretely this enables:

  • gradient-based normalization refinement (refine.py): scale/offset/ρ₀ are fit by L-BFGS against model-free physics (⟨S⟩→1 at high Q, G(r)=−4πρ₀r at low r) — the "ad hoc scale twiddling" of PDF analysis becomes an optimization;
  • an analytic 1σ band on every G(r) point, validated against a Monte-Carlo bootstrap to <1% (dev/demo_sigma_validation.py) — error propagation is the one thing existing software tends to drop;
  • statistically-meaningful Δ-PDF difference maps for time-resolved studies: σ²(ΔG) = σ²(G₁) + σ²(G₂), so a feature change can be tested against noise;
  • differentiability in atomic positions (validate.py, Debye equation), so the same code is a forward model for structure refinement against G(r).

Modules

Module Contents
composition.py Composition → ⟨f⟩(Q), ⟨f²⟩(Q), Laue term, Compton
compton.py Hubbell tabulated incoherent scattering + Breit-Dirac recoil
corrections.py Q-dependent detector efficiency, flat-plate self-absorption (MAC-backed)
fluorescence.py expected_fluorescence: which elements fluoresce at a given energy
multiple_scattering.py lumped_background: Tier-1 smooth MS/fluorescence/air background
cross_section.py differential_cross_section: per-atom dσ/dΩ(Q) (MS engine)
ms.py first-principles MS: analytic single + double scattering, Monte-Carlo references (slab + cylinder)
ms_transport.py all-orders MS by differentiable discrete-ordinates radiative transfer (slab)
structure.py differentiable small-box PDF (PDFfit-style) forward model + error-aware refinement
normalize.py faber_ziman_S: I(Q) → S(Q) with σ (and lumped background)

Runnable, one-per-capability demonstrations live in examples/. | gr.py | re-export of the reused sine FT (S(Q) → G(r) with σ) | | pipeline.py | i_of_q_to_Gr: I(Q) → G(r) end to end | | frontend.py | image_to_iq, image_to_Gr: detector pixels → G(r) | | conventions.py | structure_function_F, pair_distribution_g, total_correlation_T, radial_distribution_R | | refine.py | refine_normalization: differentiable scale/offset/ρ₀ fit | | deltapdf.py | delta_pdf, significant_mask: difference PDF + n-σ test | | validate.py | debye_scattering_intensity, synthetic_powder_image: model-free references |

Quick start

import torch
from midas_pdf import Composition, i_of_q_to_Gr

comp = Composition({"Si": 1, "O": 2})          # SiO2, number fractions
q = torch.linspace(0.5, 25.0, 2000, dtype=torch.float64)
r = torch.linspace(0.0, 10.0, 1000, dtype=torch.float64)

# I_q, sigma_I come from midas-integrate-v2 (pixels -> I(Q) with sigma)
G, sigma_G, S = i_of_q_to_Gr(
    q, I_q, comp, r,
    wavelength_A=0.1665, sigma_intensity=sigma_I,
    compton=True, q_max=22.0,
)

Conventions

Default is the Faber-Ziman total structure factor (X-ray, neutral-atom form factors), matching the PDFgetX3 default. S(Q) → 1 as Q → ∞; G(r) = (2/π) ∫ Q[S(Q)-1] sin(Qr) W(Q) dQ. Window defaults to Lorch. Convention choice (FZ vs Keen; which of S/F/G/g/D/T to report) is intended to be settled with the experimental collaborators — see dev/PLAN.md.

See dev/PLAN.md for the phased build plan and open items.

Metadata

Release files for midas-pdf 0.3.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 midas-pdf 0.3.0
File Size Uploaded
midas_pdf-0.3.0.tar.gz 446.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for midas-pdf 0.3.0
File Interpreter ABI Platform
midas_pdf-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 869.4 kB

Release files / midas_pdf-0.3.0.tar.gz

Download URL midas_pdf-0.3.0.tar.gz
Size 446.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1d0edf019cfafa0e5b610c81c6745cca5264e368e857efe3062fc33d554b32ad
BLAKE2b-256 checksum
How to use checksums
0bb6ad40f5ee70cf77673cc952c7f0435c09809be656b2931e7f700f933063f5
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 Sep 6, 2026.

Transparency log

Release files / midas_pdf-0.3.0-py3-none-any.whl

Download URL midas_pdf-0.3.0-py3-none-any.whl
Size 423.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac8e83404ff689205e7096e26ffbec20c5206f5f491cd0d6f10d72475e4b685a
BLAKE2b-256 checksum
How to use checksums
1e25e870f2188fec92b7feb7cb74e941ec152d77cdaa88f6449c1ec25ae0c22c
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 Sep 6, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 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