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 protected:
00059 Ref<PointGroup> initial_pg_;
00060
00061 void failure(const char *);
00062
00064 virtual void set_energy(double);
00065
00068 virtual void set_gradient(RefSCVector&);
00069 virtual void set_hessian(RefSymmSCMatrix&);
00070
00071 void x_to_molecule();
00072 void molecule_to_x();
00073
00074 int print_molecule_when_changed_;
00075 public:
00076 MolecularEnergy(const MolecularEnergy&);
00101 MolecularEnergy(const Ref<KeyVal>&);
00102 MolecularEnergy(StateIn&);
00103 ~MolecularEnergy();
00104
00105 void save_data_state(StateOut&);
00106
00107 MolecularEnergy & operator=(const MolecularEnergy&);
00108
00110 virtual double energy();
00111
00112 virtual Ref<Molecule> molecule() const;
00113 virtual RefSCDimension moldim() const;
00114
00115 void guess_hessian(RefSymmSCMatrix&);
00116 RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
00117
00120 RefSymmSCMatrix hessian();
00121 int hessian_implemented() const;
00122
00123 void set_x(const RefSCVector&);
00124
00126 RefSCVector get_cartesian_x();
00128 RefSCVector get_cartesian_gradient();
00130 RefSymmSCMatrix get_cartesian_hessian();
00131
00132 Ref<MolecularCoor> molecularcoor() { return mc_; }
00133
00136 virtual void symmetry_changed();
00137
00138 Ref<NonlinearTransform> change_coordinates();
00139
00141 void print_natom_3(const RefSCVector &,
00142 const char *t=0, std::ostream&o=ExEnv::out0()) const;
00143 void print_natom_3(double **, const char *t=0, std::ostream&o=ExEnv::out0()) const;
00144 void print_natom_3(double *, const char *t=0, std::ostream&o=ExEnv::out0()) const;
00145
00146 virtual void print(std::ostream& = ExEnv::out0()) const;
00147 };
00148
00149
00150 class SumMolecularEnergy: public MolecularEnergy {
00151 protected:
00152 int n_;
00153 Ref<MolecularEnergy> *mole_;
00154 double *coef_;
00155 void compute();
00156 public:
00157 SumMolecularEnergy(const Ref<KeyVal> &);
00158 SumMolecularEnergy(StateIn&);
00159 ~SumMolecularEnergy();
00160
00161 void save_data_state(StateOut&);
00162
00163 int value_implemented() const;
00164 int gradient_implemented() const;
00165 int hessian_implemented() const;
00166
00167 void set_x(const RefSCVector&);
00168 };
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 class MolEnergyConvergence: public Convergence {
00193 protected:
00194 Ref<MolecularEnergy> mole_;
00195 int cartesian_;
00196
00197 void set_defaults();
00198 public:
00199
00200 MolEnergyConvergence();
00201 MolEnergyConvergence(StateIn&);
00219 MolEnergyConvergence(const Ref<KeyVal>&);
00220 virtual ~MolEnergyConvergence();
00221
00222 void save_data_state(StateOut&);
00223
00224
00225
00226
00227 void get_grad(const Ref<Function> &);
00228 void get_x(const Ref<Function> &);
00229 void set_nextx(const RefSCVector &);
00230
00231
00232 int converged();
00233 };
00234
00235 }
00236
00237 #endif
00238
00239
00240
00241
00242