Loading...
Searching...
No Matches
CalcWorker Class Reference

Worker object that runs EnergyCalculator computations on a dedicated QThread. More...

`#include <avogadro/qtgui/calcworker.h>`

Inheritance diagram for CalcWorker:

## Public Slots

void | initCalculator (Avogadro::Calc::EnergyCalculator *calculator, Avogadro::Core::Molecule molSnapshot, Eigen::VectorXd mask, std::vector< Avogadro::Core::Constraint > constraints)
void | runOptimizeChunk (Eigen::VectorXd positions, Avogadro::Calc::OptimizationOptions options)
void | runEvaluate (Eigen::VectorXd positions, bool computeGradient)
void | runGradient (Eigen::VectorXd positions)
void | cancel ()

## Signals

void | optimizeFinished (Eigen::VectorXd positions, Eigen::VectorXd gradient, double energy, bool converged)
void | evaluateFinished (Eigen::VectorXd gradient, double energy)
void | calculatorReady ()

## Public Member Functions

| CalcWorker (QObject *parent=nullptr)

## Detailed Description

The worker owns a cloned EnergyCalculator and a Core::Molecule snapshot. All heavy computation (energy, gradient, optimization steps) happens on the worker thread; results are delivered back to the main thread via queued signal/slot connections.

Typical usage:

auto* thread = new QThread;
auto* worker = new CalcWorker;
worker->moveToThread(thread);
connect(thread, &QThread::finished, worker, &QObject::deleteLater);
connect(thread, &QThread::finished, thread, &QObject::deleteLater);
thread->start();
// Initialize calculator on the worker thread (important for QProcess)
QMetaObject::invokeMethod(worker, "initCalculator",
Qt::QueuedConnection,
Q_ARG(Avogadro::Calc::EnergyCalculator*, calc),
Q_ARG(Avogadro::Core::Molecule, molSnapshot),
Q_ARG(Eigen::VectorXd, mask),
Q_ARG(std::vector<Avogadro::Core::Constraint>, constraints));
Avogadro::Calc::EnergyCalculator
Definition energycalculator.h:26
Avogadro::Core::Molecule
The Molecule class represents a chemical molecule.
Definition core/molecule.h:46

## Member Function Documentation

## optimizeFinished

void optimizeFinished | ( | Eigen::VectorXd | positions,
|  | Eigen::VectorXd | gradient,
|  | double | energy,
|  | bool | converged )

signal

Emitted after each optimization chunk completes.

Parameters

  positions | The updated coordinate vector.
  gradient | The gradient at the new positions.
  energy | The energy at the new positions.
  converged | True if optimization could not continue.

## evaluateFinished

void evaluateFinished | ( | Eigen::VectorXd | gradient,
|  | double | energy )

signal

Emitted after a one-shot energy/gradient evaluation.

Parameters

  gradient | The gradient vector (empty if not requested).
  energy | The computed energy.

## calculatorReady

void calculatorReady | ( |  | ) |

signal

Emitted when the calculator has been initialized on the worker thread.

## initCalculator

void initCalculator | ( | Avogadro::Calc::EnergyCalculator * | calculator,
|  | Avogadro::Core::Molecule | molSnapshot,
|  | Eigen::VectorXd | mask,
|  | std::vector< Avogadro::Core::Constraint > | constraints )

slot

Initialize the calculator on the worker thread. This MUST be called via queued connection so that setMolecule() runs on the worker thread (required for QProcess affinity in ScriptEnergy/OBMMEnergy).

Takes ownership of `calculator`.

## runOptimizeChunk

void runOptimizeChunk | ( | Eigen::VectorXd | positions,
|  | Avogadro::Calc::OptimizationOptions | options )

slot

Run a chunk of optimization iterations.

## runEvaluate

void runEvaluate | ( | Eigen::VectorXd | positions,
|  | bool | computeGradient )

slot

Run a one-shot energy and optionally gradient evaluation.

## runGradient

void runGradient | ( | Eigen::VectorXd | positions | ) |

slot

Run a one-shot gradient evaluation.

## cancel

void cancel | ( |  | ) |

slot

Request cancellation of the current computation. Thread-safe: can be called from any thread.

The documentation for this class was generated from the following file:

- calcworker.h