Main Page Class Hierarchy Compound List File List Compound 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   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 /* The MolEnergyConvergence class derives from the Convergence class.  The
    00172 MolEnergyConvergence class allows the user to request that cartesian
    00173 coordinates be used in evaluating the convergence criteria.  This is
    00174 useful, since the internal coordinates can be somewhat arbitary.  If the
    00175 optimization is constrained, then the fixed internal coordinates will be
    00176 projected out of the cartesian gradients.  The input is similar to that for
    00177 Convergence class with the exception that giving none of the convergence
    00178 criteria keywords is the same as providing the following input to the
    00179 KeyVal constructor:
    00180
    00181 <pre>
    00182   conv<MolEnergyConvergence>: (
    00183     max_disp = 1.0e-4
    00184     max_grad = 1.0e-4
    00185     graddisp = 1.0e-4
    00186   )
    00187 </pre>
    00188
    00189 For MolEnergyConverence to work, the Function object given to the Optimizer
    00190 object must derive from MolecularEnergy.
    00191 */
    00192 class MolEnergyConvergence: public Convergence {
    00193   protected:
    00194     Ref<MolecularEnergy> mole_;
    00195     int cartesian_;
    00196
    00197     void set_defaults();
    00198   public:
    00199     // Standard constructors and destructor.
    00200     MolEnergyConvergence();
    00201     MolEnergyConvergence(StateIn&);
    00219     MolEnergyConvergence(const Ref<KeyVal>&);
    00220     virtual ~MolEnergyConvergence();
    00221
    00222     void save_data_state(StateOut&);
    00223
    00224     // Set the current gradient and position information.  These
    00225     //will possibly grab the cartesian infomation if we have a
    00226     //MolecularEnergy.
    00227     void get_grad(const Ref<Function> &);
    00228     void get_x(const Ref<Function> &);
    00229     void set_nextx(const RefSCVector &);
    00230
    00231     // Return nonzero if the optimization has converged.
    00232     int converged();
    00233 };
    00234
    00235 }
    00236
    00237 #endif
    00238
    00239 // Local Variables:
    00240 // mode: c++
    00241 // c-file-style: "CLJ"
    00242 // End: