midas-2d 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- midas_2d-0.1.0/LICENSE +53 -0
- midas_2d-0.1.0/PKG-INFO +178 -0
- midas_2d-0.1.0/README.md +152 -0
- midas_2d-0.1.0/midas_2d/__init__.py +211 -0
- midas_2d-0.1.0/midas_2d/active_learning.py +13 -0
- midas_2d-0.1.0/midas_2d/coherent.py +120 -0
- midas_2d-0.1.0/midas_2d/debye.py +166 -0
- midas_2d-0.1.0/midas_2d/disorder.py +166 -0
- midas_2d-0.1.0/midas_2d/dynamics.py +136 -0
- midas_2d-0.1.0/midas_2d/energy.py +62 -0
- midas_2d-0.1.0/midas_2d/ensemble.py +64 -0
- midas_2d-0.1.0/midas_2d/examples/__init__.py +0 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_coherent_rsm.py +84 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_depth_strain.py +103 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_frontier.py +109 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_md_transient_disorder.py +133 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_ml_and_detector.py +96 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_npl_fringes.py +52 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_stiffness_and_phonon.py +116 -0
- midas_2d-0.1.0/midas_2d/examples/tutorial_transport_and_md.py +131 -0
- midas_2d-0.1.0/midas_2d/forward.py +115 -0
- midas_2d-0.1.0/midas_2d/instrument.py +116 -0
- midas_2d-0.1.0/midas_2d/inverse.py +9 -0
- midas_2d-0.1.0/midas_2d/io.py +180 -0
- midas_2d-0.1.0/midas_2d/latent_dynamics.py +11 -0
- midas_2d-0.1.0/midas_2d/md_integrator.py +159 -0
- midas_2d-0.1.0/midas_2d/ml.py +40 -0
- midas_2d-0.1.0/midas_2d/multimodal.py +149 -0
- midas_2d-0.1.0/midas_2d/phonon.py +103 -0
- midas_2d-0.1.0/midas_2d/realdata.py +89 -0
- midas_2d-0.1.0/midas_2d/rocking.py +180 -0
- midas_2d-0.1.0/midas_2d/shape_factor.py +167 -0
- midas_2d-0.1.0/midas_2d/strain_profile.py +232 -0
- midas_2d-0.1.0/midas_2d/thermal_transport.py +182 -0
- midas_2d-0.1.0/midas_2d/viz.py +58 -0
- midas_2d-0.1.0/midas_2d.egg-info/PKG-INFO +178 -0
- midas_2d-0.1.0/midas_2d.egg-info/SOURCES.txt +48 -0
- midas_2d-0.1.0/midas_2d.egg-info/dependency_links.txt +1 -0
- midas_2d-0.1.0/midas_2d.egg-info/requires.txt +12 -0
- midas_2d-0.1.0/midas_2d.egg-info/top_level.txt +1 -0
- midas_2d-0.1.0/pyproject.toml +51 -0
- midas_2d-0.1.0/setup.cfg +4 -0
- midas_2d-0.1.0/tests/test_debye.py +116 -0
- midas_2d-0.1.0/tests/test_directions.py +221 -0
- midas_2d-0.1.0/tests/test_forward.py +61 -0
- midas_2d-0.1.0/tests/test_frontier.py +158 -0
- midas_2d-0.1.0/tests/test_inverse_disorder.py +219 -0
- midas_2d-0.1.0/tests/test_shape_factor.py +132 -0
- midas_2d-0.1.0/tests/test_strain_profile.py +137 -0
- midas_2d-0.1.0/tests/test_transport_md.py +147 -0
midas_2d-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Copyright (c) 2012, UChicago Argonne, LLC
|
|
2
|
+
|
|
3
|
+
All Rights Reserved
|
|
4
|
+
|
|
5
|
+
MIDAS Microstructural Imaging using Diffraction Analysis Software
|
|
6
|
+
|
|
7
|
+
Materials Physics and Engineering
|
|
8
|
+
Computational X-ray Science
|
|
9
|
+
Advanced Photon Source
|
|
10
|
+
Argonne National Laboratory
|
|
11
|
+
|
|
12
|
+
Contributing Authors:
|
|
13
|
+
Hemant Sharma (hsharma@anl.gov)
|
|
14
|
+
|
|
15
|
+
OPEN SOURCE LICENSE
|
|
16
|
+
|
|
17
|
+
Redistribution and use in source and binary forms, with or without
|
|
18
|
+
modification, are permitted provided that the following conditions are met:
|
|
19
|
+
|
|
20
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
21
|
+
this list of conditions and the following disclaimer. Software changes,
|
|
22
|
+
modifications, or derivative works, should be noted with comments and
|
|
23
|
+
the author and organization's name.
|
|
24
|
+
|
|
25
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
26
|
+
this list of conditions and the following disclaimer in the documentation
|
|
27
|
+
and/or other materials provided with the distribution.
|
|
28
|
+
|
|
29
|
+
3. Neither the names of UChicago Argonne, LLC or the Department of Energy
|
|
30
|
+
nor the names of its contributors may be used to endorse or promote
|
|
31
|
+
products derived from this software without specific prior written
|
|
32
|
+
permission.
|
|
33
|
+
|
|
34
|
+
4. The software and the end-user documentation included with the
|
|
35
|
+
redistribution, if any, must include the following acknowledgment:
|
|
36
|
+
|
|
37
|
+
"This product includes software produced by UChicago Argonne, LLC
|
|
38
|
+
under Contract No. DE-AC02-06CH11357 with the Department of Energy."
|
|
39
|
+
|
|
40
|
+
****************************************************************************
|
|
41
|
+
|
|
42
|
+
DISCLAIMER
|
|
43
|
+
|
|
44
|
+
THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND.
|
|
45
|
+
|
|
46
|
+
Neither the United States GOVERNMENT, nor the United States Department
|
|
47
|
+
of Energy, NOR UChicago Argonne, LLC, nor any of their employees, makes
|
|
48
|
+
any warranty, express or implied, or assumes any legal liability or
|
|
49
|
+
responsibility for the accuracy, completeness, or usefulness of any
|
|
50
|
+
information, data, apparatus, product, or process disclosed, or
|
|
51
|
+
represents that its use would not infringe privately owned rights.
|
|
52
|
+
|
|
53
|
+
****************************************************************************
|
midas_2d-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: midas-2d
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Differentiable diffraction for 2D / few-layer & ultrafast experiments: finite-size interference (Laue oscillations), crystal-truncation rods, and rocking curves on top of midas-hkls.
|
|
5
|
+
Author-email: Hemant Sharma <hsharma@anl.gov>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.20
|
|
16
|
+
Requires-Dist: torch>=2.0
|
|
17
|
+
Requires-Dist: midas-hkls>=0.5
|
|
18
|
+
Requires-Dist: midas-pink>=0.1
|
|
19
|
+
Requires-Dist: midas-invert>=0.1
|
|
20
|
+
Provides-Extra: viz
|
|
21
|
+
Requires-Dist: matplotlib>=3.5; extra == "viz"
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Requires-Dist: matplotlib>=3.5; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# midas-2d
|
|
28
|
+
|
|
29
|
+
Differentiable diffraction for **2D / few-layer & ultrafast** experiments,
|
|
30
|
+
built on `midas-hkls` (structure factors, form factors, lattice math, HKL
|
|
31
|
+
enumeration) and `midas-pink` (energy spectrum). All forward paths are
|
|
32
|
+
torch-differentiable and run on CPU / CUDA / MPS.
|
|
33
|
+
|
|
34
|
+
See `../MIDAS_2D_ULTRAFAST_DIFFRACTION_PLAN.md` for the full phased plan and the
|
|
35
|
+
collaborator-driven scope (Schaller/Flanders ultrafast nanoplatelets;
|
|
36
|
+
Hruszkewycz BCDI; Cherukara ML inversion; Sankaranarayanan MD).
|
|
37
|
+
|
|
38
|
+
## Status: Phases 1-4 implemented (38 tests, MPS/CPU verified)
|
|
39
|
+
|
|
40
|
+
### Phase 1 -- finite-size forward core
|
|
41
|
+
- **`shape_factor`** -- Laue interference `|S(q)|^2 = prod sin^2(N_i pi x_i)/
|
|
42
|
+
sin^2(pi x_i)` (thickness fringes / Laue oscillations), its `N -> inf`
|
|
43
|
+
crystal-truncation-rod limit, `nanoplatelet_rod`. Differentiable in a
|
|
44
|
+
real-valued layer count `N`, with finite/correct gradients at the Bragg peak.
|
|
45
|
+
- **`forward`** -- continuous-q structure factor `F(q)` (reuses `midas-hkls`
|
|
46
|
+
form-factor / metric / DWF physics, no integer rounding), assembled into
|
|
47
|
+
`I(q) = |F|^2 . |S|^2 . Lp`.
|
|
48
|
+
- **`energy`** -- swappable mono/pink/white via `midas_pink.ParameterisedSpectrum`.
|
|
49
|
+
- **`io`** -- zinc-blende CdSe builder.
|
|
50
|
+
|
|
51
|
+
### Phase 3 -- MD-coupled engine (`debye`) *(the novel core)*
|
|
52
|
+
Diffraction straight from atomic coordinates, **differentiable w.r.t. the atom
|
|
53
|
+
positions**:
|
|
54
|
+
- `coherent_amplitude` / `coherent_intensity` -- oriented `|sum f e^{iQ.r}|^2`
|
|
55
|
+
(reproduces the Phase-1 analytic fringes to 2e-3 -- cross-checked).
|
|
56
|
+
- `debye_intensity` -- orientationally-averaged Debye equation (colloidal case).
|
|
57
|
+
- `ensemble_intensity` -- average over MD frames; **the spread of coordinates
|
|
58
|
+
*is* the disorder**, so anisotropic Debye-Waller falloff emerges with no DWF
|
|
59
|
+
assumed.
|
|
60
|
+
- `io.cdse_supercell`, `io.load_xyz_frames` -- explicit structures / trajectories.
|
|
61
|
+
|
|
62
|
+
### Phase 2 -- transient anisotropic disorder, rocking, inversion, UQ
|
|
63
|
+
- **`disorder`** -- `AnisotropicMSD` / `TransientMSD` (fittable, time-resolved
|
|
64
|
+
out-of-plane vs in-plane MSD) and `msd_tensor_from_frames` (read the same
|
|
65
|
+
tensor off an MD trajectory -- closes the loop with `debye`).
|
|
66
|
+
- **`rocking`** -- `rocking_curve`, `fwhm`, `thickness_from_fwhm` (FWHM ~ 0.886/N),
|
|
67
|
+
`reciprocal_space_map`; rod models from either the analytic or MD forward.
|
|
68
|
+
- **`inverse`** -- `fit` (Adam/L-BFGS), `cosine_loss` (smooth scale-invariant
|
|
69
|
+
shape loss), `laplace_uncertainty` (Hessian-at-optimum error bars).
|
|
70
|
+
|
|
71
|
+
### Phase 4 -- coherent / BCDI (`coherent`)
|
|
72
|
+
- `coherent_speckle`, `bcdi_forward` (`|FFT(psi)|^2`), and `phase_retrieval`
|
|
73
|
+
(autograd phase retrieval inside a support -- the differentiable ER/HIO
|
|
74
|
+
alternative and a slot for learned priors).
|
|
75
|
+
|
|
76
|
+
### Diffraction-as-a-loss-on-dynamics (`dynamics`) *(novel closure)*
|
|
77
|
+
- `thermal_ensemble` -- differentiable thermal cloud from anisotropic spring
|
|
78
|
+
constants (reparameterisation trick), `stiffness_from_msd` (equipartition),
|
|
79
|
+
`recover_stiffness` -- fit `(k_par, k_perp)` straight from diffraction, so a
|
|
80
|
+
transient drop in `k_perp` (lattice softening) is read off the patterns.
|
|
81
|
+
|
|
82
|
+
### Coherent phonons (`phonon`)
|
|
83
|
+
- `strain_wave`, `bragg_timeseries`, `fit_coherent_phonon` -- a damped
|
|
84
|
+
out-of-plane breathing mode modulates a Bragg reflection; recover its
|
|
85
|
+
frequency, damping and amplitude from the time series.
|
|
86
|
+
|
|
87
|
+
### Amortised ML inference (`ml`)
|
|
88
|
+
- `make_dataset` (forward model = data generator), `ParameterMLP`,
|
|
89
|
+
`train_surrogate` -- one network pass maps a pattern to {N3, u_perp}
|
|
90
|
+
(held-out N3 MAE ~0.07 cell).
|
|
91
|
+
|
|
92
|
+
### Instrument realism + real data (`instrument`, `realdata`)
|
|
93
|
+
- `project_to_detector` (Ewald-correct), `solid_angle_polarization`,
|
|
94
|
+
`poisson_nll` / `add_poisson_noise`, `resolution_convolve`;
|
|
95
|
+
`load_profile` and `debye_reference_numpy` (independent NumPy Debye oracle,
|
|
96
|
+
agrees with the torch path to 1e-14).
|
|
97
|
+
|
|
98
|
+
### Multi-reflection (`rocking.thickness_loss_scan`)
|
|
99
|
+
- Joint thickness loss over several rods -- breaks the single-rod thickness
|
|
100
|
+
multimodality (one basin per integer N3) to a unique minimum.
|
|
101
|
+
|
|
102
|
+
### Depth-resolved strain + unified thermal (`strain_profile`)
|
|
103
|
+
- A per-atom out-of-plane displacement `u_z(z)` makes the Bragg peak asymmetric
|
|
104
|
+
(the d-spacing-vs-depth signal); `recover_depth_strain` inverts the asymmetric
|
|
105
|
+
peak back to the depth profile. `thermal_rod` drives BOTH the shift (thermal
|
|
106
|
+
expansion) and the amplitude (local Debye-Waller) from one `T(z)` field.
|
|
107
|
+
Builders: `linear_strain`, `exponential_strain`, `acoustic_pulse` (Thomsen).
|
|
108
|
+
|
|
109
|
+
### Diffraction -> transport/coupling coefficients (`thermal_transport`)
|
|
110
|
+
- `two_temperature_model` + `fit_electron_phonon_coupling` -- recover the
|
|
111
|
+
**electron-phonon coupling g** from the Bragg-amplitude transient.
|
|
112
|
+
- `heat_diffusion_1d` + `fit_thermal_diffusivity` -- recover the **thermal
|
|
113
|
+
diffusivity kappa** from the depth-resolved strain front.
|
|
114
|
+
|
|
115
|
+
### Differentiable MD -> learn the potential (`md_integrator`)
|
|
116
|
+
- `velocity_verlet` (autograd through every step), `bragg_from_trajectory`,
|
|
117
|
+
`coherent_mode_kick`, `recover_potential_from_movie` -- recover the
|
|
118
|
+
**interatomic spring constant** by differentiating an MD trajectory to match a
|
|
119
|
+
Bragg-intensity oscillation. (Uses a non-uniform standing-wave mode: a
|
|
120
|
+
uniform kick is a rigid translation that |A|^2 cannot see; the intensity rings
|
|
121
|
+
at 2*omega.)
|
|
122
|
+
|
|
123
|
+
### Frontier tier
|
|
124
|
+
- **`multimodal`** -- joint X-ray + optical (transient-absorption) inversion.
|
|
125
|
+
`fit_multimodal` recovers the **deformation potential Xi** and thermal
|
|
126
|
+
coefficient; the optical channel pins the carrier dynamics. (Honest finding:
|
|
127
|
+
when electronic/thermal timescales are well separated, the X-ray strain shape
|
|
128
|
+
alone already localizes Xi -- see `xray_only_degeneracy`.)
|
|
129
|
+
- **`latent_dynamics`** -- `discover_eom` recovers the equation of motion
|
|
130
|
+
(e.g. a damped phonon `v_dot = -omega^2 x - gamma v`) from a structural
|
|
131
|
+
trajectory by sparse regression (SINDy/STLSQ), *without assuming the form*;
|
|
132
|
+
the spurious cubic term is thresholded to zero.
|
|
133
|
+
- **`ensemble`** -- `recover_thickness_distribution`: deconvolve the thickness
|
|
134
|
+
*distribution* of a polydisperse sample from the smeared fringes.
|
|
135
|
+
- **`active_learning`** -- `fisher_information` / `next_best_measurement`: rank
|
|
136
|
+
candidate delays/reflections by how much they constrain a target parameter
|
|
137
|
+
(autonomous-beamline experiment design).
|
|
138
|
+
|
|
139
|
+
### Showcase demos (write to `dev/paper/figures/`)
|
|
140
|
+
- `tutorial_npl_fringes` -- 3/4/5-monolayer Laue oscillations (fringe count = N3-1).
|
|
141
|
+
- `tutorial_md_transient_disorder` -- **anisotropic transient disordering from
|
|
142
|
+
the atoms + differentiable recovery of u_perp(t); planted = MD-derived =
|
|
143
|
+
recovered.**
|
|
144
|
+
- `tutorial_coherent_rsm` -- coherent reciprocal-space map + phase retrieval.
|
|
145
|
+
- `tutorial_stiffness_and_phonon` -- transient lattice softening k_perp(t) +
|
|
146
|
+
coherent-phonon frequency/damping, both recovered from diffraction.
|
|
147
|
+
- `tutorial_ml_and_detector` -- amortised-inference parity plot + a coherent
|
|
148
|
+
pattern Ewald-projected onto a detector with Poisson noise.
|
|
149
|
+
- `tutorial_depth_strain` -- depth-resolved lattice-displacement reconstruction
|
|
150
|
+
from an asymmetric Bragg peak (the d-spacing-vs-depth signal).
|
|
151
|
+
- `tutorial_transport_and_md` -- recover electron-phonon coupling g, thermal
|
|
152
|
+
diffusivity kappa, and interatomic stiffness k, all from diffraction.
|
|
153
|
+
- `tutorial_frontier` -- deformation potential (multi-modal), equation-of-motion
|
|
154
|
+
discovery, and ensemble thickness distribution.
|
|
155
|
+
|
|
156
|
+
## Quick start
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import torch
|
|
160
|
+
from midas_2d import cdse_supercell, coherent_intensity
|
|
161
|
+
|
|
162
|
+
# Diffraction straight from atoms, differentiable in the coordinates:
|
|
163
|
+
coords, elements, cell = cdse_supercell((8, 8, 4)) # few-layer CdSe platelet
|
|
164
|
+
coords.requires_grad_(True)
|
|
165
|
+
q = (2 * torch.pi / 6.077) * torch.tensor([[1., 1., 1.0]])
|
|
166
|
+
I = coherent_intensity(coords, elements, q) # I.backward() -> per-atom grads
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
python -m midas_2d.examples.tutorial_md_transient_disorder # the headline figure
|
|
171
|
+
pytest # 38 tests (set KMP_DUPLICATE_LIB_OK=TRUE on macOS)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Not yet implemented
|
|
175
|
+
|
|
176
|
+
- Phase 5: ML inversion / amortized-inference surrogates (uses the
|
|
177
|
+
differentiable forwards as data generators + consistency layer).
|
|
178
|
+
- Multi-reflection / multi-Bragg joint BCDI; absolute-scale spectral weighting.
|
midas_2d-0.1.0/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# midas-2d
|
|
2
|
+
|
|
3
|
+
Differentiable diffraction for **2D / few-layer & ultrafast** experiments,
|
|
4
|
+
built on `midas-hkls` (structure factors, form factors, lattice math, HKL
|
|
5
|
+
enumeration) and `midas-pink` (energy spectrum). All forward paths are
|
|
6
|
+
torch-differentiable and run on CPU / CUDA / MPS.
|
|
7
|
+
|
|
8
|
+
See `../MIDAS_2D_ULTRAFAST_DIFFRACTION_PLAN.md` for the full phased plan and the
|
|
9
|
+
collaborator-driven scope (Schaller/Flanders ultrafast nanoplatelets;
|
|
10
|
+
Hruszkewycz BCDI; Cherukara ML inversion; Sankaranarayanan MD).
|
|
11
|
+
|
|
12
|
+
## Status: Phases 1-4 implemented (38 tests, MPS/CPU verified)
|
|
13
|
+
|
|
14
|
+
### Phase 1 -- finite-size forward core
|
|
15
|
+
- **`shape_factor`** -- Laue interference `|S(q)|^2 = prod sin^2(N_i pi x_i)/
|
|
16
|
+
sin^2(pi x_i)` (thickness fringes / Laue oscillations), its `N -> inf`
|
|
17
|
+
crystal-truncation-rod limit, `nanoplatelet_rod`. Differentiable in a
|
|
18
|
+
real-valued layer count `N`, with finite/correct gradients at the Bragg peak.
|
|
19
|
+
- **`forward`** -- continuous-q structure factor `F(q)` (reuses `midas-hkls`
|
|
20
|
+
form-factor / metric / DWF physics, no integer rounding), assembled into
|
|
21
|
+
`I(q) = |F|^2 . |S|^2 . Lp`.
|
|
22
|
+
- **`energy`** -- swappable mono/pink/white via `midas_pink.ParameterisedSpectrum`.
|
|
23
|
+
- **`io`** -- zinc-blende CdSe builder.
|
|
24
|
+
|
|
25
|
+
### Phase 3 -- MD-coupled engine (`debye`) *(the novel core)*
|
|
26
|
+
Diffraction straight from atomic coordinates, **differentiable w.r.t. the atom
|
|
27
|
+
positions**:
|
|
28
|
+
- `coherent_amplitude` / `coherent_intensity` -- oriented `|sum f e^{iQ.r}|^2`
|
|
29
|
+
(reproduces the Phase-1 analytic fringes to 2e-3 -- cross-checked).
|
|
30
|
+
- `debye_intensity` -- orientationally-averaged Debye equation (colloidal case).
|
|
31
|
+
- `ensemble_intensity` -- average over MD frames; **the spread of coordinates
|
|
32
|
+
*is* the disorder**, so anisotropic Debye-Waller falloff emerges with no DWF
|
|
33
|
+
assumed.
|
|
34
|
+
- `io.cdse_supercell`, `io.load_xyz_frames` -- explicit structures / trajectories.
|
|
35
|
+
|
|
36
|
+
### Phase 2 -- transient anisotropic disorder, rocking, inversion, UQ
|
|
37
|
+
- **`disorder`** -- `AnisotropicMSD` / `TransientMSD` (fittable, time-resolved
|
|
38
|
+
out-of-plane vs in-plane MSD) and `msd_tensor_from_frames` (read the same
|
|
39
|
+
tensor off an MD trajectory -- closes the loop with `debye`).
|
|
40
|
+
- **`rocking`** -- `rocking_curve`, `fwhm`, `thickness_from_fwhm` (FWHM ~ 0.886/N),
|
|
41
|
+
`reciprocal_space_map`; rod models from either the analytic or MD forward.
|
|
42
|
+
- **`inverse`** -- `fit` (Adam/L-BFGS), `cosine_loss` (smooth scale-invariant
|
|
43
|
+
shape loss), `laplace_uncertainty` (Hessian-at-optimum error bars).
|
|
44
|
+
|
|
45
|
+
### Phase 4 -- coherent / BCDI (`coherent`)
|
|
46
|
+
- `coherent_speckle`, `bcdi_forward` (`|FFT(psi)|^2`), and `phase_retrieval`
|
|
47
|
+
(autograd phase retrieval inside a support -- the differentiable ER/HIO
|
|
48
|
+
alternative and a slot for learned priors).
|
|
49
|
+
|
|
50
|
+
### Diffraction-as-a-loss-on-dynamics (`dynamics`) *(novel closure)*
|
|
51
|
+
- `thermal_ensemble` -- differentiable thermal cloud from anisotropic spring
|
|
52
|
+
constants (reparameterisation trick), `stiffness_from_msd` (equipartition),
|
|
53
|
+
`recover_stiffness` -- fit `(k_par, k_perp)` straight from diffraction, so a
|
|
54
|
+
transient drop in `k_perp` (lattice softening) is read off the patterns.
|
|
55
|
+
|
|
56
|
+
### Coherent phonons (`phonon`)
|
|
57
|
+
- `strain_wave`, `bragg_timeseries`, `fit_coherent_phonon` -- a damped
|
|
58
|
+
out-of-plane breathing mode modulates a Bragg reflection; recover its
|
|
59
|
+
frequency, damping and amplitude from the time series.
|
|
60
|
+
|
|
61
|
+
### Amortised ML inference (`ml`)
|
|
62
|
+
- `make_dataset` (forward model = data generator), `ParameterMLP`,
|
|
63
|
+
`train_surrogate` -- one network pass maps a pattern to {N3, u_perp}
|
|
64
|
+
(held-out N3 MAE ~0.07 cell).
|
|
65
|
+
|
|
66
|
+
### Instrument realism + real data (`instrument`, `realdata`)
|
|
67
|
+
- `project_to_detector` (Ewald-correct), `solid_angle_polarization`,
|
|
68
|
+
`poisson_nll` / `add_poisson_noise`, `resolution_convolve`;
|
|
69
|
+
`load_profile` and `debye_reference_numpy` (independent NumPy Debye oracle,
|
|
70
|
+
agrees with the torch path to 1e-14).
|
|
71
|
+
|
|
72
|
+
### Multi-reflection (`rocking.thickness_loss_scan`)
|
|
73
|
+
- Joint thickness loss over several rods -- breaks the single-rod thickness
|
|
74
|
+
multimodality (one basin per integer N3) to a unique minimum.
|
|
75
|
+
|
|
76
|
+
### Depth-resolved strain + unified thermal (`strain_profile`)
|
|
77
|
+
- A per-atom out-of-plane displacement `u_z(z)` makes the Bragg peak asymmetric
|
|
78
|
+
(the d-spacing-vs-depth signal); `recover_depth_strain` inverts the asymmetric
|
|
79
|
+
peak back to the depth profile. `thermal_rod` drives BOTH the shift (thermal
|
|
80
|
+
expansion) and the amplitude (local Debye-Waller) from one `T(z)` field.
|
|
81
|
+
Builders: `linear_strain`, `exponential_strain`, `acoustic_pulse` (Thomsen).
|
|
82
|
+
|
|
83
|
+
### Diffraction -> transport/coupling coefficients (`thermal_transport`)
|
|
84
|
+
- `two_temperature_model` + `fit_electron_phonon_coupling` -- recover the
|
|
85
|
+
**electron-phonon coupling g** from the Bragg-amplitude transient.
|
|
86
|
+
- `heat_diffusion_1d` + `fit_thermal_diffusivity` -- recover the **thermal
|
|
87
|
+
diffusivity kappa** from the depth-resolved strain front.
|
|
88
|
+
|
|
89
|
+
### Differentiable MD -> learn the potential (`md_integrator`)
|
|
90
|
+
- `velocity_verlet` (autograd through every step), `bragg_from_trajectory`,
|
|
91
|
+
`coherent_mode_kick`, `recover_potential_from_movie` -- recover the
|
|
92
|
+
**interatomic spring constant** by differentiating an MD trajectory to match a
|
|
93
|
+
Bragg-intensity oscillation. (Uses a non-uniform standing-wave mode: a
|
|
94
|
+
uniform kick is a rigid translation that |A|^2 cannot see; the intensity rings
|
|
95
|
+
at 2*omega.)
|
|
96
|
+
|
|
97
|
+
### Frontier tier
|
|
98
|
+
- **`multimodal`** -- joint X-ray + optical (transient-absorption) inversion.
|
|
99
|
+
`fit_multimodal` recovers the **deformation potential Xi** and thermal
|
|
100
|
+
coefficient; the optical channel pins the carrier dynamics. (Honest finding:
|
|
101
|
+
when electronic/thermal timescales are well separated, the X-ray strain shape
|
|
102
|
+
alone already localizes Xi -- see `xray_only_degeneracy`.)
|
|
103
|
+
- **`latent_dynamics`** -- `discover_eom` recovers the equation of motion
|
|
104
|
+
(e.g. a damped phonon `v_dot = -omega^2 x - gamma v`) from a structural
|
|
105
|
+
trajectory by sparse regression (SINDy/STLSQ), *without assuming the form*;
|
|
106
|
+
the spurious cubic term is thresholded to zero.
|
|
107
|
+
- **`ensemble`** -- `recover_thickness_distribution`: deconvolve the thickness
|
|
108
|
+
*distribution* of a polydisperse sample from the smeared fringes.
|
|
109
|
+
- **`active_learning`** -- `fisher_information` / `next_best_measurement`: rank
|
|
110
|
+
candidate delays/reflections by how much they constrain a target parameter
|
|
111
|
+
(autonomous-beamline experiment design).
|
|
112
|
+
|
|
113
|
+
### Showcase demos (write to `dev/paper/figures/`)
|
|
114
|
+
- `tutorial_npl_fringes` -- 3/4/5-monolayer Laue oscillations (fringe count = N3-1).
|
|
115
|
+
- `tutorial_md_transient_disorder` -- **anisotropic transient disordering from
|
|
116
|
+
the atoms + differentiable recovery of u_perp(t); planted = MD-derived =
|
|
117
|
+
recovered.**
|
|
118
|
+
- `tutorial_coherent_rsm` -- coherent reciprocal-space map + phase retrieval.
|
|
119
|
+
- `tutorial_stiffness_and_phonon` -- transient lattice softening k_perp(t) +
|
|
120
|
+
coherent-phonon frequency/damping, both recovered from diffraction.
|
|
121
|
+
- `tutorial_ml_and_detector` -- amortised-inference parity plot + a coherent
|
|
122
|
+
pattern Ewald-projected onto a detector with Poisson noise.
|
|
123
|
+
- `tutorial_depth_strain` -- depth-resolved lattice-displacement reconstruction
|
|
124
|
+
from an asymmetric Bragg peak (the d-spacing-vs-depth signal).
|
|
125
|
+
- `tutorial_transport_and_md` -- recover electron-phonon coupling g, thermal
|
|
126
|
+
diffusivity kappa, and interatomic stiffness k, all from diffraction.
|
|
127
|
+
- `tutorial_frontier` -- deformation potential (multi-modal), equation-of-motion
|
|
128
|
+
discovery, and ensemble thickness distribution.
|
|
129
|
+
|
|
130
|
+
## Quick start
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import torch
|
|
134
|
+
from midas_2d import cdse_supercell, coherent_intensity
|
|
135
|
+
|
|
136
|
+
# Diffraction straight from atoms, differentiable in the coordinates:
|
|
137
|
+
coords, elements, cell = cdse_supercell((8, 8, 4)) # few-layer CdSe platelet
|
|
138
|
+
coords.requires_grad_(True)
|
|
139
|
+
q = (2 * torch.pi / 6.077) * torch.tensor([[1., 1., 1.0]])
|
|
140
|
+
I = coherent_intensity(coords, elements, q) # I.backward() -> per-atom grads
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
python -m midas_2d.examples.tutorial_md_transient_disorder # the headline figure
|
|
145
|
+
pytest # 38 tests (set KMP_DUPLICATE_LIB_OK=TRUE on macOS)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Not yet implemented
|
|
149
|
+
|
|
150
|
+
- Phase 5: ML inversion / amortized-inference surrogates (uses the
|
|
151
|
+
differentiable forwards as data generators + consistency layer).
|
|
152
|
+
- Multi-reflection / multi-Bragg joint BCDI; absolute-scale spectral weighting.
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""midas-2d -- differentiable diffraction for 2D / few-layer & ultrafast work.
|
|
2
|
+
|
|
3
|
+
Phase 1 (finite-size forward core):
|
|
4
|
+
from midas_2d import (
|
|
5
|
+
interference_factor, truncation_rod, nanoplatelet_rod,
|
|
6
|
+
rod_intensity, structure_factor_q,
|
|
7
|
+
cdse_zincblende, build_crystal_tensor,
|
|
8
|
+
make_spectrum, monochromatic,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
Builds on midas-hkls (structure factors, form factors, lattice, hkl gen) and
|
|
12
|
+
midas-pink (energy spectrum). See MIDAS_2D_ULTRAFAST_DIFFRACTION_PLAN.md.
|
|
13
|
+
"""
|
|
14
|
+
from .coherent import bcdi_forward, coherent_speckle, phase_retrieval
|
|
15
|
+
from .debye import (
|
|
16
|
+
atomic_form_factors,
|
|
17
|
+
coherent_amplitude,
|
|
18
|
+
coherent_intensity,
|
|
19
|
+
debye_intensity,
|
|
20
|
+
ensemble_intensity,
|
|
21
|
+
)
|
|
22
|
+
from .disorder import (
|
|
23
|
+
AnisotropicMSD,
|
|
24
|
+
TransientMSD,
|
|
25
|
+
dwf_amplitude,
|
|
26
|
+
msd_tensor_from_frames,
|
|
27
|
+
)
|
|
28
|
+
from .dynamics import (
|
|
29
|
+
msd_from_stiffness,
|
|
30
|
+
recover_stiffness,
|
|
31
|
+
stiffness_from_msd,
|
|
32
|
+
thermal_ensemble,
|
|
33
|
+
)
|
|
34
|
+
from .energy import make_spectrum, monochromatic
|
|
35
|
+
from .instrument import (
|
|
36
|
+
add_poisson_noise,
|
|
37
|
+
poisson_nll,
|
|
38
|
+
project_to_detector,
|
|
39
|
+
resolution_convolve,
|
|
40
|
+
solid_angle_polarization,
|
|
41
|
+
)
|
|
42
|
+
from .inverse import cosine_loss, fit, laplace_uncertainty, relative_l2_loss
|
|
43
|
+
from .ml import ParameterMLP, make_dataset, train_surrogate
|
|
44
|
+
from .phonon import (
|
|
45
|
+
apply_out_of_plane_strain,
|
|
46
|
+
bragg_timeseries,
|
|
47
|
+
fit_coherent_phonon,
|
|
48
|
+
strain_wave,
|
|
49
|
+
)
|
|
50
|
+
from .realdata import debye_reference_numpy, load_profile
|
|
51
|
+
from .active_learning import (
|
|
52
|
+
fisher_information,
|
|
53
|
+
next_best_measurement,
|
|
54
|
+
rank_measurements,
|
|
55
|
+
sensitivity,
|
|
56
|
+
)
|
|
57
|
+
from .ensemble import polydisperse_rod, recover_thickness_distribution
|
|
58
|
+
from .latent_dynamics import discover_eom, integrate_latent_ode, library_terms
|
|
59
|
+
from .md_integrator import (
|
|
60
|
+
bragg_from_trajectory,
|
|
61
|
+
coherent_mode_kick,
|
|
62
|
+
harmonic_force,
|
|
63
|
+
recover_potential_from_movie,
|
|
64
|
+
velocity_verlet,
|
|
65
|
+
)
|
|
66
|
+
from .multimodal import (
|
|
67
|
+
carrier_density,
|
|
68
|
+
fit_multimodal,
|
|
69
|
+
lattice_temperature_from_carriers,
|
|
70
|
+
optical_signal,
|
|
71
|
+
strain_two_channel,
|
|
72
|
+
xray_only_degeneracy,
|
|
73
|
+
)
|
|
74
|
+
from .strain_profile import (
|
|
75
|
+
acoustic_pulse,
|
|
76
|
+
apply_depth_displacement,
|
|
77
|
+
depth_resolved_amplitude,
|
|
78
|
+
depth_resolved_intensity,
|
|
79
|
+
exponential_strain,
|
|
80
|
+
linear_strain,
|
|
81
|
+
recover_depth_strain,
|
|
82
|
+
strain_to_displacement,
|
|
83
|
+
temperature_to_displacement,
|
|
84
|
+
temperature_to_msd,
|
|
85
|
+
thermal_rod,
|
|
86
|
+
)
|
|
87
|
+
from .thermal_transport import (
|
|
88
|
+
fit_electron_phonon_coupling,
|
|
89
|
+
fit_thermal_diffusivity,
|
|
90
|
+
heat_diffusion_1d,
|
|
91
|
+
lattice_T_to_intensity_ratio,
|
|
92
|
+
two_temperature_model,
|
|
93
|
+
)
|
|
94
|
+
from .rocking import (
|
|
95
|
+
analytic_rod_model,
|
|
96
|
+
fwhm,
|
|
97
|
+
md_rod_model,
|
|
98
|
+
reciprocal_space_map,
|
|
99
|
+
rocking_curve,
|
|
100
|
+
thickness_from_fwhm,
|
|
101
|
+
thickness_loss_scan,
|
|
102
|
+
)
|
|
103
|
+
from .forward import rod_intensity, structure_factor_q
|
|
104
|
+
from .io import (
|
|
105
|
+
build_crystal_tensor,
|
|
106
|
+
cdse_supercell,
|
|
107
|
+
cdse_zincblende,
|
|
108
|
+
load_xyz_frames,
|
|
109
|
+
supercell_from_crystal,
|
|
110
|
+
)
|
|
111
|
+
from .shape_factor import (
|
|
112
|
+
interference_factor,
|
|
113
|
+
laue_interference_1d,
|
|
114
|
+
nanoplatelet_rod,
|
|
115
|
+
truncation_rod,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
__version__ = "0.1.0"
|
|
119
|
+
|
|
120
|
+
__all__ = [
|
|
121
|
+
"interference_factor",
|
|
122
|
+
"laue_interference_1d",
|
|
123
|
+
"nanoplatelet_rod",
|
|
124
|
+
"truncation_rod",
|
|
125
|
+
"rod_intensity",
|
|
126
|
+
"structure_factor_q",
|
|
127
|
+
"cdse_zincblende",
|
|
128
|
+
"build_crystal_tensor",
|
|
129
|
+
"cdse_supercell",
|
|
130
|
+
"supercell_from_crystal",
|
|
131
|
+
"load_xyz_frames",
|
|
132
|
+
"atomic_form_factors",
|
|
133
|
+
"coherent_amplitude",
|
|
134
|
+
"coherent_intensity",
|
|
135
|
+
"debye_intensity",
|
|
136
|
+
"ensemble_intensity",
|
|
137
|
+
"AnisotropicMSD",
|
|
138
|
+
"TransientMSD",
|
|
139
|
+
"dwf_amplitude",
|
|
140
|
+
"msd_tensor_from_frames",
|
|
141
|
+
"analytic_rod_model",
|
|
142
|
+
"md_rod_model",
|
|
143
|
+
"rocking_curve",
|
|
144
|
+
"fwhm",
|
|
145
|
+
"thickness_from_fwhm",
|
|
146
|
+
"reciprocal_space_map",
|
|
147
|
+
"thickness_loss_scan",
|
|
148
|
+
"fit",
|
|
149
|
+
"laplace_uncertainty",
|
|
150
|
+
"relative_l2_loss",
|
|
151
|
+
"cosine_loss",
|
|
152
|
+
"coherent_speckle",
|
|
153
|
+
"bcdi_forward",
|
|
154
|
+
"phase_retrieval",
|
|
155
|
+
"stiffness_from_msd",
|
|
156
|
+
"msd_from_stiffness",
|
|
157
|
+
"thermal_ensemble",
|
|
158
|
+
"recover_stiffness",
|
|
159
|
+
"strain_wave",
|
|
160
|
+
"apply_out_of_plane_strain",
|
|
161
|
+
"bragg_timeseries",
|
|
162
|
+
"fit_coherent_phonon",
|
|
163
|
+
"make_dataset",
|
|
164
|
+
"ParameterMLP",
|
|
165
|
+
"train_surrogate",
|
|
166
|
+
"project_to_detector",
|
|
167
|
+
"solid_angle_polarization",
|
|
168
|
+
"poisson_nll",
|
|
169
|
+
"add_poisson_noise",
|
|
170
|
+
"resolution_convolve",
|
|
171
|
+
"load_profile",
|
|
172
|
+
"debye_reference_numpy",
|
|
173
|
+
"depth_resolved_amplitude",
|
|
174
|
+
"depth_resolved_intensity",
|
|
175
|
+
"apply_depth_displacement",
|
|
176
|
+
"linear_strain",
|
|
177
|
+
"exponential_strain",
|
|
178
|
+
"acoustic_pulse",
|
|
179
|
+
"strain_to_displacement",
|
|
180
|
+
"temperature_to_displacement",
|
|
181
|
+
"temperature_to_msd",
|
|
182
|
+
"thermal_rod",
|
|
183
|
+
"recover_depth_strain",
|
|
184
|
+
"two_temperature_model",
|
|
185
|
+
"lattice_T_to_intensity_ratio",
|
|
186
|
+
"fit_electron_phonon_coupling",
|
|
187
|
+
"heat_diffusion_1d",
|
|
188
|
+
"fit_thermal_diffusivity",
|
|
189
|
+
"harmonic_force",
|
|
190
|
+
"velocity_verlet",
|
|
191
|
+
"bragg_from_trajectory",
|
|
192
|
+
"coherent_mode_kick",
|
|
193
|
+
"recover_potential_from_movie",
|
|
194
|
+
"carrier_density",
|
|
195
|
+
"lattice_temperature_from_carriers",
|
|
196
|
+
"strain_two_channel",
|
|
197
|
+
"optical_signal",
|
|
198
|
+
"fit_multimodal",
|
|
199
|
+
"xray_only_degeneracy",
|
|
200
|
+
"library_terms",
|
|
201
|
+
"integrate_latent_ode",
|
|
202
|
+
"discover_eom",
|
|
203
|
+
"polydisperse_rod",
|
|
204
|
+
"recover_thickness_distribution",
|
|
205
|
+
"sensitivity",
|
|
206
|
+
"fisher_information",
|
|
207
|
+
"rank_measurements",
|
|
208
|
+
"next_best_measurement",
|
|
209
|
+
"make_spectrum",
|
|
210
|
+
"monochromatic",
|
|
211
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Experiment design -- now provided by the shared ``midas_invert`` leaf.
|
|
2
|
+
|
|
3
|
+
Thin re-export so existing ``midas_2d`` imports are unchanged.
|
|
4
|
+
"""
|
|
5
|
+
from midas_invert.design import (
|
|
6
|
+
fisher_information,
|
|
7
|
+
next_best_measurement,
|
|
8
|
+
rank_measurements,
|
|
9
|
+
sensitivity,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = ["sensitivity", "fisher_information", "rank_measurements",
|
|
13
|
+
"next_best_measurement"]
|