ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/restraints/Restraints.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/restraints/Restraints.cpp (file contents):
Revision 1772 by chrisfen, Tue Nov 23 22:48:31 2004 UTC vs.
Revision 2101 by chrisfen, Thu Mar 10 15:10:24 2005 UTC

# Line 1 | Line 1
1 < // Thermodynamic integration is not multiprocessor friendly right now
1 > /*
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 > *
4 > * The University of Notre Dame grants you ("Licensee") a
5 > * non-exclusive, royalty free, license to use, modify and
6 > * redistribute this software in source and binary code form, provided
7 > * that the following conditions are met:
8 > *
9 > * 1. Acknowledgement of the program authors must be made in any
10 > *    publication of scientific results based in part on use of the
11 > *    program.  An acceptable form of acknowledgement is citation of
12 > *    the article in which the program was described (Matthew
13 > *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 > *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 > *    Parallel Simulation Engine for Molecular Dynamics,"
16 > *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 > *
18 > * 2. Redistributions of source code must retain the above copyright
19 > *    notice, this list of conditions and the following disclaimer.
20 > *
21 > * 3. Redistributions in binary form must reproduce the above copyright
22 > *    notice, this list of conditions and the following disclaimer in the
23 > *    documentation and/or other materials provided with the
24 > *    distribution.
25 > *
26 > * This software is provided "AS IS," without a warranty of any
27 > * kind. All express or implied conditions, representations and
28 > * warranties, including any implied warranty of merchantability,
29 > * fitness for a particular purpose or non-infringement, are hereby
30 > * excluded.  The University of Notre Dame and its licensors shall not
31 > * be liable for any damages suffered by licensee as a result of
32 > * using, modifying or distributing the software or its
33 > * derivatives. In no event will the University of Notre Dame or its
34 > * licensors be liable for any lost revenue, profit or data, or for
35 > * direct, indirect, special, consequential, incidental or punitive
36 > * damages, however caused and regardless of the theory of liability,
37 > * arising out of the use of or inability to use software, even if the
38 > * University of Notre Dame has been advised of the possibility of
39 > * such damages.
40 > */
41  
3 #include <iostream>
42   #include <stdlib.h>
5 #include <cstdio>
6 #include <fstream>
7 #include <iomanip>
8 #include <string>
9 #include <cstring>
43   #include <math.h>
44  
45   using namespace std;
46  
47   #include "restraints/Restraints.hpp"
48 < #include "brains/SimInfo.hpp"
48 > #include "primitives/Molecule.hpp"
49   #include "utils/simError.h"
17 #include "io/basic_ifstrstream.hpp"
50  
19 #ifdef IS_MPI
20 #include<mpi.h>
21 #include "brains/mpiSimulation.hpp"
22 #endif // is_mpi
23
51   #define PI 3.14159265359
52   #define TWO_PI 6.28318530718
53  
54 < Restraints::Restraints(double lambdaVal, double lambdaExp){
55 <  lambdaValue = lambdaVal;
56 <  lambdaK = lambdaExp;
57 <  vector<double> resConsts;
58 <  const char *jolt = " \t\n;,";
54 > namespace oopse {
55 >  
56 >  Restraints::Restraints(SimInfo* info, double lambdaVal, double lambdaExp){
57 >    info_ = info;
58 >    Globals* simParam = info_->getSimParams();
59  
60 < #ifdef IS_MPI
61 <  if(worldRank == 0 ){
35 < #endif // is_mpi
36 <
37 <    strcpy(springName, "HarmSpringConsts.txt");
60 >    lambdaValue = lambdaVal;
61 >    lambdaK = lambdaExp;
62      
63 <    ifstream springs(springName);
64 <    
65 <    if (!springs) {
42 <      sprintf(painCave.errMsg,
43 <              "Unable to open HarmSpringConsts.txt for reading, so the\n"
44 <              "\tdefault spring constants will be loaded. If you want\n"
45 <              "\tto specify spring constants, include a three line\n"
46 <              "\tHarmSpringConsts.txt file in the execution directory.\n");
47 <      painCave.severity = OOPSE_WARNING;
48 <      painCave.isFatal = 0;
49 <      simError();  
50 <      
51 <      // load default spring constants
52 <      kDist  = 6;  // spring constant in units of kcal/(mol*ang^2)
53 <      kTheta = 7.5;   // in units of kcal/mol
54 <      kOmega = 13.5;   // in units of kcal/mol
55 <    } else  {
56 <      
57 <      springs.getline(inLine,999,'\n');
58 <      // the file is blank!
59 <      if (springs.eof()){
60 <      sprintf(painCave.errMsg,
61 <              "HarmSpringConsts.txt file is not valid.\n"
62 <              "\tThe file should contain four rows, the last three containing\n"
63 <              "\ta label and the spring constant value. They should be listed\n"
64 <              "\tin the following order: kDist (positional restrant), kTheta\n"
65 <              "\t(rot. restraint: deflection of z-axis), and kOmega (rot.\n"
66 <              "\trestraint: rotation about the z-axis).\n");
67 <      painCave.severity = OOPSE_ERROR;
68 <      painCave.isFatal = 1;
69 <      simError();  
63 >    if (simParam->getUseSolidThermInt()) {
64 >      if (simParam->haveDistSpringConst()) {
65 >        kDist = simParam->getDistSpringConst();
66        }
67 <      // read in spring constants and check to make sure it is a valid file
68 <      springs.getline(inLine,999,'\n');
69 <      while (!springs.eof()){
70 <        if (NULL != inLine){
71 <          token = strtok(inLine,jolt);
72 <          token = strtok(NULL,jolt);
73 <          if (NULL != token){
74 <            strcpy(inValue,token);
75 <            resConsts.push_back(atof(inValue));
76 <          }
81 <        }
82 <        springs.getline(inLine,999,'\n');
67 >      else{
68 >        kDist = 6.0;
69 >        sprintf(painCave.errMsg,
70 >                "ThermoIntegration Warning: the spring constant for the\n"
71 >                "\ttranslational restraint was not specified. OOPSE will use\n"
72 >                "\ta default value of %f. To set it to something else, use\n"
73 >                "\tthe thermIntDistSpringConst variable.\n",
74 >                kDist);
75 >        painCave.isFatal = 0;
76 >        simError();
77        }
78 <      if (resConsts.size() == 3){
79 <        kDist = resConsts[0];
86 <        kTheta = resConsts[1];
87 <        kOmega = resConsts[2];
78 >      if (simParam->haveThetaSpringConst()) {
79 >        kTheta = simParam->getThetaSpringConst();
80        }
81 <      else {
82 <        sprintf(painCave.errMsg,
83 <                "HarmSpringConsts.txt file is not valid.\n"
84 <                "\tThe file should contain four rows, the last three containing\n"
85 <                "\ta label and the spring constant value. They should be listed\n"
86 <                "\tin the following order: kDist (positional restrant), kTheta\n"
87 <                "\t(rot. restraint: deflection of z-axis), and kOmega (rot.\n"
88 <                "\trestraint: rotation about the z-axis).\n");
89 <        painCave.severity = OOPSE_ERROR;
90 <        painCave.isFatal = 1;
99 <        simError();  
81 >      else{
82 >        kTheta = 7.5;
83 >        sprintf(painCave.errMsg,
84 >                "ThermoIntegration Warning: the spring constant for the\n"
85 >                "\tdeflection orientational restraint was not specified.\n"
86 >                "\tOOPSE will use a default value of %f. To set it to\n"
87 >                "\tsomething else, use the thermIntThetaSpringConst variable.\n",
88 >                kTheta);
89 >        painCave.isFatal = 0;
90 >        simError();
91        }
92 +      if (simParam->haveOmegaSpringConst()) {
93 +        kOmega = simParam->getOmegaSpringConst();
94 +      }
95 +      else{
96 +        kOmega = 13.5;
97 +        sprintf(painCave.errMsg,
98 +                "ThermoIntegration Warning: the spring constant for the\n"
99 +                "\tspin orientational restraint was not specified. OOPSE\n"
100 +                "\twill use a default value of %f. To set it to something\n"
101 +                "\telse, use the thermIntOmegaSpringConst variable.\n",
102 +                kOmega);
103 +        painCave.isFatal = 0;
104 +        simError();
105 +      }
106      }
107 < #ifdef IS_MPI
107 >    
108 >    // build a RestReader and read in important information
109 >    restRead_ = new RestReader(info_);
110 >    restRead_->readIdealCrystal();
111 >    restRead_->readZangle();
112 >    
113 >    delete restRead_;
114 >    restRead_ = NULL;
115 >    
116    }
117    
118 <  MPI_Bcast(&kDist, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
119 <  MPI_Bcast(&kTheta, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
107 <  MPI_Bcast(&kOmega, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
118 >  Restraints::~Restraints(){
119 >  }
120    
121 <  sprintf( checkPointMsg,
122 <           "Sucessfully opened and read spring file.\n");
123 <  MPIcheckPoint();
124 <
125 < #endif // is_mpi
121 >  void Restraints::Calc_rVal(Vector3d &position, double refPosition[3]){
122 >    delRx = position.x() - refPosition[0];
123 >    delRy = position.y() - refPosition[1];
124 >    delRz = position.z() - refPosition[2];
125 >    
126 >    return;
127 >  }
128    
129 <  sprintf(painCave.errMsg,
130 <          "The spring constants for thermodynamic integration are:\n"
131 <          "\tkDist = %lf\n"
132 <          "\tkTheta = %lf\n"
133 <          "\tkOmega = %lf\n", kDist, kTheta, kOmega);
134 <  painCave.severity = OOPSE_INFO;
135 <  painCave.isFatal = 0;
136 <  simError();  
137 < }
138 <
139 < Restraints::~Restraints(){
140 < }
141 <
142 < void Restraints::Calc_rVal(double position[3], double refPosition[3]){
143 <  delRx = position[0] - refPosition[0];
144 <  delRy = position[1] - refPosition[1];
145 <  delRz = position[2] - refPosition[2];
132 <
133 <  return;
134 < }
135 <
136 < void Restraints::Calc_body_thetaVal(double matrix[3][3], double refUnit[3]){
137 <  ub0x = matrix[0][0]*refUnit[0] + matrix[0][1]*refUnit[1]
138 <    + matrix[0][2]*refUnit[2];
139 <  ub0y = matrix[1][0]*refUnit[0] + matrix[1][1]*refUnit[1]
140 <    + matrix[1][2]*refUnit[2];
141 <  ub0z = matrix[2][0]*refUnit[0] + matrix[2][1]*refUnit[1]
142 <    + matrix[2][2]*refUnit[2];
143 <
144 <  normalize = sqrt(ub0x*ub0x + ub0y*ub0y + ub0z*ub0z);
145 <  ub0x = ub0x/normalize;
146 <  ub0y = ub0y/normalize;
147 <  ub0z = ub0z/normalize;
148 <
149 <  // Theta is the dot product of the reference and new z-axes
150 <  theta = acos(ub0z);
151 <
152 <  return;
153 < }
154 <
155 < void Restraints::Calc_body_omegaVal(double matrix[3][3], double zAngle){
156 <  double zRotator[3][3];
157 <  double tempOmega;
158 <  double wholeTwoPis;
159 <  // Use the omega accumulated from the rotation propagation
160 <  omega = zAngle;
161 <
162 <  // translate the omega into a range between -PI and PI
163 <  if (omega < -PI){
164 <    tempOmega = omega / -TWO_PI;
165 <    wholeTwoPis = floor(tempOmega);
166 <    tempOmega = omega + TWO_PI*wholeTwoPis;
167 <    if (tempOmega < -PI)
168 <      omega = tempOmega + TWO_PI;
169 <    else
170 <      omega = tempOmega;
129 >  void Restraints::Calc_body_thetaVal(RotMat3x3d &matrix, double refUnit[3]){
130 >    ub0x = matrix(0,0)*refUnit[0] + matrix(0,1)*refUnit[1]
131 >    + matrix(0,2)*refUnit[2];
132 >    ub0y = matrix(1,0)*refUnit[0] + matrix(1,1)*refUnit[1]
133 >      + matrix(1,2)*refUnit[2];
134 >    ub0z = matrix(2,0)*refUnit[0] + matrix(2,1)*refUnit[1]
135 >      + matrix(2,2)*refUnit[2];
136 >    
137 >    normalize = sqrt(ub0x*ub0x + ub0y*ub0y + ub0z*ub0z);
138 >    ub0x = ub0x/normalize;
139 >    ub0y = ub0y/normalize;
140 >    ub0z = ub0z/normalize;
141 >    
142 >    // Theta is the dot product of the reference and new z-axes
143 >    theta = acos(ub0z);
144 >    
145 >    return;
146    }
147 <  if (omega > PI){
148 <    tempOmega = omega / TWO_PI;
149 <    wholeTwoPis = floor(tempOmega);
150 <    tempOmega = omega - TWO_PI*wholeTwoPis;
151 <    if (tempOmega > PI)
152 <      omega = tempOmega - TWO_PI;  
153 <    else
179 <      omega = tempOmega;
180 <  }
181 <
182 <  vb0x = sin(omega);
183 <  vb0y = cos(omega);
184 <  vb0z = 0.0;
185 <
186 <  normalize = sqrt(vb0x*vb0x + vb0y*vb0y + vb0z*vb0z);
187 <  vb0x = vb0x/normalize;
188 <  vb0y = vb0y/normalize;
189 <  vb0z = vb0z/normalize;
190 <
191 <  return;
192 < }
193 <
194 < double Restraints::Calc_Restraint_Forces(vector<StuntDouble*> vecParticles){
195 <  double pos[3];
196 <  double A[3][3];
197 <  double refPos[3];
198 <  double refVec[3];
199 <  double tolerance;
200 <  double tempPotent;
201 <  double factor;
202 <  double spaceTrq[3];
203 <  double omegaPass;
204 <  GenericData* data;
205 <  DoubleGenericData* doubleData;
206 <
207 <  tolerance = 5.72957795131e-7;
208 <
209 <  harmPotent = 0.0;  // zero out the global harmonic potential variable
210 <
211 <  factor = 1 - pow(lambdaValue, lambdaK);
212 <
213 <  for (i=0; i<vecParticles.size(); i++){
214 <    // obtain the current and reference positions
215 <    vecParticles[i]->getPos(pos);
216 <
217 <    data = vecParticles[i]->getProperty("refPosX");
218 <    if (data){
219 <      doubleData = dynamic_cast<DoubleGenericData*>(data);
220 <      if (!doubleData){
221 <        cerr << "Can't obtain refPosX from StuntDouble\n";
222 <        return 0.0;
223 <      }
224 <      else refPos[0] = doubleData->getData();
225 <    }
226 <    data = vecParticles[i]->getProperty("refPosY");
227 <    if (data){
228 <      doubleData = dynamic_cast<DoubleGenericData*>(data);
229 <      if (!doubleData){
230 <        cerr << "Can't obtain refPosY from StuntDouble\n";
231 <        return 0.0;
232 <      }
233 <      else refPos[1] = doubleData->getData();
234 <    }
235 <    data = vecParticles[i]->getProperty("refPosZ");
236 <    if (data){
237 <      doubleData = dynamic_cast<DoubleGenericData*>(data);
238 <      if (!doubleData){
239 <        cerr << "Can't obtain refPosZ from StuntDouble\n";
240 <        return 0.0;
241 <      }
242 <      else refPos[2] = doubleData->getData();
243 <    }
244 <
245 <    // calculate the displacement
246 <    Calc_rVal( pos, refPos );
247 <
248 <    // calculate the derivatives
249 <    dVdrx = -kDist*delRx;
250 <    dVdry = -kDist*delRy;
251 <    dVdrz = -kDist*delRz;
147 >  
148 >  void Restraints::Calc_body_omegaVal(double zAngle){
149 >    double zRotator[3][3];
150 >    double tempOmega;
151 >    double wholeTwoPis;
152 >    // Use the omega accumulated from the rotation propagation
153 >    omega = zAngle;
154      
155 <    // next we calculate the restraint forces
156 <    restraintFrc[0] = dVdrx;
157 <    restraintFrc[1] = dVdry;
158 <    restraintFrc[2] = dVdrz;
159 <    tempPotent = 0.5*kDist*(delRx*delRx + delRy*delRy + delRz*delRz);
160 <
161 <    // apply the lambda scaling factor to the forces
162 <    for (j = 0; j < 3; j++) restraintFrc[j] *= factor;
163 <
164 <    // and add the temporary force to the total force
165 <    vecParticles[i]->addFrc(restraintFrc);
166 <
167 <    // if the particle is directional, we accumulate the rot. restraints
168 <    if (vecParticles[i]->isDirectional()){
169 <
170 <      // get the current rotation matrix and reference vector
171 <      vecParticles[i]->getA(A);
172 <      
173 <      data = vecParticles[i]->getProperty("refVectorX");
174 <      if (data){
175 <        doubleData = dynamic_cast<DoubleGenericData*>(data);
176 <        if (!doubleData){
177 <          cerr << "Can't obtain refVectorX from StuntDouble\n";
178 <          return 0.0;
179 <        }
180 <        else refVec[0] = doubleData->getData();
155 >    // translate the omega into a range between -PI and PI
156 >    if (omega < -PI){
157 >      tempOmega = omega / -TWO_PI;
158 >      wholeTwoPis = floor(tempOmega);
159 >      tempOmega = omega + TWO_PI*wholeTwoPis;
160 >      if (tempOmega < -PI)
161 >        omega = tempOmega + TWO_PI;
162 >      else
163 >        omega = tempOmega;
164 >    }
165 >    if (omega > PI){
166 >      tempOmega = omega / TWO_PI;
167 >      wholeTwoPis = floor(tempOmega);
168 >      tempOmega = omega - TWO_PI*wholeTwoPis;
169 >      if (tempOmega > PI)
170 >        omega = tempOmega - TWO_PI;  
171 >      else
172 >        omega = tempOmega;
173 >    }
174 >    
175 >    vb0x = sin(omega);
176 >    vb0y = cos(omega);
177 >    vb0z = 0.0;
178 >    
179 >    normalize = sqrt(vb0x*vb0x + vb0y*vb0y + vb0z*vb0z);
180 >    vb0x = vb0x/normalize;
181 >    vb0y = vb0y/normalize;
182 >    vb0z = vb0z/normalize;
183 >    
184 >    return;
185 >  }
186 >  
187 >  double Restraints::Calc_Restraint_Forces(){
188 >    SimInfo::MoleculeIterator mi;
189 >    Molecule* mol;
190 >    Molecule::IntegrableObjectIterator ii;
191 >    StuntDouble* integrableObject;
192 >    Vector3d pos;
193 >    RotMat3x3d A;
194 >    double refPos[3];
195 >    double refVec[3];
196 >    double tolerance;
197 >    double tempPotent;
198 >    double factor;
199 >    double spaceTrq[3];
200 >    double omegaPass;
201 >    GenericData* data;
202 >    DoubleGenericData* doubleData;
203 >    
204 >    tolerance = 5.72957795131e-7;
205 >    
206 >    harmPotent = 0.0;  // zero out the global harmonic potential variable
207 >    
208 >    factor = 1 - pow(lambdaValue, lambdaK);
209 >    
210 >    for (mol = info_->beginMolecule(mi); mol != NULL;
211 >         mol = info_->nextMolecule(mi)) {
212 >      for (integrableObject = mol->beginIntegrableObject(ii);
213 >           integrableObject != NULL;
214 >           integrableObject = mol->nextIntegrableObject(ii)) {
215 >        
216 >        // obtain the current and reference positions
217 >        pos = integrableObject->getPos();
218 >        
219 >        data = integrableObject->getPropertyByName("refPosX");
220 >        if (data){
221 >          doubleData = dynamic_cast<DoubleGenericData*>(data);
222 >          if (!doubleData){
223 >            cerr << "Can't obtain refPosX from StuntDouble\n";
224 >            return 0.0;
225 >          }
226 >          else refPos[0] = doubleData->getData();
227 >        }
228 >        data = integrableObject->getPropertyByName("refPosY");
229 >        if (data){
230 >          doubleData = dynamic_cast<DoubleGenericData*>(data);
231 >          if (!doubleData){
232 >            cerr << "Can't obtain refPosY from StuntDouble\n";
233 >            return 0.0;
234 >          }
235 >          else refPos[1] = doubleData->getData();
236 >        }
237 >        data = integrableObject->getPropertyByName("refPosZ");
238 >        if (data){
239 >          doubleData = dynamic_cast<DoubleGenericData*>(data);
240 >          if (!doubleData){
241 >            cerr << "Can't obtain refPosZ from StuntDouble\n";
242 >            return 0.0;
243 >          }
244 >          else refPos[2] = doubleData->getData();
245 >        }
246 >        
247 >        // calculate the displacement
248 >        Calc_rVal( pos, refPos );
249 >        
250 >        // calculate the derivatives
251 >        dVdrx = -kDist*delRx;
252 >        dVdry = -kDist*delRy;
253 >        dVdrz = -kDist*delRz;
254 >        
255 >        // next we calculate the restraint forces
256 >        restraintFrc[0] = dVdrx;
257 >        restraintFrc[1] = dVdry;
258 >        restraintFrc[2] = dVdrz;
259 >        tempPotent = 0.5*kDist*(delRx*delRx + delRy*delRy + delRz*delRz);
260 >        
261 >        // apply the lambda scaling factor to the forces
262 >        for (j = 0; j < 3; j++) restraintFrc[j] *= factor;
263 >        
264 >        // and add the temporary force to the total force
265 >        integrableObject->addFrc(restraintFrc);
266 >        
267 >        // if the particle is directional, we accumulate the rot. restraints
268 >        if (integrableObject->isDirectional()){
269 >          
270 >          // get the current rotation matrix and reference vector
271 >          A = integrableObject->getA();
272 >          
273 >          data = integrableObject->getPropertyByName("refVectorX");
274 >          if (data){
275 >            doubleData = dynamic_cast<DoubleGenericData*>(data);
276 >            if (!doubleData){
277 >              cerr << "Can't obtain refVectorX from StuntDouble\n";
278 >              return 0.0;
279 >            }
280 >            else refVec[0] = doubleData->getData();
281 >          }
282 >          data = integrableObject->getPropertyByName("refVectorY");
283 >          if (data){
284 >            doubleData = dynamic_cast<DoubleGenericData*>(data);
285 >            if (!doubleData){
286 >              cerr << "Can't obtain refVectorY from StuntDouble\n";
287 >              return 0.0;
288 >            }
289 >            else refVec[1] = doubleData->getData();
290 >          }
291 >          data = integrableObject->getPropertyByName("refVectorZ");
292 >          if (data){
293 >            doubleData = dynamic_cast<DoubleGenericData*>(data);
294 >            if (!doubleData){
295 >              cerr << "Can't obtain refVectorZ from StuntDouble\n";
296 >              return 0.0;
297 >            }
298 >            else refVec[2] = doubleData->getData();
299 >          }
300 >          
301 >          // calculate the theta and omega displacements
302 >          Calc_body_thetaVal( A, refVec );
303 >          omegaPass = integrableObject->getZangle();
304 >          Calc_body_omegaVal( omegaPass );
305 >          
306 >          // uTx... and vTx... are the body-fixed z and y unit vectors
307 >          uTx = 0.0;
308 >          uTy = 0.0;
309 >          uTz = 1.0;
310 >          vTx = 0.0;
311 >          vTy = 1.0;
312 >          vTz = 0.0;
313 >          
314 >          dVdux = 0.0;
315 >          dVduy = 0.0;
316 >          dVduz = 0.0;
317 >          dVdvx = 0.0;
318 >          dVdvy = 0.0;
319 >          dVdvz = 0.0;
320 >          
321 >          if (fabs(theta) > tolerance) {
322 >            dVdux = -(kTheta*theta/sin(theta))*ub0x;
323 >            dVduy = -(kTheta*theta/sin(theta))*ub0y;
324 >            dVduz = -(kTheta*theta/sin(theta))*ub0z;
325 >          }
326 >          
327 >          if (fabs(omega) > tolerance) {
328 >            dVdvx = -(kOmega*omega/sin(omega))*vb0x;
329 >            dVdvy = -(kOmega*omega/sin(omega))*vb0y;
330 >            dVdvz = -(kOmega*omega/sin(omega))*vb0z;
331 >          }
332 >          
333 >          // next we calculate the restraint torques
334 >          restraintTrq[0] = 0.0;
335 >          restraintTrq[1] = 0.0;
336 >          restraintTrq[2] = 0.0;
337 >          
338 >          if (fabs(omega) > tolerance) {
339 >            restraintTrq[0] += 0.0;
340 >            restraintTrq[1] += 0.0;
341 >            restraintTrq[2] += vTy*dVdvx;
342 >            tempPotent += 0.5*(kOmega*omega*omega);
343 >          }
344 >          if (fabs(theta) > tolerance) {
345 >            restraintTrq[0] += (uTz*dVduy);
346 >            restraintTrq[1] += -(uTz*dVdux);
347 >            restraintTrq[2] += 0.0;
348 >            tempPotent += 0.5*(kTheta*theta*theta);
349 >          }
350 >          
351 >          // apply the lambda scaling factor to these torques
352 >          for (j = 0; j < 3; j++) restraintTrq[j] *= factor;
353 >          
354 >          // now we need to convert from body-fixed to space-fixed torques
355 >          spaceTrq[0] = A(0,0)*restraintTrq[0] + A(1,0)*restraintTrq[1]
356 >            + A(2,0)*restraintTrq[2];
357 >          spaceTrq[1] = A(0,1)*restraintTrq[0] + A(1,1)*restraintTrq[1]
358 >            + A(2,1)*restraintTrq[2];
359 >          spaceTrq[2] = A(0,2)*restraintTrq[0] + A(1,2)*restraintTrq[1]
360 >            + A(2,2)*restraintTrq[2];
361 >          
362 >          // now pass this temporary torque vector to the total torque
363 >          integrableObject->addTrq(spaceTrq);
364 >        }
365 >        
366 >        // update the total harmonic potential with this object's contribution
367 >        harmPotent += tempPotent;
368        }
280      data = vecParticles[i]->getProperty("refVectorY");
281      if (data){
282        doubleData = dynamic_cast<DoubleGenericData*>(data);
283        if (!doubleData){
284          cerr << "Can't obtain refVectorY from StuntDouble\n";
285          return 0.0;
286        }
287        else refVec[1] = doubleData->getData();
288      }
289      data = vecParticles[i]->getProperty("refVectorZ");
290      if (data){
291        doubleData = dynamic_cast<DoubleGenericData*>(data);
292        if (!doubleData){
293          cerr << "Can't obtain refVectorZ from StuntDouble\n";
294          return 0.0;
295        }
296        else refVec[2] = doubleData->getData();
297      }
369        
299      // calculate the theta and omega displacements
300      Calc_body_thetaVal( A, refVec );
301      omegaPass = vecParticles[i]->getZangle();
302      Calc_body_omegaVal( A, omegaPass );
303
304      // uTx... and vTx... are the body-fixed z and y unit vectors
305      uTx = 0.0;
306      uTy = 0.0;
307      uTz = 1.0;
308      vTx = 0.0;
309      vTy = 1.0;
310      vTz = 0.0;
311
312      dVdux = 0.0;
313      dVduy = 0.0;
314      dVduz = 0.0;
315      dVdvx = 0.0;
316      dVdvy = 0.0;
317      dVdvz = 0.0;
318
319      if (fabs(theta) > tolerance) {
320        dVdux = -(kTheta*theta/sin(theta))*ub0x;
321        dVduy = -(kTheta*theta/sin(theta))*ub0y;
322        dVduz = -(kTheta*theta/sin(theta))*ub0z;
323      }
324
325      if (fabs(omega) > tolerance) {
326        dVdvx = -(kOmega*omega/sin(omega))*vb0x;
327        dVdvy = -(kOmega*omega/sin(omega))*vb0y;
328        dVdvz = -(kOmega*omega/sin(omega))*vb0z;
329      }
330
331      // next we calculate the restraint torques
332      restraintTrq[0] = 0.0;
333      restraintTrq[1] = 0.0;
334      restraintTrq[2] = 0.0;
335
336      if (fabs(omega) > tolerance) {
337        restraintTrq[0] += 0.0;
338        restraintTrq[1] += 0.0;
339        restraintTrq[2] += vTy*dVdvx;
340        tempPotent += 0.5*(kOmega*omega*omega);
341      }
342      if (fabs(theta) > tolerance) {
343        restraintTrq[0] += (uTz*dVduy);
344        restraintTrq[1] += -(uTz*dVdux);
345        restraintTrq[2] += 0.0;
346        tempPotent += 0.5*(kTheta*theta*theta);
347      }
348
349      // apply the lambda scaling factor to these torques
350      for (j = 0; j < 3; j++) restraintTrq[j] *= factor;
351
352      // now we need to convert from body-fixed torques to space-fixed torques
353      spaceTrq[0] = A[0][0]*restraintTrq[0] + A[1][0]*restraintTrq[1]
354        + A[2][0]*restraintTrq[2];
355      spaceTrq[1] = A[0][1]*restraintTrq[0] + A[1][1]*restraintTrq[1]
356        + A[2][1]*restraintTrq[2];
357      spaceTrq[2] = A[0][2]*restraintTrq[0] + A[1][2]*restraintTrq[1]
358        + A[2][2]*restraintTrq[2];
359
360      // now pass this temporary torque vector to the total torque
361      vecParticles[i]->addTrq(spaceTrq);
370      }
371 <
372 <    // update the total harmonic potential with this object's contribution
373 <    harmPotent += tempPotent;
371 >    
372 >    // we can finish by returning the appropriately scaled potential energy
373 >    tempPotent = harmPotent * factor;
374 >    
375 >    return tempPotent;
376 >    
377    }
378    
379 <  // we can finish by returning the appropriately scaled potential energy
369 <  tempPotent = harmPotent * factor;
370 <  return tempPotent;
371 < }
372 <
373 < void Restraints::Write_zAngle_File(vector<StuntDouble*> vecParticles,
374 <                                   int currTime,
375 <                                   int nIntObj){
376 <
377 <  char zOutName[200];
378 <
379 <  std::cerr << nIntObj << " is the number of integrable objects\n";
380 <
381 <  //#ifndef IS_MPI
382 <  
383 <  strcpy(zOutName,"zAngle.ang");
384 <  
385 <  ofstream angleOut(zOutName);
386 <  angleOut << currTime << ": omega values at this time\n";
387 <  for (i=0; i<vecParticles.size(); i++) {
388 <    angleOut << vecParticles[i]->getZangle() << "\n";
389 <  }
390 <
391 <  return;
392 < }
393 <
394 < double Restraints::getVharm(){
395 <  return harmPotent;
396 < }
397 <
379 > }// end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines