C++20 Electron + React + TypeScript CMake + vcpkg Windows · macOS · Linux

StochFit

Stochastic methods for fitting specular X-ray and neutron reflectivity data — now a modern, cross-platform, open-source rewrite.

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

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

Electron GUI (React / TypeScript) ↕ IPC (FlatBuffers) Koffi FFI (Node.js ↔ stochfit.dll / .so / .dylib) ↕ C-style exports stochfit_core (static library, C++20) ├─ StochFitHarness — top-level orchestrator, worker thread ├─ Anneal<Policy> — Greedy / SimulatedAnnealing / STUN ├─ ParrattReflectivity — recursive reflectivity, OpenMP + Q-smearing ├─ CEDP — electron density profile generation └─ levmardll — Levenberg-Marquardt post-refinement

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
PlatformRequirements
WindowsVisual Studio 2022 (C++ workload), CMake 3.21+, Node.js 24+
macOSXcode 16+ command-line tools, macOS 14+ (required for std::jthread)
LinuxCMake 3.21+, a C++20 toolchain, Node.js 24+

Full build instructions, presets, and architecture notes are in the README.

Citing StochFit

S. M. Danauskas, D. Li, M. Meron, B. Lin and K. Y. C. Lee
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).