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
43namespace sc {
44
48class 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:
84 MolecularEnergy(const MolecularEnergy&);
136 MolecularEnergy(StateIn&);
137 ~MolecularEnergy();
138
140
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
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
193class SumMolecularEnergy: public MolecularEnergy {
194 protected:
195 int n_;
197 double *coef_;
198 void compute();
199 public:
200 SumMolecularEnergy(const Ref<KeyVal> &);
201 SumMolecularEnergy(StateIn&);
202 ~SumMolecularEnergy();
203
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
215MolEnergyConvergence class allows the user to request that cartesian
216coordinates be used in evaluating the convergence criteria. This is
217useful, since the internal coordinates can be somewhat arbitary. If the
218optimization is constrained, then the fixed internal coordinates will be
219projected out of the cartesian gradients. The input is similar to that for
220Convergence class with the exception that giving none of the convergence
221criteria keywords is the same as providing the following input to the
222KeyVal 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
232For MolEnergyConverence to work, the Function object given to the Optimizer
233object must derive from MolecularEnergy.
234*/
235class MolEnergyConvergence: public Convergence {
236 protected:
238 int cartesian_;
239
240 void set_defaults();
241 public:
242 // Standard constructors and destructor.
243 MolEnergyConvergence();
244 MolEnergyConvergence(StateIn&);
263 virtual ~MolEnergyConvergence();
264
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.
276};
277
278}
279
280#endif
281
282// Local Variables:
283// mode: c++
284// c-file-style: "CLJ"
285// End:
static std::ostream & out0()
Return an ostream that writes from node 0.
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.
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 ...
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();.
virtual void set_gradient(RefSCVector &)
These are passed gradients and hessian in cartesian coordinates.
void guess_hessian(RefSymmSCMatrix &)
Compute a quick, approximate hessian.
RefSymmSCMatrix hessian()
If a molecule hessian object is given, it will be used to provide a hessian.
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...
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
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...
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:156
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:261
A template class that maintains references counts.
Definition ref.h:332
Restores objects that derive from SavableState.
Definition statein.h:70
Serializes objects that derive from SavableState.
Definition stateout.h:61
void set_x(const RefSCVector &)
Set and retrieve the coordinate values.
int value_implemented() const
Information about the availability of values, gradients, and hessians.
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 compute()
Recompute at least the results that have compute true and are not already computed.

Generated at Sun Jan 19 2025 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.13.2.