Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ComputeRestraints.C

Go to the documentation of this file.
00001 
00007 #include "ComputeRestraints.h"
00008 #include "Node.h"
00009 #include "Molecule.h"
00010 #include "SimParameters.h"
00011 #include "Patch.h"
00012 #include "NamdOneTools.h"
00013 
00014 /************************************************************************/
00015 /*                                                                      */
00016 /*                      FUNCTION ComputeRestraints                      */
00017 /*                                                                      */
00018 /************************************************************************/
00019 
00020 ComputeRestraints::ComputeRestraints(ComputeID c, PatchID pid)
00021   : ComputePatch(c,pid)
00022 {
00023         reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00024 
00025         SimParameters *simParams = Node::Object()->simParameters;
00026 
00027         //  Get parameters from the SimParameters object
00028         consExp = simParams->constraintExp;
00029         
00030         //****** BEGIN selective restraints (X,Y,Z) changes 
00031         consSelectOn = simParams->selectConstraintsOn;
00032         if (consSelectOn) {
00033           consSelectX = simParams->constrXOn;
00034           consSelectY = simParams->constrYOn;
00035           consSelectZ = simParams->constrZOn;
00036         }
00037         //****** END selective restraints (X,Y,Z) changes 
00038         
00039         //****** BEGIN moving constraints changes 
00040         consMoveOn = simParams->movingConstraintsOn;
00041         if (consMoveOn) {
00042           moveVel = simParams->movingConsVel;
00043         }
00044         //****** END moving constraints changes 
00045         //****** BEGIN rotating constraints changes 
00046         consRotOn = simParams->rotConstraintsOn;
00047         if (consRotOn) {
00048           rotVel = simParams->rotConsVel;
00049           rotAxis = simParams->rotConsAxis;
00050           rotPivot = simParams->rotConsPivot;
00051         }
00052         //****** END rotating constraints changes 
00053 
00054 }
00055 /*                      END OF FUNCTION ComputeRestraints               */
00056 
00057 /************************************************************************/
00058 /*                                                                      */
00059 /*                      FUNCTION ~ComputeRestraints                     */
00060 /*                                                                      */
00061 /*      This is the destructor for the ComputeRestraints force object.  */
00062 /*                                                                      */
00063 /************************************************************************/
00064 
00065 ComputeRestraints::~ComputeRestraints()
00066 
00067 {
00068         delete reduction;
00069 }
00070 /*                      END OF FUNCTION ~ComputeRestraints              */
00071 
00072 /************************************************************************/
00073 /*                                                                      */
00074 /*                              FUNCTION force                          */
00075 /*                                                                      */
00076 /************************************************************************/
00077 #ifdef MEM_OPT_VERSION
00078 void ComputeRestraints::doForce(CompAtom* p, CompAtomExt* pExt, Results* res)
00079 #else
00080 void ComputeRestraints::doForce(CompAtom* p, Results* res)
00081 #endif
00082 {
00083         Molecule *molecule = Node::Object()->molecule;
00084         Real k;                 //  Force constant
00085         BigReal scaling = Node::Object()->simParameters->constraintScaling;
00086         Vector refPos;          //  Reference position
00087         BigReal r, r2;  //  r=distance between atom position and the
00088                         //  reference position, r2 = r^2
00089         Vector Rij;     //  vector between current position and reference pos
00090         BigReal value;  //  Current calculated value
00091 
00092         // aliases to work with old code
00093         Force *f = res->f[Results::normal];
00094         BigReal energy = 0;
00095         BigReal m[9];
00096         Tensor virial;
00097         Vector netForce = 0;
00098 
00099         // BEGIN moving and rotating constraint changes ******
00100 
00101         // This version only allows one atom to be moved 
00102         // and only ALL ref positions to be rotated
00103 
00104         int currentTime = patch->flags.step;
00105         if (consRotOn) {
00106           vec_rotation_matrix(rotVel * currentTime, rotAxis, m);
00107         }
00108 
00109         // END moving and rotating constraint changes ******
00110 
00111           
00112         if (scaling != 0.) for (int localID=0; localID<numAtoms; ++localID)
00113         {
00114           if (molecule->is_atom_constrained(p[localID].id))
00115           {
00116             molecule->get_cons_params(k, refPos, p[localID].id);
00117 
00118             k *= scaling;
00119 
00120             // BEGIN moving and rotating constraint changes ******
00121             
00122             if (consMoveOn) {
00123               refPos += currentTime * moveVel;
00124             }
00125             else if(consRotOn) {
00126               refPos = mat_multiply_vec(refPos - rotPivot, m) + rotPivot;
00127             }
00128 
00129             // END moving and rotating constraint changes *******
00130 
00131             Rij = patch->lattice.delta(refPos,p[localID].position);
00132             Vector vpos = refPos - Rij;
00133 
00134             //****** BEGIN selective restraints (X,Y,Z) changes 
00135             if (consSelectOn) { // check which components we want to restrain:
00136               if (!consSelectX) {Rij.x=0.0;}  // by setting the appropriate
00137               if (!consSelectY) {Rij.y=0.0;}  // Cartesian component to zero
00138               if (!consSelectZ) {Rij.z=0.0;}  // we will avoid a restoring force
00139             }                                 // along that component, and the
00140                                               // energy will also be correct
00141             //****** END selective restraints (X,Y,Z) changes 
00142 
00143             
00144             //  Calculate the distance and the distance squared
00145             r2 = Rij.length2();
00146             r = sqrt(r2);
00147 
00148             //  Only calculate the energy and the force if the distance is
00149             //  non-zero.   Otherwise, you could end up dividing by 0, which
00150             //  is bad
00151             if (r>0.0)
00152             {
00153               value=k;
00154       
00155               //  Loop through and multiple k by r consExp times.
00156               //  i.e.  calculate kr^e
00157               //  I know, I could use pow(), but I don't trust it.
00158               for (int k=0; k<consExp; ++k)
00159               {
00160                 value *= r;
00161               }
00162 
00163               //  Add to the energy total
00164               energy += value;
00165       
00166               //  Now calculate the force, which is ekr^(e-1).  Also, divide
00167               //  by another factor of r to normalize the vector before we
00168               //  multiple it by the magnitude
00169               value *= consExp;
00170               value /= r2;
00171       
00172               Rij *= value;
00173               //iout << iINFO << "restraining force" << Rij        << "\n"; 
00174 
00175               f[localID] += Rij;
00176               netForce += Rij;
00177               virial += outer(Rij,vpos);
00178             }
00179           }
00180         }
00181 
00182         reduction->item(REDUCTION_BC_ENERGY) += energy;
00183         ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,virial);
00184         ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,netForce);
00185         reduction->submit();
00186 
00187 }
00188 /*                      END OF FUNCTION force                           */
00189 

Generated on Sat Sep 6 04:07:41 2008 for NAMD by  doxygen 1.3.9.1