What is StochFit
StochFit fits specular X-ray and neutron reflectivity curves using simulated-annealing-based stochastic optimization, with both model-independent (electron density profile) and model-dependent (box model) fitting. It provides an interactive GUI for building a layer model, running the fit live, and inspecting the resulting reflectivity and density profile.
A ground-up modernization
The original StochFit (2008–2013) was a Windows-only .NET application. The current codebase is a full rewrite: a native C++20 computation core, a cross-platform Electron/React GUI, and a reproducible CMake + vcpkg build — while preserving the same underlying stochastic fitting algorithms described in the original paper.
Rebuilt computation core
Simulated annealing (Greedy / SA / STUN policies), unified Parratt recursion, and electron density profile generation reimplemented in modern, OpenMP-parallel C++20 with optional GPU acceleration hooks.
Cross-platform GUI
Electron + React + TypeScript replaces the old WinForms UI, driven by a FlatBuffers-serialized FFI bridge into the native library — runs on Windows, macOS, and Linux.
Standardized build
CMake 3.21+ with named presets and vcpkg-managed dependencies (LAPACK, levmar, FlatBuffers) replace hand-maintained Visual Studio project files and vendored DLLs.
Real test coverage
GTest-based regression tests for the reflectivity math and fitting harness, plus a standalone console utility (mirefl) for manual spot-checks — the original shipped with none.
Notable fixes since the last public release
- Fixed a heap buffer overflow when Q critical-edge / high-Q offsets were nonzero during simulated annealing
- Fixed reflectivity offset handling so the full data range is displayed and saved regardless of Q offsets
- Fixed a null-pointer crash path when initialization failed early in the fitting harness
- Worker thread exceptions are now caught and reported instead of silently crashing the process
- Fixed session save/resume state (temperature, roughness, absorption) that had been miscomputed in the legacy port
- Replaced blocking data polling with a bounded wait, eliminating a GUI freeze when the fitting thread stalled
- Fixed a macOS arm64 crash in the LevMar covariance solver caused by an integer-width mismatch in the LAPACK bridge
- General clang-tidy / clang-format cleanup and compiler-warning fixes across the C++ core
Looking for the legacy .NET releases (1.6.5 / 1.7.0)? They're still archived on SourceForge, but are unmaintained — the current, actively developed releases are on GitHub.
Architecture
Building from source
Builds use CMake 3.21+ with named presets; dependencies are managed by vcpkg and bootstrapped automatically on first configure.
# Windows cmake --preset windows cmake --build --preset windows --target stochfit_shared # macOS / Linux cmake --preset default cmake --build --preset default --target stochfit_shared # GUI (Electron) cd gui npm install npm start # dev mode with hot reload npm run make # package a distributable installer
| Platform | Requirements |
|---|---|
| Windows | Visual Studio 2022 (C++ workload), CMake 3.21+, Node.js 24+ |
| macOS | Xcode 16+ command-line tools, macOS 14+ (required for std::jthread) |
| Linux | CMake 3.21+, a C++20 toolchain, Node.js 24+ |
Full build instructions, presets, and architecture notes are in the README.
Citing StochFit
Stochastic fitting of specular X-ray reflectivity data using StochFit.
J. Appl. Cryst. (2008). 41, 1187–1193.
Get involved
Issues, feature requests, and pull requests are welcome on GitHub — that's now the home for all development, downloads, and bug tracking (this SourceForge page previously pointed to its own forums, which are retired).