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 1492 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
Revision 1731 by chrisfen, Thu Nov 11 21:47:25 2004 UTC

# Line 1 | Line 1
1 + // Thermodynamic integration is not multiprocessor friendly right now
2 +
3   #include <iostream>
4   #include <stdlib.h>
5   #include <cstdio>
# Line 12 | Line 14 | using namespace std;
14   #include "restraints/Restraints.hpp"
15   #include "brains/SimInfo.hpp"
16   #include "utils/simError.h"
17 + #include "io/basic_ifstrstream.hpp"
18  
19   #define PI 3.14159265359
20   #define TWO_PI 6.28318530718
# Line 19 | Line 22 | Restraints::Restraints(double lambdaVal, double lambda
22   Restraints::Restraints(double lambdaVal, double lambdaExp){
23    lambdaValue = lambdaVal;
24    lambdaK = lambdaExp;
25 <
25 >  vector<double> resConsts;
26    const char *jolt = " \t\n;,";
27  
28   #ifdef IS_MPI
# Line 32 | Line 35 | Restraints::Restraints(double lambdaVal, double lambda
35      
36      if (!springs) {
37        sprintf(painCave.errMsg,
38 <              "In Restraints: Unable to open HarmSpringConsts.txt for reading.\n"
39 <              "\tDefault spring constants will be loaded. If you want to specify\n"
40 <              "\tspring constants, include a three line HarmSpringConsts.txt file\n"
41 <              "\tin the current directory.\n");
38 >              "Unable to open HarmSpringConsts.txt for reading, so the\n"
39 >              "\tdefault spring constants will be loaded. If you want\n"
40 >              "\tto specify spring constants, include a three line\n"
41 >              "\tHarmSpringConsts.txt file in the execution directory.\n");
42        painCave.severity = OOPSE_WARNING;
43        painCave.isFatal = 0;
44        simError();  
# Line 47 | Line 50 | Restraints::Restraints(double lambdaVal, double lambda
50      } else  {
51        
52        springs.getline(inLine,999,'\n');
53 +      // the file is blank!
54 +      if (springs.eof()){
55 +      sprintf(painCave.errMsg,
56 +              "HarmSpringConsts.txt file is not valid.\n"
57 +              "\tThe file should contain four rows, the last three containing\n"
58 +              "\ta label and the spring constant value. They should be listed\n"
59 +              "\tin the following order: kDist (positional restrant), kTheta\n"
60 +              "\t(rot. restraint: deflection of z-axis), and kOmega (rot.\n"
61 +              "\trestraint: rotation about the z-axis).\n");
62 +      painCave.severity = OOPSE_ERROR;
63 +      painCave.isFatal = 1;
64 +      simError();  
65 +      }
66 +      // read in spring constants and check to make sure it is a valid file
67        springs.getline(inLine,999,'\n');
68 <      token = strtok(inLine,jolt);
69 <      token = strtok(NULL,jolt);
70 <      strcpy(inValue,token);
71 <      kDist = (atof(inValue));
72 <      springs.getline(inLine,999,'\n');
73 <      token = strtok(inLine,jolt);
74 <      token = strtok(NULL,jolt);
75 <      strcpy(inValue,token);
76 <      kTheta = (atof(inValue));
77 <      springs.getline(inLine,999,'\n');
78 <      token = strtok(inLine,jolt);
79 <      token = strtok(NULL,jolt);
80 <      strcpy(inValue,token);
81 <      kOmega = (atof(inValue));
82 <      springs.close();
68 >      while (!springs.eof()){
69 >        if (NULL != inLine){
70 >          token = strtok(inLine,jolt);
71 >          token = strtok(NULL,jolt);
72 >          if (NULL != token){
73 >            strcpy(inValue,token);
74 >            resConsts.push_back(atof(inValue));
75 >          }
76 >        }
77 >        springs.getline(inLine,999,'\n');
78 >      }
79 >      if (resConsts.size() == 3){
80 >        kDist = resConsts[0];
81 >        kTheta = resConsts[1];
82 >        kOmega = resConsts[2];
83 >      }
84 >      else {
85 >        sprintf(painCave.errMsg,
86 >                "HarmSpringConsts.txt file is not valid.\n"
87 >                "\tThe file should contain four rows, the last three containing\n"
88 >                "\ta label and the spring constant value. They should be listed\n"
89 >                "\tin the following order: kDist (positional restrant), kTheta\n"
90 >                "\t(rot. restraint: deflection of z-axis), and kOmega (rot.\n"
91 >                "\trestraint: rotation about the z-axis).\n");
92 >        painCave.severity = OOPSE_ERROR;
93 >        painCave.isFatal = 1;
94 >        simError();  
95 >      }
96      }
97   #ifdef IS_MPI
98    }
# Line 179 | Line 209 | double Restraints::Calc_Restraint_Forces(vector<StuntD
209        Calc_body_thetaVal( A, i );
210        omegaPass = vecParticles[i]->getZangle();
211        Calc_body_omegaVal( A, omegaPass );
182
183      if (omega > PI || omega < -PI)
184        cout << "oops... " << omega << "\n";
212  
213        // first we calculate the derivatives
214        dVdrx = -kDist*delRx;
# Line 266 | Line 293 | void Restraints::Store_Init_Info(vector<StuntDouble*>
293   }
294  
295   void Restraints::Store_Init_Info(vector<StuntDouble*> vecParticles){
296 +  int idealSize;
297    double pos[3];
298    double A[3][3];
299    double RfromQ[3][3];
300    double quat0, quat1, quat2, quat3;
301    double dot;
302 < //   char *token;
275 < //   char fileName[200];
276 < //   char angleName[200];
277 < //   char inLine[1000];
278 < //   char inValue[200];
302 >  vector<double> tempZangs;
303    const char *delimit = " \t\n;,";
304  
305    //open the idealCrystal.in file and zAngle.ang file
306    strcpy(fileName, "idealCrystal.in");
307    strcpy(angleName, "zAngle.ang");
308    
309 <  ifstream crystalIn(fileName);
310 <  ifstream angleIn(angleName);
309 >  ifstrstream crystalIn(fileName);
310 >  ifstrstream angleIn(angleName);
311  
312 +  // check to see if these files are present in the execution directory
313    if (!crystalIn) {
314      sprintf(painCave.errMsg,
315              "Restraints Error: Unable to open idealCrystal.in for reading.\n"
316 <            "\tMake sure a reference crystal file is in the current directory.\n");
316 >            "\tMake sure a ref. crystal file is in the working directory.\n");
317 >    painCave.severity = OOPSE_ERROR;
318      painCave.isFatal = 1;
319      simError();  
294    
295    return;
320    }
321  
322 +  // it's not fatal to lack a zAngle.ang file, it just means you're starting
323 +  // from the ideal crystal state
324    if (!angleIn) {
325      sprintf(painCave.errMsg,
326              "Restraints Warning: The lack of a zAngle.ang file is mildly\n"
327              "\tunsettling... This means the simulation is starting from the\n"
328              "\tidealCrystal.in reference configuration, so the omega values\n"
329 <            "\twill all be set to zero. If this is not the case, you should\n"
330 <            "\tquestion your results.\n");
329 >            "\twill all be set to zero. If this is not the case, the energy\n"
330 >            "\tcalculations will be wrong.\n");
331 >    painCave.severity = OOPSE_WARNING;
332      painCave.isFatal = 0;
333      simError();  
334    }
# Line 309 | Line 336 | void Restraints::Store_Init_Info(vector<StuntDouble*>
336    // A rather specific reader for OOPSE .eor files...
337    // Let's read in the perfect crystal file
338    crystalIn.getline(inLine,999,'\n');
339 +  // check to see if the crystal file is the same length as starting config.
340 +  token = strtok(inLine,delimit);
341 +  strcpy(inValue,token);
342 +  idealSize = atoi(inValue);
343 +  if (idealSize != vecParticles.size()) {
344 +    sprintf(painCave.errMsg,
345 +            "Restraints Error: Reference crystal file is not valid.\n"
346 +            "\tMake sure the idealCrystal.in file is the same size as the\n"
347 +            "\tstarting configuration. Using an incompatable crystal will\n"
348 +            "\tlead to energy calculation failures.\n");
349 +    painCave.severity = OOPSE_ERROR;
350 +    painCave.isFatal = 1;
351 +    simError();  
352 +  }
353 +  // else, the file is okay... let's continue
354    crystalIn.getline(inLine,999,'\n');
355    
356    for (i=0; i<vecParticles.size(); i++) {
# Line 362 | Line 404 | void Restraints::Store_Init_Info(vector<StuntDouble*>
404      vY0.push_back(RfromQ[1][1]/normalize);
405      vZ0.push_back(RfromQ[1][2]/normalize);
406    }
407 +  crystalIn.close();
408  
409 <  // now we can read in the zAngle.ang file
409 >  // now we read in the zAngle.ang file
410    if (angleIn){
411      angleIn.getline(inLine,999,'\n');
412 <    for (i=0; i<vecParticles.size(); i++) {
413 <      angleIn.getline(inLine,999,'\n');
412 >    angleIn.getline(inLine,999,'\n');
413 >    while (!angleIn.eof()) {
414        token = strtok(inLine,delimit);
415        strcpy(inValue,token);
416 <      vecParticles[i]->setZangle(atof(inValue));
416 >      tempZangs.push_back(atof(inValue));
417 >      angleIn.getline(inLine,999,'\n');
418      }
419 +
420 +    // test to make sure the zAngle.ang file is the proper length
421 +    if (tempZangs.size() == vecParticles.size())
422 +      for (i=0; i<vecParticles.size(); i++)
423 +        vecParticles[i]->setZangle(tempZangs[i]);
424 +    else {
425 +      sprintf(painCave.errMsg,
426 +              "Restraints Error: the supplied zAngle file is not valid.\n"
427 +              "\tMake sure the zAngle.ang file matches with the initial\n"
428 +              "\tconfiguration (i.e. they're the same length). Using the wrong\n"
429 +              "\tzAngle file will lead to errors in the energy calculations.\n");
430 +      painCave.severity = OOPSE_ERROR;
431 +      painCave.isFatal = 1;
432 +      simError();  
433 +    }
434    }
435 +  angleIn.close();
436  
437    return;
438   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines