Avogadro::Calc::EnergyCalculator#

class EnergyCalculator#

Subclassed by LennardJones, UFF

Public Functions

EnergyCalculator() = default#
virtual ~EnergyCalculator() = default#
virtual EnergyCalculator *newInstance() const = 0#

Create a new instance of the model. Ownership passes to the caller.

virtual std::string identifier() const = 0#
Returns:

a unique identifier for this calculator.

virtual std::string name() const = 0#
Returns:

A short translatable name for this method (e.g., MMFF94, UFF, etc.)

virtual std::string description() const = 0#
Returns:

a description of the method

inline virtual std::string userOptions() const#

Return a JSON object string describing optional user-editable settings for this model. Empty string means no user options.

inline virtual bool setUserOptions(const std::string &optionsJson)#

Set user-selected options serialized as a JSON object string.

Returns:

True on success.

virtual Core::Molecule::ElementMask elements() const = 0#

Indicate if your method only treats a subset of elements.

Returns:

an element mask corresponding to the defined subset

inline virtual bool acceptsUnitCell() const#

Indicate if your method can handle unit cells.

Returns:

true if unit cells are supported

inline virtual bool acceptsIons() const#

Indicate if your method can handle ions Many methods only treat neutral systems, either a neutral molecule or a neutral unit cell.

Returns:

true if ions are supported

inline virtual bool acceptsRadicals() const#

Indicate if your method can handle radicals Most methods only treat closed-shell molecules.

Returns:

true if radicals are supported

virtual Real value(const Eigen::VectorXd &x) = 0#

Calculate the energy for this method.

virtual void gradient(const Eigen::VectorXd &x, Eigen::VectorXd &grad)#

Calculate the gradients for this method, defaulting to numerical finite-difference methods

void finiteGradient(const Eigen::VectorXd &x, Eigen::VectorXd &grad, int accuracy = 0)#

Calculate numerical gradients for this method.

virtual Real evaluate(const Eigen::VectorXd &x, Eigen::VectorXd *grad = nullptr)#

Evaluate the energy and optionally gradients in one call.

Derived classes with efficient fused implementations should override this.

inline virtual bool supportsBatch() const#

Indicate if this method can evaluate many coordinate sets in a single call (e.g. an external script that batches frames).

When false (the default), valueBatch()/gradientBatch() simply loop over the supplied coordinate sets, calling value()/gradient() once each.

virtual std::vector<Real> valueBatch(const std::vector<Eigen::VectorXd> &coords)#

Evaluate the energy for several coordinate sets (e.g. conformers or trajectory frames).

The default implementation loops over coords calling value(). Derived classes with a true batch transport should override this.

Parameters:

coords – A vector of coordinate vectors, each of length 3 * atomCount.

Returns:

One energy per coordinate set, in the same order as coords.

virtual void gradientBatch(const std::vector<Eigen::VectorXd> &coords, std::vector<Eigen::VectorXd> &grads)#

Evaluate the gradients for several coordinate sets.

The default implementation loops over coords calling gradient(). Derived classes with a true batch transport should override this.

Parameters:
  • coords – A vector of coordinate vectors, each of length 3 * atomCount.

  • grads – Filled with one gradient vector per coordinate set, in the same order as coords (resized as needed).

virtual void hessian(const Eigen::VectorXd &x, Eigen::MatrixXd &hess)#

Calculate the Hessian matrix for this method, defaulting to numerical finite-difference methods.

void finiteHessian(const Eigen::VectorXd &x, Eigen::MatrixXd &hess, int accuracy = 0)#

Calculate numerical Hessian for this method.

void cleanGradients(Eigen::VectorXd &grad)#

Called to ‘clean’ gradients

Parameters:

grad – (e.g., for constraints)

Real constraintEnergies(const Eigen::VectorXd &x)#

Called to get the energies for the current set of constraints. which should be added to the value() method for real energies in derived classes

Returns:

the sum of the constraint energies

void constraintGradients(const Eigen::VectorXd &x, Eigen::VectorXd &grad)#

Called to get the gradients for the current set of constraints. which should be added to the gradient() method in derived classes.

Parameters:
  • x – the current coordinates

  • grad – the gradient vector to be updated with constraint gradients

std::vector<Core::Constraint> constraints() const#

Called to get the constraints for this method.

Returns:

the constraints for this method

void setConstraints(const std::vector<Core::Constraint> &constraints)#
inline void setMask(Eigen::VectorXd mask)#

Called to update the “frozen” mask (e.g., during editing)

inline Eigen::VectorXd mask() const#
Returns:

the frozen atoms mask

virtual void setMolecule(Core::Molecule *mol) = 0#

Called when the current molecule changes.

Protected Functions

void appendError(const std::string &errorString, bool newLine = true) const#

Append an error to the error string for the model.

Parameters:
  • errorString – The error to be added.

  • newLine – Add a new line after the error string?

Protected Attributes

Eigen::VectorXd m_mask#
std::vector<Core::Constraint> m_distanceConstraints#
std::vector<Core::Constraint> m_angleConstraints#
std::vector<Core::Constraint> m_torsionConstraints#
std::vector<Core::Constraint> m_outOfPlaneConstraints#