36#ifndef MADNESS_CHEM_MOLECULAR_OPTIMIZER_H__INCLUDED
37#define MADNESS_CHEM_MOLECULAR_OPTIMIZER_H__INCLUDED
69 (
"remove_dof", {
"tx",
"ty",
"tz",
"rx",
"ry",
"rz"},
"degree of freedom projected out: translation/rotation");
79 return std::string(
"geoopt");
106 std::shared_ptr<MolecularOptimizationTargetInterface>
target;
116 const std::shared_ptr<MolecularOptimizationTargetInterface>&
tar)
160 for (
size_t i=0; i<
target->molecule().natom(); ++i) {
161 h(3*i ,3*i )=1.0/(
target->molecule().get_atom(i).mass);
162 h(3*i+1,3*i+1)=1.0/(
target->molecule().get_atom(i).mass);
163 h(3*i+2,3*i+2)=1.0/(
target->molecule().get_atom(i).mass);
171 madness::print(
"\ngopt: projected vibrational frequencies (cm-1)\n");
172 printf(
"frequency in cm-1 ");
173 for (
int i=0; i<
freq.size(); ++i) {
189 target->value_and_gradient(x,
f, gradient);
220 madness::print(
"\ngopt: projected vibrational frequencies (cm-1)\n");
221 printf(
"frequency in cm-1 ");
222 for (
int i=0; i<
freq.size(); ++i) {
242 printf(
" QuasiNewton iteration %2d energy: %16.8f gradient %.2e displacement %.2e \n", iter,
f,
gnorm,
disp2);
247 print(
"final hessian");
325 for (
int i=0; i<
e.size(); ++i) {
328 " forcing negative eigenvalue to be positive %d %.1e\n", i,
e[i]);
333 else if (
e[i] < tol) {
335 " forcing small eigenvalue to be zero %d %.1e\n", i,
e[i]);
342 gv[i] = -
gv[i] /
e[i];
346 " restricting step in spectral direction %d %.1e --> %.1e\n",
370 const std::vector<std::string>& remove_dof) {
376 for (
size_t i=0; i<mol.
natom(); ++i) {
407 for (
size_t iatom=0; iatom<mol.
natom(); ++iatom) {
423 rotx(3*iatom + 0)=
p(1)*
v(0,2)-
p(2)*
v(0,1);
424 rotx(3*iatom + 1)=
p(1)*
v(1,2)-
p(2)*
v(1,1);
425 rotx(3*iatom + 2)=
p(1)*
v(2,2)-
p(2)*
v(2,1);
427 roty(3*iatom + 0)=
p(2)*
v(0,0)-
p(0l)*
v(0,2);
428 roty(3*iatom + 1)=
p(2)*
v(1,0)-
p(0l)*
v(1,2);
429 roty(3*iatom + 2)=
p(2)*
v(2,0)-
p(0l)*
v(2,2);
431 rotz(3*iatom + 0)=
p(0l)*
v(0,1)-
p(1)*
v(0,0);
432 rotz(3*iatom + 1)=
p(0l)*
v(1,1)-
p(1)*
v(1,0);
433 rotz(3*iatom + 2)=
p(0l)*
v(2,1)-
p(1)*
v(2,0);
457 for (
int i=0; i<6; ++i) {
469 for (
int i=0; i<6; ++i) {
493 const std::vector<std::string>& remove_dof) {
512 const std::vector<std::string>& remove_dof={},
const bool print_hessian=
false) {
517 for (
size_t i=0; i<3*
molecule.natom(); ++i)
Minv(i,i)=1.0/
M(i,i);
526 if (remove_dof.size()>0) {
527 print(
"mass-weighted hessian with translation and rotation projected out");
529 print(
"mass-weighted unprojected hessian");
533 print(
"mass-weighted unprojected hessian; mass-weighing undone");
539 for (
long i=0; i<
freq.size(); ++i) {
557 for (
size_t i=0; i<3*
molecule.natom(); ++i) {
double y
Definition molecule.h:62
double x
Definition molecule.h:62
double z
Definition molecule.h:62
double get_mass_in_au() const
return the mass in atomic units (electron mass = 1 a.u.)
Definition molecule.h:109
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
Definition molecular_optimizer.h:56
std::vector< std::string > remove_dof() const
Definition molecular_optimizer.h:92
MolecularOptimizationParameters(World &world, const commandlineparser &parser)
Definition molecular_optimizer.h:72
MolecularOptimizationParameters()
ctor reading out the input file
Definition molecular_optimizer.h:60
bool printtest() const
Definition molecular_optimizer.h:91
double tol() const
Definition molecular_optimizer.h:88
std::string cg_method() const
Definition molecular_optimizer.h:86
std::string get_tag() const override
Definition molecular_optimizer.h:78
double gradient_precision() const
Definition molecular_optimizer.h:90
double value_precision() const
Definition molecular_optimizer.h:89
std::string update() const
Definition molecular_optimizer.h:85
void set_derived_values()
Definition molecular_optimizer.h:82
int maxiter() const
Definition molecular_optimizer.h:87
Molecular optimizer derived from the QuasiNewton optimizer.
Definition molecular_optimizer.h:103
void set_hessian(const Tensor< double > &hess)
set an (initial) hessian
Definition molecular_optimizer.h:143
bool optimize_quasi_newton(Tensor< double > &x)
Definition molecular_optimizer.h:150
bool optimize(Tensor< double > &x)
optimize the underlying molecule
Definition molecular_optimizer.h:123
Tensor< double > h
Definition molecular_optimizer.h:107
double gradient_norm() const
Definition molecular_optimizer.h:140
MolecularOptimizationParameters parameters
Definition molecular_optimizer.h:112
static Tensor< double > compute_frequencies(const Molecule &molecule, const Tensor< double > &hessian, Tensor< double > &normalmodes, const std::vector< std::string > &remove_dof={}, const bool print_hessian=false)
returns the vibrational frequencies
Definition molecular_optimizer.h:510
bool converged() const
Definition molecular_optimizer.h:130
bool converged(const Tensor< double > &displacement) const
Definition molecular_optimizer.h:134
static Tensor< double > projector_external_dof(const Molecule &mol, const std::vector< std::string > &remove_dof)
compute the projector to remove transl. and rot. degrees of freedom
Definition molecular_optimizer.h:369
static Tensor< double > compute_reduced_mass(const Molecule &molecule, const Tensor< double > &normalmodes)
Definition molecular_optimizer.h:547
double f
Definition molecular_optimizer.h:108
bool optimize_conjugate_gradients(Tensor< double > &x)
Definition molecular_optimizer.h:253
MolecularOptimizer(World &world, const commandlineparser &parser, const std::shared_ptr< MolecularOptimizationTargetInterface > &tar)
same ctor as the QuasiNewton optimizer
Definition molecular_optimizer.h:115
std::shared_ptr< MolecularOptimizationTargetInterface > target
How to update the hessian: BFGS or SR1.
Definition molecular_optimizer.h:106
Tensor< double > new_search_direction2(const Tensor< double > &g, const Tensor< double > &hessian) const
effectively invert the hessian and multiply with the gradient
Definition molecular_optimizer.h:307
static void remove_external_dof(Tensor< double > &hessian, const Molecule &mol, const std::vector< std::string > &remove_dof)
remove translational degrees of freedom from the hessian
Definition molecular_optimizer.h:492
double gnorm
Definition molecular_optimizer.h:109
double value() const
Definition molecular_optimizer.h:138
Definition molecule.h:129
void translate(const Tensor< double > &translation)
translate the molecule
Definition molecule.cc:709
const Atom & get_atom(unsigned int i) const
Definition molecule.cc:452
Tensor< double > center_of_mass() const
compute the center of mass
Definition molecule.cc:878
size_t natom() const
Definition molecule.h:415
class for holding the parameters for calculation
Definition QCCalculationParametersBase.h:295
void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition QCCalculationParametersBase.h:331
static double line_search(double a1, double f0, double dxgrad, const Tensor< double > &x, const Tensor< double > &dx, std::shared_ptr< OptimizationTargetInterface > target, double value_precision)
make this static for other QN classed to have access to it
Definition solvers.cc:113
static void hessian_update_bfgs(const Tensor< double > &dx, const Tensor< double > &dg, Tensor< double > &hessian)
make this static for other QN classed to have access to it
Definition solvers.cc:179
static void hessian_update_sr1(const Tensor< double > &s, const Tensor< double > &y, Tensor< double > &hessian)
make this static for other QN classed to have access to it
Definition solvers.cc:166
A tensor is a multidimensional array.
Definition tensor.h:317
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1726
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type scale(Q x)
Inplace multiplication by scalar of supported type (legacy name)
Definition tensor.h:686
A parallel world class.
Definition world.h:132
double(* energy)()
Definition derivatives.cc:58
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
constexpr double au2invcm
conversion from atomic units in reciprocal centimeter
Definition constants.h:272
constexpr double atomic_mass_in_au
Atomic mass in atomic units.
Definition constants.h:269
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
response_space transpose(response_space &f)
Definition basic_operators.cc:10
Key< NDIM > displacement(const Key< NDIM > &source, const Key< NDIM > &target)
given a source and a target, return the displacement in translation
Definition key.h:452
static const Slice _(0,-1, 1)
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:226
NDIM const Function< R, NDIM > & g
Definition mra.h:2528
double inner(response_space &a, response_space &b)
Definition response_functions.h:639
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2096
void syev(const Tensor< T > &A, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Real-symmetric or complex-Hermitian eigenproblem.
Definition lapack.cc:969
static long abs(long a)
Definition tensor.h:218
const double mu
Definition navstokes_cosines.cc:95
static const double L
Definition rk.cc:46
Defines interfaces for optimization and non-linear equation solvers.
Definition test_ar.cc:204
Definition molecular_optimizer.h:46
virtual Molecule & molecule()
return the molecule of the target
Definition molecular_optimizer.h:49
The interface to be provided by functions to be optimized.
Definition solvers.h:176
The interface to be provided by optimizers.
Definition solvers.h:206
very simple command line parser
Definition commandlineparser.h:15
static std::string tolower(std::string s)
make lower case
Definition commandlineparser.h:86
static const double_complex I
Definition tdse1d.cc:164
void converge(World &world, functionT &potn, functionT &psi, double &eps)
Definition tdse.cc:441
double norm(const T i1)
Definition test_cloud.cc:85
void e()
Definition test_sig.cc:75
static Molecule molecule
Definition testperiodicdft.cc:39