# | Line 1 | Line 1 | |
---|---|---|
1 | #include "GridBuilder.hpp" | |
2 | – | #include "MatVec3.h" |
2 | #define PI 3.14159265359 | |
3 | ||
4 | ||
5 | < | GridBuilder::GridBuilder(RigidBody* rb, int bandWidth) { |
6 | < | rbMol = rb; |
7 | < | bandwidth = bandWidth; |
8 | < | thetaStep = PI / bandwidth; |
9 | < | thetaMin = thetaStep / 2.0; |
10 | < | 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 | < | } |
5 | > | GridBuilder::GridBuilder(RigidBody* rb, int gridWidth) { |
6 | > | rbMol = rb; |
7 | > | gridwidth = gridWidth; |
8 | > | thetaStep = PI / gridwidth; |
9 | > | thetaMin = thetaStep / 2.0; |
10 | > | phiStep = thetaStep * 2.0; |
11 | } | |
12 | ||
13 | GridBuilder::~GridBuilder() { | |
14 | } | |
15 | ||
16 | < | void GridBuilder::launchProbe(int forceField, vector<double> sigmaGrid, vector<double> sGrid, |
17 | < | vector<double> epsGrid){ |
18 | < | double startDist; |
19 | < | double minDist = 10.0; //minimum start distance |
16 | > | void GridBuilder::launchProbe(int forceField, vector<double> sigmaGrid, |
17 | > | vector<double> sGrid, vector<double> epsGrid){ |
18 | > | ofstream sigmaOut("sigma.grid"); |
19 | > | ofstream sOut("s.grid"); |
20 | > | ofstream epsOut("eps.grid"); |
21 | > | double startDist; |
22 | > | double phiVal; |
23 | > | double thetaVal; |
24 | > | double sigTemp, sTemp, epsTemp, sigProbe; |
25 | > | double minDist = 10.0; //minimum start distance |
26 | ||
27 | < | //first determine the start distance - we always start at least minDist away |
28 | < | startDist = rbMol->findMaxExtent() + minDist; |
29 | < | if (startDist < minDist) |
30 | < | startDist = minDist; |
31 | < | |
32 | < | initBody(); |
33 | < | for (i=0; i<bandwidth; i++){ |
34 | < | for (j=0; j<bandwidth; j++){ |
35 | < | releaseProbe(startDist); |
36 | < | stepPhi(phiStep); |
37 | < | } |
38 | < | stepTheta(thetaStep); |
39 | < | } |
40 | < | |
41 | < | } |
27 | > | sigList = sigmaGrid; |
28 | > | sList = sGrid; |
29 | > | epsList = epsGrid; |
30 | > | forcefield = forceField; |
31 | > | |
32 | > | //load the probe atom parameters |
33 | > | switch(forcefield){ |
34 | > | case 1:{ |
35 | > | rparHe = 1.4800; |
36 | > | epsHe = -0.021270; |
37 | > | }; break; |
38 | > | case 2:{ |
39 | > | rparHe = 1.14; |
40 | > | epsHe = 0.0203; |
41 | > | }; break; |
42 | > | case 3:{ |
43 | > | rparHe = 2.28; |
44 | > | epsHe = 0.020269601874; |
45 | > | }; break; |
46 | > | case 4:{ |
47 | > | rparHe = 2.5560; |
48 | > | epsHe = 0.0200; |
49 | > | }; break; |
50 | > | case 5:{ |
51 | > | rparHe = 1.14; |
52 | > | epsHe = 0.0203; |
53 | > | }; break; |
54 | > | } |
55 | > | |
56 | > | if (rparHe < 2.2) |
57 | > | sigProbe = 2*rparHe/1.12246204831; |
58 | > | else |
59 | > | sigProbe = rparHe; |
60 | > | |
61 | > | //determine the start distance - we always start at least minDist away |
62 | > | startDist = rbMol->findMaxExtent() + minDist; |
63 | > | if (startDist < minDist) |
64 | > | startDist = minDist; |
65 | ||
66 | < | void GridBuilder::initBody(){ |
67 | < | //set up the rigid body in the starting configuration |
68 | < | stepTheta(thetaMin); |
66 | > | //set the initial orientation of the body and loop over theta values |
67 | > | |
68 | > | for (k =0; k < gridwidth; k++) { |
69 | > | thetaVal = thetaMin + k*thetaStep; |
70 | > | for (j=0; j < gridwidth; j++) { |
71 | > | phiVal = j*phiStep + 0.5*PI; |
72 | > | |
73 | > | rbMol->setEuler(0.0, thetaVal, phiVal); |
74 | > | |
75 | > | releaseProbe(startDist); |
76 | > | |
77 | > | //translate the values to sigma, s, and epsilon of the rigid body |
78 | > | sigTemp = 2*sigDist - sigProbe; |
79 | > | sTemp = (2*(sDist - sigDist))/(0.122462048309) - sigProbe; |
80 | > | epsTemp = pow(epsVal, 2)/fabs(epsHe); |
81 | > | |
82 | > | sigList.push_back(sigTemp); |
83 | > | sList.push_back(sTemp); |
84 | > | epsList.push_back(epsTemp); |
85 | > | } |
86 | > | } |
87 | } | |
88 | ||
89 | void GridBuilder::releaseProbe(double farPos){ | |
90 | < | int tooClose; |
91 | < | double tempPotEnergy; |
92 | < | double interpRange; |
93 | < | double interpFrac; |
90 | > | int tooClose; |
91 | > | double tempPotEnergy; |
92 | > | double interpRange; |
93 | > | double interpFrac; |
94 | ||
95 | < | probeCoor = farPos; |
96 | < | tooClose = 0; |
97 | < | epsVal = 0; |
98 | < | rhoStep = 0.1; //the distance the probe atom moves between steps |
99 | < | |
100 | < | while (!tooClose){ |
64 | < | calcEnergy(); |
65 | < | potProgress.push_back(potEnergy); |
66 | < | distProgress.push_back(probeCoor); |
95 | > | probeCoor = farPos; |
96 | > | potProgress.clear(); |
97 | > | distProgress.clear(); |
98 | > | tooClose = 0; |
99 | > | epsVal = 0; |
100 | > | rhoStep = 0.1; //the distance the probe atom moves between steps |
101 | ||
102 | < | //if we've reached a new minimum, save the value and position |
103 | < | if (potEnergy < epsVal){ |
104 | < | epsVal = potEnergy; |
105 | < | sDist = probeCoor; |
72 | < | } |
102 | > | while (!tooClose){ |
103 | > | calcEnergy(); |
104 | > | potProgress.push_back(potEnergy); |
105 | > | distProgress.push_back(probeCoor); |
106 | ||
107 | < | //test if the probe reached the origin - if so, stop stepping closer |
108 | < | if (probeCoor < 0){ |
109 | < | sigDist = 0.0; |
110 | < | tooClose = 1; |
111 | < | } |
107 | > | //if we've reached a new minimum, save the value and position |
108 | > | if (potEnergy < epsVal){ |
109 | > | epsVal = potEnergy; |
110 | > | sDist = probeCoor; |
111 | > | } |
112 | ||
113 | < | //test if the probe beyond the contact point - if not, take a step closer |
114 | < | if (potEnergy < 0){ |
115 | < | sigDist = probeCoor; |
116 | < | tempPotEnergy = potEnergy; |
117 | < | probeCoor -= rhoStep; |
118 | < | } |
119 | < | else { |
120 | < | //do a linear interpolation to obtain the sigDist |
121 | < | interpRange = potEnergy - tempPotEnergy; |
122 | < | interpFrac = potEnergy / interpRange; |
123 | < | interpFrac = interpFrac * rhoStep; |
124 | < | sigDist = probeCoor + interpFrac; |
113 | > | //test if the probe reached the origin - if so, stop stepping closer |
114 | > | if (probeCoor < 0){ |
115 | > | sigDist = 0.0; |
116 | > | tooClose = 1; |
117 | > | } |
118 | > | |
119 | > | //test if the probe beyond the contact point - if not, take a step closer |
120 | > | if (potEnergy < 0){ |
121 | > | sigDist = probeCoor; |
122 | > | tempPotEnergy = potEnergy; |
123 | > | probeCoor -= rhoStep; |
124 | > | } |
125 | > | else { |
126 | > | //do a linear interpolation to obtain the sigDist |
127 | > | interpRange = potEnergy - tempPotEnergy; |
128 | > | interpFrac = potEnergy / interpRange; |
129 | > | interpFrac = interpFrac * rhoStep; |
130 | > | sigDist = probeCoor + interpFrac; |
131 | ||
132 | < | //end the loop |
133 | < | tooClose = 1; |
134 | < | } |
135 | < | } |
132 | > | //end the loop |
133 | > | tooClose = 1; |
134 | > | } |
135 | > | } |
136 | } | |
137 | ||
138 | void GridBuilder::calcEnergy(){ | |
139 | < | |
140 | < | } |
139 | > | double rXij, rYij, rZij; |
140 | > | double rijSquared; |
141 | > | double rValSquared, rValPowerSix; |
142 | > | double atomRpar, atomEps; |
143 | > | double rbAtomPos[3]; |
144 | > | |
145 | > | potEnergy = 0.0; |
146 | ||
147 | < | void GridBuilder::stepTheta(double increment){ |
148 | < | //zero out the euler angles |
149 | < | for (i=0; i<3; i++) |
150 | < | angles[i] = 0.0; |
151 | < | |
152 | < | //the second euler angle is for rotation about the x-axis (we use the zxz convention) |
153 | < | angles[1] = increment; |
154 | < | |
155 | < | //obtain the rotation matrix through the rigid body class |
156 | < | rbMol->doEulerToRotMat(angles, rotX); |
157 | < | |
158 | < | //rotate the rigid body |
159 | < | rbMol->getA(rbMatrix); |
160 | < | matMul3(rotX, rbMatrix, rotatedMat); |
161 | < | rbMol->setA(rotatedMat); |
162 | < | |
163 | < | } |
147 | > | for(i=0; i<rbMol->getNumAtoms(); i++){ |
148 | > | rbMol->getAtomPos(rbAtomPos, i); |
149 | > | |
150 | > | rXij = rbAtomPos[0]; |
151 | > | rYij = rbAtomPos[1]; |
152 | > | rZij = rbAtomPos[2] - probeCoor; |
153 | > | |
154 | > | rijSquared = rXij * rXij + rYij * rYij + rZij * rZij; |
155 | > | |
156 | > | //in the interest of keeping the code more compact, we are being less |
157 | > | //efficient by placing a switch statement in the calculation loop |
158 | > | switch(forcefield){ |
159 | > | case 1:{ |
160 | > | //we are using the CHARMm force field |
161 | > | atomRpar = rbMol->getAtomRpar(i); |
162 | > | atomEps = rbMol->getAtomEps(i); |
163 | > | |
164 | > | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); |
165 | > | rValPowerSix = rValSquared * rValSquared * rValSquared; |
166 | > | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); |
167 | > | }; break; |
168 | > | |
169 | > | case 2:{ |
170 | > | //we are using the AMBER force field |
171 | > | atomRpar = rbMol->getAtomRpar(i); |
172 | > | atomEps = rbMol->getAtomEps(i); |
173 | > | |
174 | > | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); |
175 | > | rValPowerSix = rValSquared * rValSquared * rValSquared; |
176 | > | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); |
177 | > | }; break; |
178 | > | |
179 | > | case 3:{ |
180 | > | //we are using Allen-Tildesley LJ parameters |
181 | > | atomRpar = rbMol->getAtomRpar(i); |
182 | > | atomEps = rbMol->getAtomEps(i); |
183 | > | |
184 | > | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (4*rijSquared); |
185 | > | rValPowerSix = rValSquared * rValSquared * rValSquared; |
186 | > | potEnergy += 4*sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 1.0)); |
187 | > | |
188 | > | }; break; |
189 | > | |
190 | > | case 4:{ |
191 | > | //we are using the OPLS force field |
192 | > | atomRpar = rbMol->getAtomRpar(i); |
193 | > | atomEps = rbMol->getAtomEps(i); |
194 | > | |
195 | > | rValSquared = (pow(sqrt(rparHe+atomRpar),2)) / (rijSquared); |
196 | > | rValPowerSix = rValSquared * rValSquared * rValSquared; |
197 | > | potEnergy += 4*sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 1.0)); |
198 | > | }; break; |
199 | > | |
200 | > | case 5:{ |
201 | > | //we are using the GAFF force field |
202 | > | atomRpar = rbMol->getAtomRpar(i); |
203 | > | atomEps = rbMol->getAtomEps(i); |
204 | > | |
205 | > | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); |
206 | > | rValPowerSix = rValSquared * rValSquared * rValSquared; |
207 | > | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); |
208 | > | }; break; |
209 | > | } |
210 | > | } |
211 | > | } |
212 | ||
213 | < | void GridBuilder::stepPhi(double increment){ |
214 | < | //zero out the euler angles |
215 | < | for (i=0; i<3; i++) |
216 | < | angles[i] = 0.0; |
217 | < | |
218 | < | //the phi euler angle is for rotation about the z-axis (we use the zxz convention) |
219 | < | angles[0] = increment; |
220 | < | |
221 | < | //obtain the rotation matrix through the rigid body class |
222 | < | rbMol->doEulerToRotMat(angles, rotZ); |
131 | < | |
132 | < | //rotate the rigid body |
133 | < | rbMol->getA(rbMatrix); |
134 | < | matMul3(rotZ, rbMatrix, rotatedMat); |
135 | < | rbMol->setA(rotatedMat); |
136 | < | |
213 | > | void GridBuilder::printGridFiles(){ |
214 | > | ofstream sigmaOut("sigma.grid"); |
215 | > | ofstream sOut("s.grid"); |
216 | > | ofstream epsOut("eps.grid"); |
217 | > | |
218 | > | for (k=0; k<sigList.size(); k++){ |
219 | > | sigmaOut << sigList[k] << "\n0\n"; |
220 | > | sOut << sList[k] << "\n0\n"; |
221 | > | epsOut << epsList[k] << "\n0\n"; |
222 | > | } |
223 | } | |
224 | + |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |