AvogadroLibs 2.1.0-20261111
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 runEvaluateBatch (std::vector< Eigen::VectorXd > coordsList, bool computeGradient, int chunkSize)
void cancel ()

Signals

void optimizeFinished (Eigen::VectorXd positions, Eigen::VectorXd gradient, double energy, bool converged)
void evaluateFinished (Eigen::VectorXd gradient, double energy)
void batchProgress (int done, int total)
void evaluateBatchFinished (std::vector< double > energies, std::vector< Eigen::VectorXd > gradients)
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::Core::Molecule, molSnapshot),
Q_ARG(Eigen::VectorXd, mask),
Q_ARG(std::vector<Avogadro::Core::Constraint>, constraints));
Definition energycalculator.h:28
The Molecule class represents a chemical molecule.
Definition core/molecule.h:50

Member Function Documentation

◆ optimizeFinished

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

Emitted after each optimization chunk completes.

Parameters
positionsThe updated coordinate vector.
gradientThe gradient at the new positions.
energyThe energy at the new positions.
convergedTrue if optimization could not continue.

◆ evaluateFinished

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

Emitted after a one-shot energy/gradient evaluation.

Parameters
gradientThe gradient vector (empty if not requested).
energyThe computed energy.

◆ batchProgress

void batchProgress ( int done,
int total )
signal

Emitted after each chunk of a batch evaluation completes.

Parameters
doneNumber of coordinate sets evaluated so far.
totalTotal number of coordinate sets in the batch.

◆ evaluateBatchFinished

void evaluateBatchFinished ( std::vector< double > energies,
std::vector< Eigen::VectorXd > gradients )
signal

Emitted after a batch energy/gradient evaluation completes (or is cancelled, in which case the vectors hold the partial results computed before cancellation).

Parameters
energiesOne energy per coordinate set.
gradientsOne gradient per coordinate set (empty if not requested).

◆ 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.

◆ runEvaluateBatch

void runEvaluateBatch ( std::vector< Eigen::VectorXd > coordsList,
bool computeGradient,
int chunkSize )
slot

Evaluate energy (and optionally gradient) for many coordinate sets.

The batch is split into chunks of chunkSize frames so a large trajectory never builds one giant wire buffer / model batch and so progress can be reported and cancellation honored between chunks.

Parameters
coordsListOne coordinate vector per set (each 3 * atomCount long).
computeGradientRequest gradients in addition to energies.
chunkSizeFrames per chunk; <= 0 selects a memory-bounded default.

◆ 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: