8 #ifndef READUCT_ELEMENTARYSTEPOPTIMIZATION_ELEMENTARYSTEPOPTIMIZER_H
9 #define READUCT_ELEMENTARYSTEPOPTIMIZATION_ELEMENTARYSTEPOPTIMIZER_H
27 namespace ElementaryStepOptimization {
84 template<
class OptimizerType>
94 : _calculator(calculator), _profile(std::move(initialReactionProfile)){};
121 return std::make_shared<Utils::Settings>(_calculator.
settings());
132 const auto& elements = _profile.getMolecularSpline().getElements();
134 if (!structure || structure->getElements() != elements) {
141 auto& spline = _profile.getMolecularSpline().getBSpline();
142 auto variables = TypeConverter::getInnerControlPointMatrix(spline);
143 Eigen::VectorXd variablesVector;
144 int nRows = variables.rows();
145 int nColumns = variables.cols();
146 variablesVector = Eigen::Map<const Eigen::VectorXd>(variables.data(), nRows * nColumns);
152 auto const update = [&](
const Eigen::VectorXd& parameters,
double& value, Eigen::VectorXd& gradients) {
153 Eigen::MatrixXd variables;
154 variables = Eigen::Map<const Eigen::MatrixXd>(parameters.data(), nRows, nColumns);
157 TypeConverter::setInnerControlPoints(spline, variables);
160 profileCalculator.calculateEnergiesAndGradients(spline);
161 auto valuesAlongSpline = profileCalculator.valuesAlongSpline();
164 value = costCalculator.
getCost();
168 int numberInnerControlPoints = spline.controlPointCount() - 2;
169 Eigen::MatrixXd derivatives = fullDerivatives.middleRows(1, numberInnerControlPoints);
170 gradients = Eigen::Map<const Eigen::VectorXd>(derivatives.data(), nRows * nColumns);
173 _profile.getProfileEnergies() =
ProfileEnergies{profileCalculator.getCoordinates(), profileCalculator.getEnergies()};
177 auto cycles =
optimizer.optimize(variablesVector, update,
check, log);
218 #endif // READUCT_ELEMENTARYSTEPOPTIMIZER_H
virtual ~ElementaryStepOptimizerBase()=default
Virtual default destructor.
virtual void applySettings(const Settings &settings)=0
virtual const std::shared_ptr< Utils::Settings > getCalculatorSettings() const =0
Get the settings of the calculator used for the energy calculations during the optimization.
int optimize(Core::Log &log) override
Definition: ElementaryStepOptimizer.h:129
OptimizerType optimizer
The underlying optimizer (public in order to change its settings).
Definition: ElementaryStepOptimizer.h:199
virtual void setSettings(const Utils::Settings &settings)=0
Apply the given settings.
virtual std::unique_ptr< Utils::AtomCollection > getStructure() const =0
Utils::GradientBasedCheck getConvergenceCheck() const override
The underlying convergence check.
Definition: ElementaryStepOptimizer.h:197
Definition: RecurringProfileCalculator.h:33
A class to optimize reaction paths based on the B-Splines approach described in Alain Vaucher's Ph...
Definition: ElementaryStepOptimizer.h:85
The base class for all reaction path optimizers. The only purpose of this base class is to hide the t...
Definition: ElementaryStepOptimizer.h:33
virtual void setSettings(const Utils::Settings &settings) override
Apply the given settings.
Definition: ElementaryStepOptimizer.h:100
Definition: ReactionProfile.h:25
double getCost() const
Get the cost associated with a given spline (after it has been evaluated).
Definition: ReactionPathCostCalculator.h:98
const std::shared_ptr< Utils::Settings > getCalculatorSettings() const override
Get the settings of the calculator used for the energy calculations during the optimization.
Definition: ElementaryStepOptimizer.h:120
ElementaryStepOptimizer(Core::Calculator &calculator, ReactionProfile initialReactionProfile)
Construct a new TestOptimizer object.
Definition: ElementaryStepOptimizer.h:93
Definition: ReaductDefault.h:28
Definition: ProfileEnergies.h:26
virtual Utils::Settings & settings()=0
virtual Utils::Settings getSettings() const override
Get the public settings as a Utils::Settings object.
Definition: ElementaryStepOptimizer.h:110
virtual ReactionProfile & getReactionProfile()=0
Get the current reaction profile (at the end of an optimization, this is the final reaction profile)...
int numberEquidistantPoints
The number of interpolation points on the spline.
Definition: ElementaryStepOptimizer.h:208
Settings for an ElementaryStepOptimizer.
Definition: ElementaryStepOptimizerSettings.h:29
Definition: EnergiesAndGradientsAlongSpline.h:25
ReactionProfile & getReactionProfile() override
Get the current reaction profile (at the end of an optimization, this is the final reaction profile)...
Definition: ElementaryStepOptimizer.h:187
Utils::GradientBasedCheck check
The underlying convergence check (public in order to change its settings).
Definition: ElementaryStepOptimizer.h:205
Eigen::MatrixXd getCostDerivatives() const
Get the cost derivatives associated with a given spline.
Definition: ReactionPathCostCalculator.h:102
virtual void setStructure(const Utils::AtomCollection &structure)=0
virtual int optimize(Core::Log &log)=0
Optimize an interpolated elementary step.
ElementaryStepOptimizerBase()=default
Default constructor.
virtual Utils::Settings getSettings() const =0
Get the public settings as a Utils::Settings object.
virtual Utils::GradientBasedCheck getConvergenceCheck() const =0
The underlying convergence check.
void calculateCost(const Utils::BSplines::BSpline &spline, const EnergiesAndGradientsAlongSpline &energyValues)
Evaluate the cost associated with a given spline.
Definition: ReactionPathCostCalculator.h:93