Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

energy.h

00001 // 00002 // energy.h 00003 // 00004 // Copyright (C) 1996 Limit Point Systems, Inc. 00005 // 00006 // Author: Curtis Janssen <cljanss@limitpt.com> 00007 // Maintainer: LPS 00008 // 00009 // This file is part of the SC Toolkit. 00010 // 00011 // The SC Toolkit is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Library General Public License as published by 00013 // the Free Software Foundation; either version 2, or (at your option) 00014 // any later version. 00015 // 00016 // The SC Toolkit is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU Library General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Library General Public License 00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to 00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00024 // 00025 // The U.S. Government is granted a limited license as per AL 91-7. 00026 // 00027 00028 #ifndef _chemistry_molecule_energy_h 00029 #define _chemistry_molecule_energy_h 00030 00031 #ifdef __GNUC__ 00032 #pragma interface 00033 #endif 00034 00035 #include <iostream> 00036 00037 #include <math/optimize/function.h> 00038 #include <math/optimize/conv.h> 00039 #include <chemistry/molecule/molecule.h> 00040 #include <chemistry/molecule/coor.h> 00041 #include <chemistry/molecule/hess.h> 00042 00043 namespace sc { 00044 00048 class MolecularEnergy: public Function { 00049 private: 00050 RefSCDimension moldim_; // the number of cartesian variables 00051 Ref<MolecularCoor> mc_; 00052 Ref<Molecule> mol_; 00053 Ref<MolecularHessian> hess_; 00054 Ref<MolecularHessian> guesshess_; 00055 00056 RefSCVector cartesian_gradient_; 00057 RefSymmSCMatrix cartesian_hessian_; 00058 00060 bool ckpt_; 00062 char *ckpt_file_; 00064 int ckpt_freq_; 00065 00066 protected: 00067 Ref<PointGroup> initial_pg_; 00068 00069 void failure(const char *); 00070 00072 virtual void set_energy(double); 00073 00076 virtual void set_gradient(RefSCVector&); 00077 virtual void set_hessian(RefSymmSCMatrix&); 00078 00079 void x_to_molecule(); 00080 void molecule_to_x(); 00081 00082 int print_molecule_when_changed_; 00083 public: 00084 MolecularEnergy(const MolecularEnergy&); 00122 MolecularEnergy(const Ref<KeyVal>&); 00123 MolecularEnergy(StateIn&); 00124 ~MolecularEnergy(); 00125 00126 void save_data_state(StateOut&); 00127 00129 void set_checkpoint(); 00130 void set_checkpoint_file(const char*); 00131 void set_checkpoint_freq(int freq); 00133 bool if_to_checkpoint() const; 00134 const char* checkpoint_file() const; 00135 int checkpoint_freq() const; 00136 00137 MolecularEnergy & operator=(const MolecularEnergy&); 00138 00140 virtual double energy(); 00141 00142 virtual Ref<Molecule> molecule() const; 00143 virtual RefSCDimension moldim() const; 00144 00145 void guess_hessian(RefSymmSCMatrix&); 00146 RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&); 00147 00150 RefSymmSCMatrix hessian(); 00151 int hessian_implemented() const; 00152 00153 void set_x(const RefSCVector&); 00154 00156 RefSCVector get_cartesian_x(); 00158 RefSCVector get_cartesian_gradient(); 00160 RefSymmSCMatrix get_cartesian_hessian(); 00161 00162 Ref<MolecularCoor> molecularcoor() { return mc_; } 00163 00166 virtual void symmetry_changed(); 00167 00168 Ref<NonlinearTransform> change_coordinates(); 00169 00171 void print_natom_3(const RefSCVector &, 00172 const char *t=0, std::ostream&o=ExEnv::out0()) const; 00173 void print_natom_3(double **, const char *t=0, std::ostream&o=ExEnv::out0()) const; 00174 void print_natom_3(double *, const char *t=0, std::ostream&o=ExEnv::out0()) const; 00175 00176 virtual void print(std::ostream& = ExEnv::out0()) const; 00177 }; 00178 00179 00180 class SumMolecularEnergy: public MolecularEnergy { 00181 protected: 00182 int n_; 00183 Ref<MolecularEnergy> *mole_; 00184 double *coef_; 00185 void compute(); 00186 public: 00187 SumMolecularEnergy(const Ref<KeyVal> &); 00188 SumMolecularEnergy(StateIn&); 00189 ~SumMolecularEnergy(); 00190 00191 void save_data_state(StateOut&); 00192 00193 int value_implemented() const; 00194 int gradient_implemented() const; 00195 int hessian_implemented() const; 00196 00197 void set_x(const RefSCVector&); 00198 }; 00199 00200 00201 /* The MolEnergyConvergence class derives from the Convergence class. The 00202 MolEnergyConvergence class allows the user to request that cartesian 00203 coordinates be used in evaluating the convergence criteria. This is 00204 useful, since the internal coordinates can be somewhat arbitary. If the 00205 optimization is constrained, then the fixed internal coordinates will be 00206 projected out of the cartesian gradients. The input is similar to that for 00207 Convergence class with the exception that giving none of the convergence 00208 criteria keywords is the same as providing the following input to the 00209 KeyVal constructor: 00210 00211 <pre> 00212 conv<MolEnergyConvergence>: ( 00213 max_disp = 1.0e-4 00214 max_grad = 1.0e-4 00215 graddisp = 1.0e-4 00216 ) 00217 </pre> 00218 00219 For MolEnergyConverence to work, the Function object given to the Optimizer 00220 object must derive from MolecularEnergy. 00221 */ 00222 class MolEnergyConvergence: public Convergence { 00223 protected: 00224 Ref<MolecularEnergy> mole_; 00225 int cartesian_; 00226 00227 void set_defaults(); 00228 public: 00229 // Standard constructors and destructor. 00230 MolEnergyConvergence(); 00231 MolEnergyConvergence(StateIn&); 00249 MolEnergyConvergence(const Ref<KeyVal>&); 00250 virtual ~MolEnergyConvergence(); 00251 00252 void save_data_state(StateOut&); 00253 00254 // Set the current gradient and position information. These 00255 //will possibly grab the cartesian infomation if we have a 00256 //MolecularEnergy. 00257 void get_grad(const Ref<Function> &); 00258 void get_x(const Ref<Function> &); 00259 void set_nextx(const RefSCVector &); 00260 00261 // Return nonzero if the optimization has converged. 00262 int converged(); 00263 }; 00264 00265 } 00266 00267 #endif 00268 00269 // Local Variables: 00270 // mode: c++ 00271 // c-file-style: "CLJ" 00272 // End:

Generated at Thu Jul 29 19:53:50 2004 for MPQC 2.2.1 using the documentation package Doxygen 1.3.7.