| 1 | #include "GridBuilder.hpp" | 
| 2 | #define PI 3.14159265359 | 
| 3 |  | 
| 4 |  | 
| 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, | 
| 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 | 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 | //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 | printf("Theta step %i\n", k); | 
| 71 | for (j=0; j < gridwidth; j++) { | 
| 72 | phiVal = j*phiStep; | 
| 73 |  | 
| 74 | rbMol->setEuler(0.0, thetaVal, phiVal); | 
| 75 |  | 
| 76 | releaseProbe(startDist); | 
| 77 |  | 
| 78 | //translate the values to sigma, s, and epsilon of the rigid body | 
| 79 | sigTemp = 2*sigDist - sigProbe; | 
| 80 | sTemp = (2*(sDist - sigDist))/(0.122462048309) - sigProbe; | 
| 81 | epsTemp = pow(epsVal, 2)/fabs(epsHe); | 
| 82 |  | 
| 83 | sigList.push_back(sigTemp); | 
| 84 | sList.push_back(sTemp); | 
| 85 | epsList.push_back(epsTemp); | 
| 86 | } | 
| 87 | } | 
| 88 | } | 
| 89 |  | 
| 90 | void GridBuilder::releaseProbe(double farPos){ | 
| 91 | int tooClose; | 
| 92 | double tempPotEnergy; | 
| 93 | double interpRange; | 
| 94 | double interpFrac; | 
| 95 |  | 
| 96 | probeCoor = farPos; | 
| 97 | potProgress.clear(); | 
| 98 | distProgress.clear(); | 
| 99 | tooClose = 0; | 
| 100 | epsVal = 0; | 
| 101 | rhoStep = 0.1; //the distance the probe atom moves between steps | 
| 102 |  | 
| 103 | while (!tooClose){ | 
| 104 | calcEnergy(); | 
| 105 | potProgress.push_back(potEnergy); | 
| 106 | distProgress.push_back(probeCoor); | 
| 107 |  | 
| 108 | //if we've reached a new minimum, save the value and position | 
| 109 | if (potEnergy < epsVal){ | 
| 110 | epsVal = potEnergy; | 
| 111 | sDist = probeCoor; | 
| 112 | } | 
| 113 |  | 
| 114 | //test if the probe reached the origin - if so, stop stepping closer | 
| 115 | if (probeCoor < 0){ | 
| 116 | sigDist = 0.0; | 
| 117 | tooClose = 1; | 
| 118 | } | 
| 119 |  | 
| 120 | //test if the probe beyond the contact point - if not, take a step closer | 
| 121 | if (potEnergy < 0){ | 
| 122 | sigDist = probeCoor; | 
| 123 | tempPotEnergy = potEnergy; | 
| 124 | probeCoor -= rhoStep; | 
| 125 | } | 
| 126 | else { | 
| 127 | //do a linear interpolation to obtain the sigDist | 
| 128 | interpRange = potEnergy - tempPotEnergy; | 
| 129 | interpFrac = potEnergy / interpRange; | 
| 130 | interpFrac = interpFrac * rhoStep; | 
| 131 | sigDist = probeCoor + interpFrac; | 
| 132 |  | 
| 133 | //end the loop | 
| 134 | tooClose = 1; | 
| 135 | } | 
| 136 | } | 
| 137 | } | 
| 138 |  | 
| 139 | void GridBuilder::calcEnergy(){ | 
| 140 | double rXij, rYij, rZij; | 
| 141 | double rijSquared; | 
| 142 | double rValSquared, rValPowerSix; | 
| 143 | double atomRpar, atomEps; | 
| 144 | double rbAtomPos[3]; | 
| 145 |  | 
| 146 | potEnergy = 0.0; | 
| 147 |  | 
| 148 | for(i=0; i<rbMol->getNumAtoms(); i++){ | 
| 149 | rbMol->getAtomPos(rbAtomPos, i); | 
| 150 |  | 
| 151 | rXij = rbAtomPos[0]; | 
| 152 | rYij = rbAtomPos[1]; | 
| 153 | rZij = rbAtomPos[2] - probeCoor; | 
| 154 |  | 
| 155 | rijSquared = rXij * rXij + rYij * rYij + rZij * rZij; | 
| 156 |  | 
| 157 | //in the interest of keeping the code more compact, we are being less | 
| 158 | //efficient by placing a switch statement in the calculation loop | 
| 159 | switch(forcefield){ | 
| 160 | case 1:{ | 
| 161 | //we are using the CHARMm force field | 
| 162 | atomRpar = rbMol->getAtomRpar(i); | 
| 163 | atomEps = rbMol->getAtomEps(i); | 
| 164 |  | 
| 165 | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); | 
| 166 | rValPowerSix = rValSquared * rValSquared * rValSquared; | 
| 167 | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); | 
| 168 | }; break; | 
| 169 |  | 
| 170 | case 2:{ | 
| 171 | //we are using the AMBER force field | 
| 172 | atomRpar = rbMol->getAtomRpar(i); | 
| 173 | atomEps = rbMol->getAtomEps(i); | 
| 174 |  | 
| 175 | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); | 
| 176 | rValPowerSix = rValSquared * rValSquared * rValSquared; | 
| 177 | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); | 
| 178 | }; break; | 
| 179 |  | 
| 180 | case 3:{ | 
| 181 | //we are using Allen-Tildesley LJ parameters | 
| 182 | atomRpar = rbMol->getAtomRpar(i); | 
| 183 | atomEps = rbMol->getAtomEps(i); | 
| 184 |  | 
| 185 | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (4*rijSquared); | 
| 186 | rValPowerSix = rValSquared * rValSquared * rValSquared; | 
| 187 | potEnergy += 4*sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 1.0)); | 
| 188 |  | 
| 189 | }; break; | 
| 190 |  | 
| 191 | case 4:{ | 
| 192 | //we are using the OPLS force field | 
| 193 | atomRpar = rbMol->getAtomRpar(i); | 
| 194 | atomEps = rbMol->getAtomEps(i); | 
| 195 |  | 
| 196 | rValSquared = (pow(sqrt(rparHe+atomRpar),2)) / (rijSquared); | 
| 197 | rValPowerSix = rValSquared * rValSquared * rValSquared; | 
| 198 | potEnergy += 4*sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 1.0)); | 
| 199 | }; break; | 
| 200 |  | 
| 201 | case 5:{ | 
| 202 | //we are using the GAFF force field | 
| 203 | atomRpar = rbMol->getAtomRpar(i); | 
| 204 | atomEps = rbMol->getAtomEps(i); | 
| 205 |  | 
| 206 | rValSquared = ((rparHe+atomRpar)*(rparHe+atomRpar)) / (rijSquared); | 
| 207 | rValPowerSix = rValSquared * rValSquared * rValSquared; | 
| 208 | potEnergy += sqrt(epsHe*atomEps)*(rValPowerSix * (rValPowerSix - 2.0)); | 
| 209 | }; break; | 
| 210 | } | 
| 211 | } | 
| 212 | } | 
| 213 |  | 
| 214 | void GridBuilder::printGridFiles(){ | 
| 215 | ofstream sigmaOut("sigma.grid"); | 
| 216 | ofstream sOut("s.grid"); | 
| 217 | ofstream epsOut("eps.grid"); | 
| 218 |  | 
| 219 | for (k=0; k<sigList.size(); k++){ | 
| 220 | sigmaOut << sigList[k] << "\n0\n"; | 
| 221 | sOut << sList[k] << "\n0\n"; | 
| 222 | epsOut << epsList[k] << "\n0\n"; | 
| 223 | } | 
| 224 | } | 
| 225 |  |