FourthDimContrib.h

Go to the documentation of this file.
00001 //
00002 // Created by Santosh Putta, Nov 2006
00003 //
00004 #ifndef __RD_FOURTHDIMCONTRIB_H__
00005 #define __RD_FOURTHDIMCONTRIB_H__
00006 
00007 #include <RDGeneral/Invariant.h>
00008 #include <ForceField/Contrib.h>
00009 #include <ForceField/ForceField.h>
00010 
00011 namespace DistGeom {
00012   //! A term used in penalizing chirality violations
00013   //!
00014   class FourthDimContrib : public ForceFields::ForceFieldContrib {
00015   public:
00016     FourthDimContrib() : d_idx(0), d_weight(0.0) {};
00017 
00018     //! Constructor
00019     /*!
00020       \param owner       pointer to the owning ForceField
00021       \param idx        the index of the atom to be considered
00022       \param weight     (optional) the weight to be used for this contrib
00023                         
00024     */
00025     FourthDimContrib(ForceFields::ForceField *owner,unsigned int idx,
00026                      double weight) : d_idx(idx), d_weight(weight) {
00027       PRECONDITION(owner,"bad force field");
00028       PRECONDITION(owner->dimension()==4,"force field has wrong dimension");
00029       dp_forceField=owner;
00030     };
00031 
00032     //! return the contribution of this contrib to the energy of a given state 
00033     double getEnergy(double *pos) const {
00034       PRECONDITION(dp_forceField,"no owner");
00035       PRECONDITION(dp_forceField->dimension()==4,"force field has wrong dimension");
00036       PRECONDITION(pos,"bad vector");
00037       unsigned int pid = d_idx*dp_forceField->dimension() + 3;
00038       return d_weight*pos[pid]*pos[pid];
00039     }
00040     
00041     //! calculate the contribution of this contrib to the gradient at a given state
00042     void getGrad(double *pos, double *grad) const {
00043       PRECONDITION(dp_forceField,"no owner");
00044       PRECONDITION(dp_forceField->dimension()==4,"force field has wrong dimension");
00045       PRECONDITION(pos,"bad vector");
00046       unsigned int pid = d_idx*dp_forceField->dimension() + 3;
00047       grad[pid] += d_weight*pos[pid];
00048     }
00049   private:
00050     unsigned int d_idx;
00051     double d_weight;
00052   };
00053 }
00054 
00055 #endif
00056     

Generated on Sat May 24 08:36:32 2008 for RDCode by  doxygen 1.5.3