ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/GridBuilder.cpp
Revision: 1277
Committed: Thu Jun 17 21:29:17 2004 UTC (20 years, 10 months ago) by chrisfen
File size: 3094 byte(s)
Log Message:
Added GridBuilder.cpp and .hpp.  Doesn't calculate energies yet...

File Contents

# Content
1 #include "GridBuilder.hpp"
2 #include "MatVec3.h"
3 #define PI 3.14159265359
4
5
6 GridBuilder::GridBuilder(RigidBody* rb, int bandWidth) {
7 rbMol = rb;
8 bandwidth = bandWidth;
9 thetaStep = PI / bandwidth;
10 thetaMin = thetaStep / 2.0;
11 phiStep = thetaStep * 2.0;
12
13 //zero out the rot mats
14 for (i=0; i<3; i++) {
15 for (j=0; j<3; j++) {
16 rotX[i][j] = 0.0;
17 rotZ[i][j] = 0.0;
18 rbMatrix[i][j] = 0.0;
19 }
20 }
21 }
22
23 GridBuilder::~GridBuilder() {
24 }
25
26 void GridBuilder::launchProbe(int forceField, vector<double> sigmaGrid, vector<double> sGrid,
27 vector<double> epsGrid){
28 double startDist;
29 double minDist = 10.0; //minimum start distance
30
31 //first determine the start distance - we always start at least minDist away
32 startDist = rbMol->findMaxExtent() + minDist;
33 if (startDist < minDist)
34 startDist = minDist;
35
36 initBody();
37 for (i=0; i<bandwidth; i++){
38 for (j=0; j<bandwidth; j++){
39 releaseProbe(startDist);
40 stepPhi(phiStep);
41 }
42 stepTheta(thetaStep);
43 }
44
45 }
46
47 void GridBuilder::initBody(){
48 //set up the rigid body in the starting configuration
49 stepTheta(thetaMin);
50 }
51
52 void GridBuilder::releaseProbe(double farPos){
53 int tooClose;
54 double tempPotEnergy;
55 double interpRange;
56 double interpFrac;
57
58 probeCoor = farPos;
59 tooClose = 0;
60 epsVal = 0;
61 rhoStep = 0.1; //the distance the probe atom moves between steps
62
63 while (!tooClose){
64 calcEnergy();
65 potProgress.push_back(potEnergy);
66 distProgress.push_back(probeCoor);
67
68 //if we've reached a new minimum, save the value and position
69 if (potEnergy < epsVal){
70 epsVal = potEnergy;
71 sDist = probeCoor;
72 }
73
74 //test if the probe reached the origin - if so, stop stepping closer
75 if (probeCoor < 0){
76 sigDist = 0.0;
77 tooClose = 1;
78 }
79
80 //test if the probe beyond the contact point - if not, take a step closer
81 if (potEnergy < 0){
82 sigDist = probeCoor;
83 tempPotEnergy = potEnergy;
84 probeCoor -= rhoStep;
85 }
86 else {
87 //do a linear interpolation to obtain the sigDist
88 interpRange = potEnergy - tempPotEnergy;
89 interpFrac = potEnergy / interpRange;
90 interpFrac = interpFrac * rhoStep;
91 sigDist = probeCoor + interpFrac;
92
93 //end the loop
94 tooClose = 1;
95 }
96 }
97 }
98
99 void GridBuilder::calcEnergy(){
100
101 }
102
103 void GridBuilder::stepTheta(double increment){
104 //zero out the euler angles
105 for (i=0; i<3; i++)
106 angles[i] = 0.0;
107
108 //the second euler angle is for rotation about the x-axis (we use the zxz convention)
109 angles[1] = increment;
110
111 //obtain the rotation matrix through the rigid body class
112 rbMol->doEulerToRotMat(angles, rotX);
113
114 //rotate the rigid body
115 rbMol->getA(rbMatrix);
116 matMul3(rotX, rbMatrix, rotatedMat);
117 rbMol->setA(rotatedMat);
118
119 }
120
121 void GridBuilder::stepPhi(double increment){
122 //zero out the euler angles
123 for (i=0; i<3; i++)
124 angles[i] = 0.0;
125
126 //the phi euler angle is for rotation about the z-axis (we use the zxz convention)
127 angles[0] = increment;
128
129 //obtain the rotation matrix through the rigid body class
130 rbMol->doEulerToRotMat(angles, rotZ);
131
132 //rotate the rigid body
133 rbMol->getA(rbMatrix);
134 matMul3(rotZ, rbMatrix, rotatedMat);
135 rbMol->setA(rotatedMat);
136
137 }