diff --git a/README.md b/README.md index 0b23db7..5b34932 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,165 @@ -# BD_Fresnel_GUI +# BD Fresnel +Beam-deflection pump–probe simulator and fitting tool. A Python port of the +MATLAB `BD_Fresnel_GUI` suite. + +The program models a weak probe beam crossing a sample that has been excited by +a strong pump, propagates the perturbed probe field to a detector by Fresnel +diffraction, and computes the transmission `T` and normalised beam deflection +`ΔE/E` as a function of pump–probe delay. Measured scans can be imported and +compared against the simulation, and the result exported as data, a log, and +publication-sized figures. + +![BD Fresnel fitting a measured scan](docs/screenshot.png) + +## Features + +- Seven mechanism slots, each independently configurable, summed into the total + nonlinear response. +- Instantaneous (electronic) and non-instantaneous responses, the latter + convolved with the pulse envelope. +- Group-velocity mismatch between pump and probe handled through the walk-off + parameter `rho`. +- Excited-state absorption via a five-level population model (S₀, S₁, S₂, T₁, + T₂) solved through the sample depth for a range of radial irradiances. +- Side-by-side transmission and deflection plots with imported data overlaid. +- Optional diagnostic figures showing each mechanism's response function before + and after convolution, plus the ESA populations and beam transmissions. +- Export of the data/fit comparison, a full parameter log, and figures at + 6.5 in / 300 dpi. + +## Requirements + +- Python 3.10 or newer (developed against 3.12) +- `numpy`, `scipy`, `matplotlib`, `mpmath` +- Tkinter, which ships with most Python builds. On Debian/Ubuntu it is a + separate package: + +```sh +sudo apt install python3-tk +``` + +Install the Python dependencies with: + +```sh +pip install -r requirements.txt +``` + +## Running + +```sh +python bd_fresnel_gui.py +``` + +The window opens with the parameter panel on the left and three tabs on the +right: **Fitting**, **Diagnostics**, and **Parameter log**. + +A typical session: + +1. Set the **Data columns** to match your file, and the delimiter. +2. Press **Import…** and choose a scan. The plots show the measured data. +3. Fill in the beam, material and geometry parameters, and configure one or + more mechanisms with the **Params…** buttons. +4. Press **Fit** to run the simulation and overlay it on the data. +5. Press **Export…** to write the results. + +**Fit** stays disabled until a file is imported, and **Export** until a fit has +completed. + +Parameters are saved to `last_settings.json` beside the scripts when they +change, and restored at the next launch. The data file itself is not restored. + +## Input data format + +A delimited text file with one header line, then one row per delay point. Three +columns are required; which ones is set in the **Data columns** box, so extra +columns can be present and ignored. + +| Quantity | Units | Default column | +| --- | --- | --- | +| Delay `τ_d` | fs | 1 | +| `ΔE/E` | fractional | 2 | +| `T` | fractional (1.0 = no change) | 3 | + +The delimiter field takes a single character, `\t` for a tab, or is left blank +to split on any run of whitespace. + +## Mechanisms + +| Mechanism | Parameters | +| --- | --- | +| Electronic (both) | 2 | +| Collisional (NLR) | 3 | +| Librational (NLR) | 4 | +| Reorientational (NLR) | 3 | +| Vibrational (NLR) | 3 | +| ESA – 3 level + triplet (both) | 10 | +| Exponential rise/decay (NLA) | 3 | +| Exponential rise/decay (NLR) | 3 | +| Exponential rise/decay (both) | 4 | + +`NLR` denotes a purely refractive response, `NLA` a purely absorptive one, and +`both` a mechanism carrying each. + +## Export output + +Exporting to `_fit.txt` also writes, in the same directory: + +| File | Contents | +| --- | --- | +| `_fit.txt` | delay, data and fit for `T`, `ΔE/E` and `Δn` | +| `_fit_log.txt` | every parameter, plus a manifest of the files written | +| `_fit_combined.jpg` / `.svg` | transmission and deflection, 6.5 in at 300 dpi | +| `_fit_raw_response.jpg` | each mechanism's `R[t]` and `A[t]` | +| `_fit_convolved_response.jpg` | the same after convolution, plus the total | + +The last two appear only when *Show diagnostic plots during Fit* is ticked. + +The log records enough to reproduce a run: data columns and delimiter, the +simulation grid, every beam, material and geometry value, each mechanism with +its parameters, and the derived quantities (`n_g`, `T_lin`, `z_0`, `I_0`, +`rho`). + +## Files + +| File | Role | +| --- | --- | +| `bd_fresnel_core.py` | physics: field propagation, mechanism responses, ESA solver, parameter dataclass, settings I/O. No display dependencies. | +| `bd_fresnel_gui.py` | Tkinter interface, plotting, import/export, logging. Entry point. | +| `set_params_dialog.py` | modal dialog for entering one mechanism's parameters. | + +## Notes on the port + +The translation follows the MATLAB closely, including its array axis order, so +that intermediate results can be compared directly. Places where this port +deliberately differs are commented at the point of departure. The substantive +ones: + +- **Physical constants** are taken from `scipy.constants` rather than + transcribed. The original hard-coded `c = 299797548` in `calc_beam_params`, a + digit transposition of the correct value used elsewhere in the same codebase, + and truncated Planck's constant to seven figures. Correcting the former + shifts `rho` by about 1.7 × 10⁻⁵ relative. +- **Delay-frame consistency**: the delay grid is derived from the shifted + `τ_d`, matching what the plots and export compare against. The original used + the unshifted values, a mismatch whenever `shift ≠ 0`. +- **Diagnostic instantaneous response**: the original's diagnostic plot used + `n_2e` where its four physics branches all used `2·n_2e`, so the plotted + electronic curve was half the simulated one. The plot now matches the + simulation. +- **Dialog close**: closing the parameter dialog with the window button is + treated as OK. In the original it left the caller's `uiwait` blocked forever. + +## References + +Please cite the following when using results from this program. + +1. Reichert, M., et al. (2014). "Temporal, spectral, and polarization + dependence of the nonlinear optical response of carbon disulfide." + *Optica* **1**(6): 436. +2. Reichert, M., et al. (2014). "Temporal, spectral, and polarization + dependence of the nonlinear optical response of carbon disulfide: + supplementary material." *Optica* **1**(6): 436. +3. Ferdinandus, M. R., et al. (2013). "Beam deflection measurement of time and + polarization resolved ultrafast nonlinear refraction." *Opt. Lett.* + **38**(18): 3518–3521. diff --git a/docs/screenshot.png b/docs/screenshot.png new file mode 100644 index 0000000..9f747e6 Binary files /dev/null and b/docs/screenshot.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ba1a891 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# Runtime dependencies for BD Fresnel. +# Tkinter is not listed here: it ships with CPython and is installed through +# the system package manager (python3-tk on Debian/Ubuntu), not pip. +# +# Lower bounds are what the code actually needs: +# numpy 2.0 -- np.trapezoid +# scipy 1.6 -- scipy.fft workers=, RegularGridInterpolator +# matplotlib 3.4 -- Figure.subplots, set_xticks(labels=) +numpy>=2.0 +scipy>=1.6 +matplotlib>=3.4 +mpmath>=1.2