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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file midas_pdf-0.1.2.tar.gz.
File metadata
- Download URL: midas_pdf-0.1.2.tar.gz
- Upload date:
- Size: 452.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ab3a7260c5c4c279159740eadec507d79b76608a313782b8d8a37710ecab02
|
|
| MD5 |
4997ae7cf84bcfe960aeb7283c4c9b70
|
|
| BLAKE2b-256 |
362728597feb476ecdbeb468c3ba51a1c0e661bf806f24c0593223fa45bd9c40
|
Provenance
The following attestation bundles were made for midas_pdf-0.1.2.tar.gz:
Publisher:
python-packages.yml on marinerhemant/MIDAS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
midas_pdf-0.1.2.tar.gz -
Subject digest:
c0ab3a7260c5c4c279159740eadec507d79b76608a313782b8d8a37710ecab02 - Sigstore transparency entry: 2486687340
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@4705d0eaf22d467dc046e6e07bfa9bc35119c0cf -
Branch / Tag:
refs/tags/midas-pdf-v0.1.2 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@4705d0eaf22d467dc046e6e07bfa9bc35119c0cf -
Trigger Event:
release
-
Statement type:
File details
Details for the file midas_pdf-0.1.2-py3-none-any.whl.
File metadata
- Download URL: midas_pdf-0.1.2-py3-none-any.whl
- Upload date:
- Size: 430.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
203ffa79d19843411168dbd69db1e8a737a4e54c8d82c7574e1b1e125a0ede48
|
|
| MD5 |
499a0b45eb9929036a37fd61b4824dd6
|
|
| BLAKE2b-256 |
6bc1145fa621d14c07868ede29a3e5752c0a398f690e22797ca86dbea144b8d6
|
Provenance
The following attestation bundles were made for midas_pdf-0.1.2-py3-none-any.whl:
Publisher:
python-packages.yml on marinerhemant/MIDAS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
midas_pdf-0.1.2-py3-none-any.whl -
Subject digest:
203ffa79d19843411168dbd69db1e8a737a4e54c8d82c7574e1b1e125a0ede48 - Sigstore transparency entry: 2486687410
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@4705d0eaf22d467dc046e6e07bfa9bc35119c0cf -
Branch / Tag:
refs/tags/midas-pdf-v0.1.2 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@4705d0eaf22d467dc046e6e07bfa9bc35119c0cf -
Trigger Event:
release
-
Statement type: