MPQC  3.0.0-alpha
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 
42 namespace 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:
170  ~MolecularEnergy();
171 
172  void save_data_state(StateOut&);
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 
180  void set_checkpoint();
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 
203  int gradient_implemented() const;
208  int hessian_implemented() const;
209 
215  void set_desired_gradient_accuracy(double acc);
216  void set_desired_hessian_accuracy(double acc);
218 
222  void set_molhess(const Ref<MolecularHessian>& molhess);
223  const Ref<MolecularHessian>& molhess() const;
229  void set_molgrad(const Ref<MolecularGradient>& molgrad);
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 
261  void print_natom_3(const RefSCVector &,
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;
273  bool analytic_gradient_implemented() const;
274  bool analytic_hessian_implemented() const;
275  int n_;
276  Ref<MolecularEnergy> *mole_;
277  double *coef_;
278  void compute();
279  public:
283 
284  void save_data_state(StateOut&);
285 
286  void set_x(const RefSCVector&);
287 
288  void purge();
289 };
290 
291 
292 /* The MolEnergyConvergence class derives from the Convergence class. The
293 MolEnergyConvergence class allows the user to request that cartesian
294 coordinates be used in evaluating the convergence criteria. This is
295 useful, since the internal coordinates can be somewhat arbitary. If the
296 optimization is constrained, then the fixed internal coordinates will be
297 projected out of the cartesian gradients. The input is similar to that for
298 Convergence class with the exception that giving none of the convergence
299 criteria keywords is the same as providing the following input to the
300 KeyVal 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 
310 For MolEnergyConverence to work, the Function object given to the Optimizer
311 object must derive from MolecularEnergy.
312 */
314  protected:
315  Ref<MolecularEnergy> mole_;
316  int cartesian_;
317 
318  void set_defaults();
319  public:
320  // Standard constructors and destructor.
341  virtual ~MolEnergyConvergence();
342 
343  void save_data_state(StateOut&);
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.
353  int 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:
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::set_molhess
void set_molhess(const Ref< MolecularHessian > &molhess)
Use this function to provide MolecularHessian object that will be used to compute hessian.
sc::MolecularEnergy::hessian
RefSymmSCMatrix hessian()
Will throw if hessian_implemented() returns 0.
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::MolecularEnergy::nonzero_efield_supported
virtual bool nonzero_efield_supported() const
overload this in classes that support computations in nonzero electric field the default is to not su...
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:265
sc::SumMolecularEnergy::purge
void purge()
This function purges any caches of data in MolecularEnergy.
sc::MolecularEnergy::if_to_checkpoint
bool if_to_checkpoint() const
Check if need to checkpoint.
sc::SumMolecularEnergy::value_implemented
int value_implemented() const
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
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::SumMolecularEnergy::analytic_hessian_implemented
bool analytic_hessian_implemented() const
must overload this in a derived class if analytic hessian can be computed
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:44
sc::MolecularEnergy::electric_field
const RefSCVector & electric_field() const
returns the electric field vector
Definition: energy.h:258
sc::SumMolecularEnergy::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::StateIn
Definition: statein.h:79
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
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::DescribedXMLWritable
Definition: xml.h:50
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:50
sc::SumMolecularEnergy::analytic_gradient_implemented
bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
sc::MolecularEnergy::gradient
RefSCVector gradient()
Will throw if gradient_implemented() returns 0.
sc::MolecularEnergy::purge
virtual void purge()
This function purges any caches of data in MolecularEnergy.
sc::MolEnergyConvergence
Definition: energy.h:313
sc::MolecularEnergy::set_gradient
virtual void set_gradient(RefSCVector &)
These are passed gradients and hessian in cartesian coordinates.
sc::MolecularEnergy::set_molgrad
void set_molgrad(const Ref< MolecularGradient > &molgrad)
Use this function to provide MolecularGradient object that will be used to compute gradient.
sc::MolecularEnergy::set_desired_gradient_accuracy
void set_desired_gradient_accuracy(double acc)
These functions overload their Function counterparts.
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::StateOut
Definition: stateout.h:71
sc::XMLWriter
Definition: xmlwriter.h:215
sc::MolecularEnergy::hessian_implemented
int hessian_implemented() const
Reports whether hessian is implemented either analytically or using MolecularHessian object.
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:52
sc::MolecularEnergy::gradient_implemented
int gradient_implemented() const
Reports whether gradient is implemented either analytically or using MolecularGradient object.
sc::SumMolecularEnergy
linear combination of MolecularEnergy objects
Definition: energy.h:270
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::analytic_hessian_implemented
virtual bool analytic_hessian_implemented() const
must overload this in a derived class if analytic hessian can be computed
sc::MolecularEnergy::set_x
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
sc::MolecularEnergy::analytic_gradient_implemented
virtual bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
sc::MolEnergyConvergence::print
void print(std::ostream &=ExEnv::out0()) const
Print the object.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:23:56 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.