MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
energy.h
1//
2// energy.h
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifndef _chemistry_molecule_energy_h
29#define _chemistry_molecule_energy_h
30
31#include <iostream>
32
33#include <math/optimize/function.h>
34#include <math/optimize/conv.h>
35#include <chemistry/molecule/molecule.h>
36#include <chemistry/molecule/coor.h>
37#include <chemistry/molecule/deriv.h>
38#ifdef MPQC_NEW_FEATURES
39#include <util/misc/xml.h>
40#endif
41
42namespace sc {
43
46
51#ifdef MPQC_NEW_FEATURES
52, virtual public DescribedXMLWritable
53#endif
54{
55 private:
56 RefSCDimension moldim_; // the number of cartesian variables
58 Ref<Molecule> mol_;
63 Ref<MolecularHessian> guesshess_;
65
66 RefSCVector cartesian_gradient_;
67 RefSymmSCMatrix cartesian_hessian_;
68
69 RefSCVector efield_; //< electric field vector
70
72 bool ckpt_;
74 std::string ckpt_file_;
76 int ckpt_freq_;
77
78 protected:
79 Ref<PointGroup> initial_pg_;
80
81 void failure(const char *);
82
84 virtual void set_energy(double);
85
88 virtual void set_gradient(RefSCVector&);
89 virtual void set_hessian(RefSymmSCMatrix&);
90
91 void x_to_molecule();
92 void molecule_to_x();
93
94 int print_molecule_when_changed_;
95
98 virtual bool nonzero_efield_supported() const;
99
103 virtual bool analytic_gradient_implemented() const;
107 virtual bool analytic_hessian_implemented() const;
108
109
110 public:
171
173
174
175#ifdef MPQC_NEW_FEATURES
176 virtual boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent, const XMLWriter& writer);
177#endif
178
181 void set_checkpoint_file(const char*);
182 void set_checkpoint_freq(int freq);
184 bool if_to_checkpoint() const;
185 const char* checkpoint_file() const;
186 int checkpoint_freq() const;
187
188 MolecularEnergy & operator=(const MolecularEnergy&);
189
191 virtual double energy();
192
193 virtual Ref<Molecule> molecule() const;
194 virtual RefSCDimension moldim() const;
195
197 RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
198
209
216 void set_desired_hessian_accuracy(double acc);
218
222 void set_molhess(const Ref<MolecularHessian>& molhess);
223 const Ref<MolecularHessian>& molhess() const;
230 const Ref<MolecularGradient>& molgrad() const;
233
234 void set_x(const RefSCVector&);
235
242
243 Ref<MolecularCoor> molecularcoor() { return mc_; }
244
247 virtual void symmetry_changed();
248
250
255 virtual void purge();
256
258 const RefSCVector& electric_field() const { return efield_; }
259
262 const char *t=0, std::ostream&o=ExEnv::out0()) const;
263 void print_natom_3(double **, const char *t=0, std::ostream&o=ExEnv::out0()) const;
264 void print_natom_3(double *, const char *t=0, std::ostream&o=ExEnv::out0()) const;
265
266 virtual void print(std::ostream& = ExEnv::out0()) const;
267};
268
271 protected:
272 int value_implemented() const;
275 int n_;
277 double *coef_;
278 void compute();
279 public:
283
285
286 void set_x(const RefSCVector&);
287
288 void purge();
289};
290
291
292/* The MolEnergyConvergence class derives from the Convergence class. The
293MolEnergyConvergence class allows the user to request that cartesian
294coordinates be used in evaluating the convergence criteria. This is
295useful, since the internal coordinates can be somewhat arbitary. If the
296optimization is constrained, then the fixed internal coordinates will be
297projected out of the cartesian gradients. The input is similar to that for
298Convergence class with the exception that giving none of the convergence
299criteria keywords is the same as providing the following input to the
300KeyVal constructor:
301
302<pre>
303 conv<MolEnergyConvergence>: (
304 max_disp = 1.0e-4
305 max_grad = 1.0e-4
306 graddisp = 1.0e-4
307 )
308</pre>
309
310For MolEnergyConverence to work, the Function object given to the Optimizer
311object must derive from MolecularEnergy.
312*/
314 protected:
316 int cartesian_;
317
318 void set_defaults();
319 public:
320 // Standard constructors and destructor.
341 virtual ~MolEnergyConvergence();
342
344
345 // Set the current gradient and position information. These
346 //will possibly grab the cartesian infomation if we have a
347 //MolecularEnergy.
348 void get_grad(const Ref<Function> &);
349 void get_x(const Ref<Function> &);
350 void set_nextx(const RefSCVector &);
351
352 // Return nonzero if the optimization has converged.
354
355 void print(std::ostream& = ExEnv::out0()) const;
356};
357
359// end of addtogroup ChemistryMolecule
360
361}
362
363#endif
364
365// Local Variables:
366// mode: c++
367// c-file-style: "CLJ"
368// End:
The Convergence class is used by the optimizer to determine when an optimization is converged.
Definition conv.h:52
Definition xml.h:50
static std::ostream & out0()
Return an ostream that writes from node 0.
The Function class is an abstract base class that, given a set of coordinates, will compute a value a...
Definition function.h:44
Definition energy.h:313
void print(std::ostream &=ExEnv::out0()) const
Print the object.
MolEnergyConvergence(const Ref< KeyVal > &)
The KeyVal constructor.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
int converged()
Return nonzero if the optimization has converged.
void get_grad(const Ref< Function > &)
Set the current gradient and displacement.
The MolecularEnergy abstract class inherits from the Function class.
Definition energy.h:54
virtual bool analytic_hessian_implemented() const
must overload this in a derived class if analytic hessian can be computed
RefSymmSCMatrix get_cartesian_hessian()
Return the cartesian hessian.
void print_natom_3(const RefSCVector &, const char *t=0, std::ostream &o=ExEnv::out0()) const
Nicely print n x 3 data that are stored in a vector.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
void set_molhess(const Ref< MolecularHessian > &molhess)
Use this function to provide MolecularHessian object that will be used to compute hessian.
MolecularEnergy(const Ref< KeyVal > &)
The KeyVal constructor.
RefSCVector get_cartesian_x()
Return the cartesian coordinates.
RefSCVector get_cartesian_gradient()
Return the cartesian gradient.
virtual double energy()
A wrapper around value();.
void set_desired_gradient_accuracy(double acc)
These functions overload their Function counterparts.
virtual void set_gradient(RefSCVector &)
These are passed gradients and hessian in cartesian coordinates.
void guess_hessian(RefSymmSCMatrix &)
Compute a quick, approximate hessian.
void set_molgrad(const Ref< MolecularGradient > &molgrad)
Use this function to provide MolecularGradient object that will be used to compute gradient.
virtual bool nonzero_efield_supported() const
overload this in classes that support computations in nonzero electric field the default is to not su...
const RefSCVector & electric_field() const
returns the electric field vector
Definition energy.h:258
int gradient_implemented() const
Reports whether gradient is implemented either analytically or using MolecularGradient object.
virtual void purge()
This function purges any caches of data in MolecularEnergy.
RefSymmSCMatrix hessian()
Will throw if hessian_implemented() returns 0.
virtual void set_energy(double)
This is just a wrapper around set_value().
void set_checkpoint()
Set up checkpointing.
Ref< NonlinearTransform > change_coordinates()
An optimizer can call change coordinates periodically to give the function an opportunity to change i...
RefSCVector gradient()
Will throw if gradient_implemented() returns 0.
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
virtual bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
bool if_to_checkpoint() const
Check if need to checkpoint.
virtual void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
int hessian_implemented() const
Reports whether hessian is implemented either analytically or using MolecularHessian object.
virtual void print(std::ostream &=ExEnv::out0()) const
Print information about the object.
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition dim.h:152
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition matrix.h:55
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition matrix.h:265
A template class that maintains references counts.
Definition ref.h:361
Restores fundamental and user-defined types from images created with StateOut.
Definition statein.h:79
Serializes fundamental and user-defined types.
Definition stateout.h:71
linear combination of MolecularEnergy objects
Definition energy.h:270
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
void purge()
This function purges any caches of data in MolecularEnergy.
int value_implemented() const
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
bool analytic_hessian_implemented() const
must overload this in a derived class if analytic hessian can be computed
bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
void compute()
Recompute at least the results that have compute true and are not already computed.
Definition xmlwriter.h:223
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:28 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.