00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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_;
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
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 class MolEnergyConvergence: public Convergence {
00223 protected:
00224 Ref<MolecularEnergy> mole_;
00225 int cartesian_;
00226
00227 void set_defaults();
00228 public:
00229
00230 MolEnergyConvergence();
00231 MolEnergyConvergence(StateIn&);
00249 MolEnergyConvergence(const Ref<KeyVal>&);
00250 virtual ~MolEnergyConvergence();
00251
00252 void save_data_state(StateOut&);
00253
00254
00255
00256
00257 void get_grad(const Ref<Function> &);
00258 void get_x(const Ref<Function> &);
00259 void set_nextx(const RefSCVector &);
00260
00261
00262 int converged();
00263 };
00264
00265 }
00266
00267 #endif
00268
00269
00270
00271
00272