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