MPQC  2.3.1
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 #ifdef __GNUC__
32 #pragma interface
33 #endif
34 
35 #include <iostream>
36 
37 #include <math/optimize/function.h>
38 #include <math/optimize/conv.h>
39 #include <chemistry/molecule/molecule.h>
40 #include <chemistry/molecule/coor.h>
41 #include <chemistry/molecule/hess.h>
42 
43 namespace sc {
44 
48 class MolecularEnergy: public Function {
49  private:
50  RefSCDimension moldim_; // the number of cartesian variables
52  Ref<Molecule> mol_;
54  Ref<MolecularHessian> guesshess_;
55 
56  RefSCVector cartesian_gradient_;
57  RefSymmSCMatrix cartesian_hessian_;
58 
60  bool ckpt_;
62  char *ckpt_file_;
64  int ckpt_freq_;
65 
66  protected:
67  Ref<PointGroup> initial_pg_;
68 
69  void failure(const char *);
70 
72  virtual void set_energy(double);
73 
76  virtual void set_gradient(RefSCVector&);
77  virtual void set_hessian(RefSymmSCMatrix&);
78 
79  void x_to_molecule();
80  void molecule_to_x();
81 
82  int print_molecule_when_changed_;
83  public:
137  ~MolecularEnergy();
138 
139  void save_data_state(StateOut&);
140 
142  void set_checkpoint();
143  void set_checkpoint_file(const char*);
144  void set_checkpoint_freq(int freq);
146  bool if_to_checkpoint() const;
147  const char* checkpoint_file() const;
148  int checkpoint_freq() const;
149 
150  MolecularEnergy & operator=(const MolecularEnergy&);
151 
153  virtual double energy();
154 
155  virtual Ref<Molecule> molecule() const;
156  virtual RefSCDimension moldim() const;
157 
159  RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
160 
164  int hessian_implemented() const;
165 
166  void set_x(const RefSCVector&);
167 
174 
175  Ref<MolecularCoor> molecularcoor() { return mc_; }
176 
179  virtual void symmetry_changed();
180 
182 
184  void print_natom_3(const RefSCVector &,
185  const char *t=0, std::ostream&o=ExEnv::out0()) const;
186  void print_natom_3(double **, const char *t=0, std::ostream&o=ExEnv::out0()) const;
187  void print_natom_3(double *, const char *t=0, std::ostream&o=ExEnv::out0()) const;
188 
189  virtual void print(std::ostream& = ExEnv::out0()) const;
190 };
191 
192 
194  protected:
195  int n_;
196  Ref<MolecularEnergy> *mole_;
197  double *coef_;
198  void compute();
199  public:
203 
204  void save_data_state(StateOut&);
205 
206  int value_implemented() const;
207  int gradient_implemented() const;
208  int hessian_implemented() const;
209 
210  void set_x(const RefSCVector&);
211 };
212 
213 
214 /* The MolEnergyConvergence class derives from the Convergence class. The
215 MolEnergyConvergence class allows the user to request that cartesian
216 coordinates be used in evaluating the convergence criteria. This is
217 useful, since the internal coordinates can be somewhat arbitary. If the
218 optimization is constrained, then the fixed internal coordinates will be
219 projected out of the cartesian gradients. The input is similar to that for
220 Convergence class with the exception that giving none of the convergence
221 criteria keywords is the same as providing the following input to the
222 KeyVal constructor:
223 
224 <pre>
225  conv<MolEnergyConvergence>: (
226  max_disp = 1.0e-4
227  max_grad = 1.0e-4
228  graddisp = 1.0e-4
229  )
230 </pre>
231 
232 For MolEnergyConverence to work, the Function object given to the Optimizer
233 object must derive from MolecularEnergy.
234 */
236  protected:
237  Ref<MolecularEnergy> mole_;
238  int cartesian_;
239 
240  void set_defaults();
241  public:
242  // Standard constructors and destructor.
263  virtual ~MolEnergyConvergence();
264 
265  void save_data_state(StateOut&);
266 
267  // Set the current gradient and position information. These
268  //will possibly grab the cartesian infomation if we have a
269  //MolecularEnergy.
270  void get_grad(const Ref<Function> &);
271  void get_x(const Ref<Function> &);
272  void set_nextx(const RefSCVector &);
273 
274  // Return nonzero if the optimization has converged.
275  int converged();
276 };
277 
278 }
279 
280 #endif
281 
282 // Local Variables:
283 // mode: c++
284 // c-file-style: "CLJ"
285 // End:
sc::MolecularEnergy::get_cartesian_gradient
RefSCVector get_cartesian_gradient()
Return the cartesian gradient.
sc::MolecularEnergy::print_natom_3
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.
sc::MolecularEnergy::hessian
RefSymmSCMatrix hessian()
If a molecule hessian object is given, it will be used to provide a hessian.
sc::MolecularEnergy::symmetry_changed
virtual void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
sc::MolEnergyConvergence::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::MolecularEnergy::guess_hessian
void guess_hessian(RefSymmSCMatrix &)
Compute a quick, approximate hessian.
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:261
sc::MolecularEnergy::if_to_checkpoint
bool if_to_checkpoint() const
Check if need to checkpoint.
sc::SumMolecularEnergy::value_implemented
int value_implemented() const
Information about the availability of values, gradients, and hessians.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
sc::SumMolecularEnergy::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::MolecularEnergy::get_cartesian_hessian
RefSymmSCMatrix get_cartesian_hessian()
Return the cartesian hessian.
sc::SumMolecularEnergy::set_x
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
sc::MolEnergyConvergence::converged
int converged()
Return nonzero if the optimization has converged.
sc::Function
The Function class is an abstract base class that, given a set of coordinates, will compute a value a...
Definition: function.h:48
sc::SumMolecularEnergy::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::StateIn
Restores objects that derive from SavableState.
Definition: statein.h:70
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:156
sc::MolecularEnergy::print
virtual void print(std::ostream &=ExEnv::out0()) const
Print information about the object.
sc::MolEnergyConvergence::get_grad
void get_grad(const Ref< Function > &)
Set the current gradient and displacement.
sc::MolecularEnergy::set_checkpoint
void set_checkpoint()
Set up checkpointing.
sc::MolecularEnergy::get_cartesian_x
RefSCVector get_cartesian_x()
Return the cartesian coordinates.
sc::MolecularEnergy::energy
virtual double energy()
A wrapper around value();.
sc::MolecularEnergy
The MolecularEnergy abstract class inherits from the Function class.
Definition: energy.h:48
sc::MolEnergyConvergence
Definition: energy.h:235
sc::MolecularEnergy::set_gradient
virtual void set_gradient(RefSCVector &)
These are passed gradients and hessian in cartesian coordinates.
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::StateOut
Serializes objects that derive from SavableState.
Definition: stateout.h:61
sc::MolecularEnergy::set_energy
virtual void set_energy(double)
This is just a wrapper around set_value().
sc::MolecularEnergy::change_coordinates
Ref< NonlinearTransform > change_coordinates()
An optimizer can call change coordinates periodically to give the function an opportunity to change i...
sc::Convergence
The Convergence class is used by the optimizer to determine when an optimization is converged.
Definition: conv.h:56
sc::SumMolecularEnergy
Definition: energy.h:193
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::MolecularEnergy::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::MolecularEnergy::set_x
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.

Generated at Sun Jan 26 2020 23:33:03 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.