torchspin.fitgui#

The interactive fitting panel needs the gui extra (pip install "torchspin[gui]"). TorchSpin — interactive fitting panel (torchspin.fitgui) shows it in use.

Interactive fitting panel for Jupyter (ipywidgets + matplotlib).

FitSession runs torchspin.esfit() in a background thread and collects the live progress (through FitOptions.progress); FitPanel shows parameter sliders with bounds and “fix” toggles, method/budget controls, Start/Stop/Reset buttons, and a figure with data, current best fit, residual and the RMSD trace. In JupyterLab use %matplotlib widget (ipympl) for a live canvas; with any other backend the figure is refreshed as a PNG.

Requires ipywidgets and matplotlib (pip install "torchspin[gui]").

class torchspin.fitgui.FitSession(data, model, p0, vary=None, lb=None, ub=None, options=None, names=None, progress_interval=0.5)[source]#

A fit that runs in a background thread and reports its progress.

Parameters mirror esfit() (data, model, p0, vary/lb/ub, options); names labels the parameters. start() launches the fit (esfit in a daemon thread, so the kernel stays responsive), stop() asks it to finish at the next evaluation (the result is then the best fit so far, interrupted=True), result holds the FitResult when done and history the (evaluations, best RMSD, elapsed) trace. simulate(p) evaluates the model once, scaled to the data the way esfit does (least-squares amplitude and baseline).

Bounds: with lb/ub (or neither, which defaults to ±10 % of p0) the bounds are absolute and are kept across restarts and slider moves; with vary they are p0 ± vary around the start of each run. start(vary=...) with zero entries fixes those parameters for that run only (the panel’s “fix” boxes), so a fixed parameter can be released again on the next run.

vary is not clipped at anything physical here, because a plain parameter vector carries no information about what each entry means: vary larger than p0 gives a negative lower bound, which for a linewidth or a weight lets the optimizer explore unphysical values. Pass explicit lb/ub for those parameters (lb=np.maximum(p0 - vary, floor)), or use esfit()’s dict style, where the field names are known and non-negative fields are clipped at zero as EasySpin does.

simulate(p)[source]#

Model output at p, scaled to the data like esfit (lsq amplitude + baseline).

class torchspin.fitgui.FitPanel(session, figsize=(7.0, 6.5), refresh_s=0.5, x=None, xlabel='B (mT)')[source]#

ipywidgets panel around a FitSession.

panel.show() displays the panel (or put panel.widget as the last expression of a cell — not both); panel.result / panel.p_current give the fit result and the slider values. Sliders can be moved while idle (the starting simulation is redrawn); the “fix” boxes exclude parameters from the next fit; “Sliders → start” adopts the slider values as the new starting point.

show()[source]#

Display the panel (returns None so a trailing panel.show() is shown once).

refresh()[source]#

Redraw if the session reported progress (call manually without an event loop).