| 1 | tim | 906 | /* | 
| 2 |  |  | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 |  |  | * | 
| 4 |  |  | * The University of Notre Dame grants you ("Licensee") a | 
| 5 |  |  | * non-exclusive, royalty free, license to use, modify and | 
| 6 |  |  | * redistribute this software in source and binary code form, provided | 
| 7 |  |  | * that the following conditions are met: | 
| 8 |  |  | * | 
| 9 |  |  | * 1. Acknowledgement of the program authors must be made in any | 
| 10 |  |  | *    publication of scientific results based in part on use of the | 
| 11 |  |  | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 |  |  | *    the article in which the program was described (Matthew | 
| 13 |  |  | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 |  |  | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 |  |  | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 |  |  | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 |  |  | * | 
| 18 |  |  | * 2. Redistributions of source code must retain the above copyright | 
| 19 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 20 |  |  | * | 
| 21 |  |  | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 23 |  |  | *    documentation and/or other materials provided with the | 
| 24 |  |  | *    distribution. | 
| 25 |  |  | * | 
| 26 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 27 |  |  | * kind. All express or implied conditions, representations and | 
| 28 |  |  | * warranties, including any implied warranty of merchantability, | 
| 29 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 32 |  |  | * using, modifying or distributing the software or its | 
| 33 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 34 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 36 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 37 |  |  | * arising out of the use of or inability to use software, even if the | 
| 38 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 39 |  |  | * such damages. | 
| 40 |  |  | */ | 
| 41 |  |  |  | 
| 42 |  |  | #include "applications/hydrodynamics/ApproximationModel.hpp" | 
| 43 |  |  | #include "math/LU.hpp" | 
| 44 |  |  | #include "math/DynamicRectMatrix.hpp" | 
| 45 |  |  | #include "math/SquareMatrix3.hpp" | 
| 46 |  |  | #include "utils/OOPSEConstant.hpp" | 
| 47 | gezelter | 972 | #include "hydrodynamics/Sphere.hpp" | 
| 48 |  |  | #include "hydrodynamics/Ellipsoid.hpp" | 
| 49 | tim | 906 | #include "applications/hydrodynamics/CompositeShape.hpp" | 
| 50 |  |  | #include "math/LU.hpp" | 
| 51 | tim | 921 | #include "utils/simError.h" | 
| 52 | tim | 906 | namespace oopse { | 
| 53 |  |  | /** | 
| 54 |  |  | * Reference: | 
| 55 |  |  | * Beatriz Carrasco and Jose Gracia de la Torre, Hydrodynamic Properties of Rigid Particles: | 
| 56 |  |  | * Comparison of Different Modeling and Computational Procedures. | 
| 57 |  |  | * Biophysical Journal, 75(6), 3044, 1999 | 
| 58 |  |  | */ | 
| 59 |  |  |  | 
| 60 | gezelter | 972 | ApproximationModel::ApproximationModel(StuntDouble* sd, SimInfo* info): HydrodynamicsModel(sd, info){ | 
| 61 |  |  | } | 
| 62 |  |  |  | 
| 63 |  |  | void ApproximationModel::init() { | 
| 64 | tim | 906 | if (!createBeads(beads_)) { | 
| 65 | tim | 921 | sprintf(painCave.errMsg, "ApproximationModel::init() : Can not create beads\n"); | 
| 66 |  |  | painCave.isFatal = 1; | 
| 67 |  |  | simError(); | 
| 68 | tim | 906 | } | 
| 69 | gezelter | 972 |  | 
| 70 |  |  | } | 
| 71 |  |  |  | 
| 72 | tim | 977 | bool ApproximationModel::calcHydroProps(Shape* shape, RealType viscosity, RealType temperature) { | 
| 73 | gezelter | 972 |  | 
| 74 | tim | 906 | bool ret = true; | 
| 75 | xsun | 1177 | HydroProp* cr = new HydroProp(); | 
| 76 |  |  | HydroProp* cd = new HydroProp(); | 
| 77 | tim | 906 | calcHydroPropsAtCR(beads_, viscosity, temperature, cr); | 
| 78 | xsun | 1177 | calcHydroPropsAtCD(beads_, viscosity, temperature, cd); | 
| 79 | tim | 906 | setCR(cr); | 
| 80 |  |  | setCD(cd); | 
| 81 |  |  | return true; | 
| 82 | gezelter | 972 | } | 
| 83 |  |  |  | 
| 84 | gezelter | 981 | bool ApproximationModel::calcHydroPropsAtCR(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cr) { | 
| 85 | gezelter | 972 |  | 
| 86 | tim | 906 | int nbeads = beads.size(); | 
| 87 | tim | 977 | DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 88 |  |  | DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 89 | tim | 906 | Mat3x3d I; | 
| 90 |  |  | I(0, 0) = 1.0; | 
| 91 |  |  | I(1, 1) = 1.0; | 
| 92 |  |  | I(2, 2) = 1.0; | 
| 93 |  |  |  | 
| 94 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 95 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 96 |  |  | Mat3x3d Tij; | 
| 97 | tim | 906 | if (i != j ) { | 
| 98 | gezelter | 972 | Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 99 | tim | 977 | RealType rij = Rij.length(); | 
| 100 |  |  | RealType rij2 = rij * rij; | 
| 101 |  |  | RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; | 
| 102 | gezelter | 972 | Mat3x3d tmpMat; | 
| 103 |  |  | tmpMat = outProduct(Rij, Rij) / rij2; | 
| 104 | tim | 977 | RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 105 | tim | 978 | RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 106 |  |  | RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 107 |  |  | Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 108 | tim | 906 | }else { | 
| 109 | tim | 977 | RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 110 | gezelter | 972 | Tij(0, 0) = constant; | 
| 111 |  |  | Tij(1, 1) = constant; | 
| 112 |  |  | Tij(2, 2) = constant; | 
| 113 | tim | 906 | } | 
| 114 |  |  | B.setSubMatrix(i*3, j*3, Tij); | 
| 115 | gezelter | 972 | } | 
| 116 | tim | 906 | } | 
| 117 | gezelter | 972 |  | 
| 118 | tim | 906 | //invert B Matrix | 
| 119 |  |  | invertMatrix(B, C); | 
| 120 | tim | 910 |  | 
| 121 | tim | 906 | //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) | 
| 122 |  |  | std::vector<Mat3x3d> U; | 
| 123 |  |  | for (int i = 0; i < nbeads; ++i) { | 
| 124 | gezelter | 972 | Mat3x3d currU; | 
| 125 |  |  | currU.setupSkewMat(beads[i].pos); | 
| 126 |  |  | U.push_back(currU); | 
| 127 | tim | 906 | } | 
| 128 |  |  |  | 
| 129 |  |  | //calculate Xi matrix at arbitrary origin O | 
| 130 |  |  | Mat3x3d Xiott; | 
| 131 |  |  | Mat3x3d Xiorr; | 
| 132 |  |  | Mat3x3d Xiotr; | 
| 133 | gezelter | 972 |  | 
| 134 | tim | 906 | //calculate the total volume | 
| 135 | gezelter | 972 |  | 
| 136 | tim | 977 | RealType volume = 0.0; | 
| 137 | tim | 906 | for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { | 
| 138 | gezelter | 972 | volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 139 | tim | 906 | } | 
| 140 | gezelter | 972 |  | 
| 141 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 142 |  |  | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 143 |  |  | Mat3x3d Cij; | 
| 144 |  |  | C.getSubMatrix(i*3, j*3, Cij); | 
| 145 | tim | 906 |  | 
| 146 | gezelter | 972 | Xiott += Cij; | 
| 147 |  |  | Xiotr += U[i] * Cij; | 
| 148 | xsun | 1208 | // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 149 | gezelter | 972 | Xiorr += -U[i] * Cij * U[j]; | 
| 150 |  |  | } | 
| 151 | tim | 906 | } | 
| 152 | xsun | 1208 |  | 
| 153 |  |  | // add the volume correction | 
| 154 |  |  | Xiorr += (6.0 * viscosity * volume) * I; | 
| 155 | gezelter | 972 |  | 
| 156 | xsun | 1208 | const RealType convertConstant = 1.439326479e4; //converts Poise angstroms | 
| 157 |  |  | // to kcal fs mol^-1 Angstrom^-1 | 
| 158 |  |  |  | 
| 159 | tim | 906 | Xiott *= convertConstant; | 
| 160 |  |  | Xiotr *= convertConstant; | 
| 161 |  |  | Xiorr *= convertConstant; | 
| 162 |  |  |  | 
| 163 |  |  | Mat3x3d tmp; | 
| 164 |  |  | Mat3x3d tmpInv; | 
| 165 |  |  | Vector3d tmpVec; | 
| 166 |  |  | tmp(0, 0) = Xiott(1, 1) + Xiott(2, 2); | 
| 167 |  |  | tmp(0, 1) = - Xiott(0, 1); | 
| 168 |  |  | tmp(0, 2) = -Xiott(0, 2); | 
| 169 |  |  | tmp(1, 0) = -Xiott(0, 1); | 
| 170 |  |  | tmp(1, 1) = Xiott(0, 0)  + Xiott(2, 2); | 
| 171 |  |  | tmp(1, 2) = -Xiott(1, 2); | 
| 172 |  |  | tmp(2, 0) = -Xiott(0, 2); | 
| 173 |  |  | tmp(2, 1) = -Xiott(1, 2); | 
| 174 |  |  | tmp(2, 2) = Xiott(1, 1) + Xiott(0, 0); | 
| 175 |  |  | tmpVec[0] = Xiotr(2, 1) - Xiotr(1, 2); | 
| 176 |  |  | tmpVec[1] = Xiotr(0, 2) - Xiotr(2, 0); | 
| 177 |  |  | tmpVec[2] = Xiotr(1, 0) - Xiotr(0, 1); | 
| 178 |  |  | tmpInv = tmp.inverse(); | 
| 179 |  |  | Vector3d ror = tmpInv * tmpVec; //center of resistance | 
| 180 |  |  | Mat3x3d Uor; | 
| 181 |  |  | Uor.setupSkewMat(ror); | 
| 182 |  |  |  | 
| 183 |  |  | Mat3x3d Xirtt; | 
| 184 |  |  | Mat3x3d Xirrr; | 
| 185 |  |  | Mat3x3d Xirtr; | 
| 186 |  |  |  | 
| 187 |  |  | Xirtt = Xiott; | 
| 188 |  |  | Xirtr = (Xiotr - Uor * Xiott); | 
| 189 |  |  | Xirrr = Xiorr - Uor * Xiott * Uor + Xiotr * Uor - Uor * Xiotr.transpose(); | 
| 190 |  |  |  | 
| 191 |  |  |  | 
| 192 | tim | 977 | SquareMatrix<RealType,6> Xir6x6; | 
| 193 |  |  | SquareMatrix<RealType,6> Dr6x6; | 
| 194 | tim | 906 |  | 
| 195 |  |  | Xir6x6.setSubMatrix(0, 0, Xirtt); | 
| 196 |  |  | Xir6x6.setSubMatrix(0, 3, Xirtr.transpose()); | 
| 197 |  |  | Xir6x6.setSubMatrix(3, 0, Xirtr); | 
| 198 |  |  | Xir6x6.setSubMatrix(3, 3, Xirrr); | 
| 199 |  |  |  | 
| 200 |  |  | invertMatrix(Xir6x6, Dr6x6); | 
| 201 |  |  | Mat3x3d Drtt; | 
| 202 |  |  | Mat3x3d Drtr; | 
| 203 |  |  | Mat3x3d Drrt; | 
| 204 |  |  | Mat3x3d Drrr; | 
| 205 |  |  | Dr6x6.getSubMatrix(0, 0, Drtt); | 
| 206 |  |  | Dr6x6.getSubMatrix(0, 3, Drrt); | 
| 207 |  |  | Dr6x6.getSubMatrix(3, 0, Drtr); | 
| 208 |  |  | Dr6x6.getSubMatrix(3, 3, Drrr); | 
| 209 | xsun | 1208 | RealType kt = OOPSEConstant::kb * temperature ; // in kcal mol^-1 | 
| 210 | tim | 906 | Drtt *= kt; | 
| 211 |  |  | Drrt *= kt; | 
| 212 |  |  | Drtr *= kt; | 
| 213 |  |  | Drrr *= kt; | 
| 214 | xsun | 1208 | //Xirtt *= OOPSEConstant::kb * temperature; | 
| 215 |  |  | //Xirtr *= OOPSEConstant::kb * temperature; | 
| 216 |  |  | //Xirrr *= OOPSEConstant::kb * temperature; | 
| 217 | tim | 906 |  | 
| 218 | gezelter | 981 | Mat6x6d Xi, D; | 
| 219 | tim | 906 |  | 
| 220 | gezelter | 981 | cr->setCOR(ror); | 
| 221 |  |  |  | 
| 222 |  |  | Xi.setSubMatrix(0, 0, Xirtt); | 
| 223 |  |  | Xi.setSubMatrix(0, 3, Xirtr); | 
| 224 |  |  | Xi.setSubMatrix(3, 0, Xirtr); | 
| 225 |  |  | Xi.setSubMatrix(3, 3, Xirrr); | 
| 226 |  |  |  | 
| 227 |  |  | cr->setXi(Xi); | 
| 228 |  |  |  | 
| 229 |  |  | D.setSubMatrix(0, 0, Drtt); | 
| 230 |  |  | D.setSubMatrix(0, 3, Drrt); | 
| 231 |  |  | D.setSubMatrix(3, 0, Drtr); | 
| 232 |  |  | D.setSubMatrix(3, 3, Drrr); | 
| 233 |  |  |  | 
| 234 |  |  | cr->setD(D); | 
| 235 | tim | 906 |  | 
| 236 |  |  | std::cout << "-----------------------------------------\n"; | 
| 237 |  |  | std::cout << "center of resistance :" << std::endl; | 
| 238 |  |  | std::cout << ror << std::endl; | 
| 239 |  |  | std::cout << "resistant tensor at center of resistance" << std::endl; | 
| 240 |  |  | std::cout << "translation:" << std::endl; | 
| 241 |  |  | std::cout << Xirtt << std::endl; | 
| 242 |  |  | std::cout << "translation-rotation:" << std::endl; | 
| 243 |  |  | std::cout << Xirtr << std::endl; | 
| 244 |  |  | std::cout << "rotation:" << std::endl; | 
| 245 |  |  | std::cout << Xirrr << std::endl; | 
| 246 |  |  | std::cout << "diffusion tensor at center of resistance" << std::endl; | 
| 247 |  |  | std::cout << "translation:" << std::endl; | 
| 248 |  |  | std::cout << Drtt << std::endl; | 
| 249 |  |  | std::cout << "rotation-translation:" << std::endl; | 
| 250 |  |  | std::cout << Drrt << std::endl; | 
| 251 |  |  | std::cout << "translation-rotation:" << std::endl; | 
| 252 |  |  | std::cout << Drtr << std::endl; | 
| 253 |  |  | std::cout << "rotation:" << std::endl; | 
| 254 |  |  | std::cout << Drrr << std::endl; | 
| 255 |  |  | std::cout << "-----------------------------------------\n"; | 
| 256 |  |  |  | 
| 257 |  |  | return true; | 
| 258 |  |  | } | 
| 259 | gezelter | 972 |  | 
| 260 | xsun | 1177 | bool ApproximationModel::calcHydroPropsAtCD(std::vector<BeadParam>& beads, RealType viscosity, RealType temperature, HydroProp* cd) { | 
| 261 | gezelter | 972 |  | 
| 262 | tim | 906 | int nbeads = beads.size(); | 
| 263 | tim | 977 | DynamicRectMatrix<RealType> B(3*nbeads, 3*nbeads); | 
| 264 |  |  | DynamicRectMatrix<RealType> C(3*nbeads, 3*nbeads); | 
| 265 | tim | 906 | Mat3x3d I; | 
| 266 |  |  | I(0, 0) = 1.0; | 
| 267 |  |  | I(1, 1) = 1.0; | 
| 268 |  |  | I(2, 2) = 1.0; | 
| 269 |  |  |  | 
| 270 |  |  | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 271 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 272 |  |  | Mat3x3d Tij; | 
| 273 |  |  | if (i != j ) { | 
| 274 |  |  | Vector3d Rij = beads[i].pos - beads[j].pos; | 
| 275 | tim | 977 | RealType rij = Rij.length(); | 
| 276 |  |  | RealType rij2 = rij * rij; | 
| 277 |  |  | RealType sumSigma2OverRij2 = ((beads[i].radius*beads[i].radius) + (beads[j].radius*beads[j].radius)) / rij2; | 
| 278 | gezelter | 972 | Mat3x3d tmpMat; | 
| 279 |  |  | tmpMat = outProduct(Rij, Rij) / rij2; | 
| 280 | tim | 977 | RealType constant = 8.0 * NumericConstant::PI * viscosity * rij; | 
| 281 | tim | 978 | RealType tmp1 = 1.0 + sumSigma2OverRij2/3.0; | 
| 282 |  |  | RealType tmp2 = 1.0 - sumSigma2OverRij2; | 
| 283 |  |  | Tij = (tmp1 * I + tmp2 * tmpMat ) / constant; | 
| 284 | gezelter | 972 | }else { | 
| 285 | tim | 977 | RealType constant = 1.0 / (6.0 * NumericConstant::PI * viscosity * beads[i].radius); | 
| 286 | gezelter | 972 | Tij(0, 0) = constant; | 
| 287 |  |  | Tij(1, 1) = constant; | 
| 288 |  |  | Tij(2, 2) = constant; | 
| 289 | tim | 906 | } | 
| 290 | gezelter | 972 | B.setSubMatrix(i*3, j*3, Tij); | 
| 291 |  |  | } | 
| 292 | tim | 906 | } | 
| 293 | gezelter | 972 |  | 
| 294 | tim | 906 | //invert B Matrix | 
| 295 |  |  | invertMatrix(B, C); | 
| 296 | gezelter | 972 |  | 
| 297 | tim | 906 | //prepare U Matrix relative to arbitrary origin O(0.0, 0.0, 0.0) | 
| 298 |  |  | std::vector<Mat3x3d> U; | 
| 299 |  |  | for (int i = 0; i < nbeads; ++i) { | 
| 300 | gezelter | 972 | Mat3x3d currU; | 
| 301 |  |  | currU.setupSkewMat(beads[i].pos); | 
| 302 |  |  | U.push_back(currU); | 
| 303 | tim | 906 | } | 
| 304 |  |  |  | 
| 305 |  |  | //calculate Xi matrix at arbitrary origin O | 
| 306 |  |  | Mat3x3d Xitt; | 
| 307 |  |  | Mat3x3d Xirr; | 
| 308 |  |  | Mat3x3d Xitr; | 
| 309 |  |  |  | 
| 310 |  |  | //calculate the total volume | 
| 311 |  |  |  | 
| 312 | tim | 977 | RealType volume = 0.0; | 
| 313 | tim | 906 | for (std::vector<BeadParam>::iterator iter = beads.begin(); iter != beads.end(); ++iter) { | 
| 314 | gezelter | 972 | volume += 4.0/3.0 * NumericConstant::PI * pow((*iter).radius,3); | 
| 315 | tim | 906 | } | 
| 316 | gezelter | 972 |  | 
| 317 | tim | 906 | for (std::size_t i = 0; i < nbeads; ++i) { | 
| 318 | gezelter | 972 | for (std::size_t j = 0; j < nbeads; ++j) { | 
| 319 |  |  | Mat3x3d Cij; | 
| 320 |  |  | C.getSubMatrix(i*3, j*3, Cij); | 
| 321 | tim | 906 |  | 
| 322 | gezelter | 972 | Xitt += Cij; | 
| 323 |  |  | Xitr += U[i] * Cij; | 
| 324 | xsun | 1208 | // uncorrected here.  Volume correction is added after we assemble Xiorr | 
| 325 | gezelter | 972 | Xirr += -U[i] * Cij * U[j]; | 
| 326 |  |  | } | 
| 327 | tim | 906 | } | 
| 328 | xsun | 1208 | // add the volume correction here: | 
| 329 |  |  | Xirr += (6.0 * viscosity * volume) * I; | 
| 330 | gezelter | 972 |  | 
| 331 | xsun | 1208 | const RealType convertConstant = 1.439326479e4; //converts Poise angstroms | 
| 332 |  |  | // to kcal fs mol^-1 Angstrom^-1 | 
| 333 | tim | 906 | Xitt *= convertConstant; | 
| 334 |  |  | Xitr *= convertConstant; | 
| 335 |  |  | Xirr *= convertConstant; | 
| 336 | gezelter | 972 |  | 
| 337 | xsun | 1208 | RealType kt = OOPSEConstant::kb * temperature; // in kcal mol^-1 | 
| 338 | gezelter | 972 |  | 
| 339 | tim | 906 | Mat3x3d Dott; //translational diffusion tensor at arbitrary origin O | 
| 340 |  |  | Mat3x3d Dorr; //rotational diffusion tensor at arbitrary origin O | 
| 341 |  |  | Mat3x3d Dotr; //translation-rotation couplingl diffusion tensor at arbitrary origin O | 
| 342 | gezelter | 972 |  | 
| 343 | tim | 906 | const static Mat3x3d zeroMat(0.0); | 
| 344 |  |  |  | 
| 345 |  |  | Mat3x3d XittInv(0.0); | 
| 346 |  |  | XittInv = Xitt.inverse(); | 
| 347 |  |  |  | 
| 348 |  |  | Mat3x3d XirrInv; | 
| 349 |  |  | XirrInv = Xirr.inverse(); | 
| 350 |  |  |  | 
| 351 |  |  | Mat3x3d tmp; | 
| 352 |  |  | Mat3x3d tmpInv; | 
| 353 |  |  | tmp = Xitt - Xitr.transpose() * XirrInv * Xitr; | 
| 354 |  |  | tmpInv = tmp.inverse(); | 
| 355 |  |  |  | 
| 356 |  |  | Dott = tmpInv; | 
| 357 |  |  | Dotr = -XirrInv * Xitr * tmpInv; | 
| 358 |  |  |  | 
| 359 |  |  | tmp = Xirr - Xitr * XittInv * Xitr.transpose(); | 
| 360 |  |  | tmpInv = tmp.inverse(); | 
| 361 |  |  |  | 
| 362 |  |  | Dorr = tmpInv; | 
| 363 |  |  |  | 
| 364 |  |  | //calculate center of diffusion | 
| 365 |  |  | tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2); | 
| 366 |  |  | tmp(0, 1) = - Dorr(0, 1); | 
| 367 |  |  | tmp(0, 2) = -Dorr(0, 2); | 
| 368 |  |  | tmp(1, 0) = -Dorr(0, 1); | 
| 369 |  |  | tmp(1, 1) = Dorr(0, 0)  + Dorr(2, 2); | 
| 370 |  |  | tmp(1, 2) = -Dorr(1, 2); | 
| 371 |  |  | tmp(2, 0) = -Dorr(0, 2); | 
| 372 |  |  | tmp(2, 1) = -Dorr(1, 2); | 
| 373 |  |  | tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0); | 
| 374 |  |  |  | 
| 375 |  |  | Vector3d tmpVec; | 
| 376 |  |  | tmpVec[0] = Dotr(1, 2) - Dotr(2, 1); | 
| 377 |  |  | tmpVec[1] = Dotr(2, 0) - Dotr(0, 2); | 
| 378 |  |  | tmpVec[2] = Dotr(0, 1) - Dotr(1, 0); | 
| 379 |  |  |  | 
| 380 |  |  | tmpInv = tmp.inverse(); | 
| 381 |  |  |  | 
| 382 |  |  | Vector3d rod = tmpInv * tmpVec; | 
| 383 |  |  |  | 
| 384 |  |  | //calculate Diffusion Tensor at center of diffusion | 
| 385 |  |  | Mat3x3d Uod; | 
| 386 |  |  | Uod.setupSkewMat(rod); | 
| 387 |  |  |  | 
| 388 |  |  | Mat3x3d Ddtt; //translational diffusion tensor at diffusion center | 
| 389 |  |  | Mat3x3d Ddtr; //rotational diffusion tensor at diffusion center | 
| 390 |  |  | Mat3x3d Ddrr; //translation-rotation couplingl diffusion tensor at diffusion tensor | 
| 391 |  |  |  | 
| 392 |  |  | Ddtt = Dott - Uod * Dorr * Uod + Dotr.transpose() * Uod - Uod * Dotr; | 
| 393 |  |  | Ddrr = Dorr; | 
| 394 |  |  | Ddtr = Dotr + Dorr * Uod; | 
| 395 |  |  |  | 
| 396 | tim | 977 | SquareMatrix<RealType, 6> Dd; | 
| 397 | tim | 906 | Dd.setSubMatrix(0, 0, Ddtt); | 
| 398 |  |  | Dd.setSubMatrix(0, 3, Ddtr.transpose()); | 
| 399 |  |  | Dd.setSubMatrix(3, 0, Ddtr); | 
| 400 |  |  | Dd.setSubMatrix(3, 3, Ddrr); | 
| 401 | tim | 977 | SquareMatrix<RealType, 6> Xid; | 
| 402 | tim | 906 | Ddtt *= kt; | 
| 403 |  |  | Ddtr *=kt; | 
| 404 |  |  | Ddrr *= kt; | 
| 405 |  |  | invertMatrix(Dd, Xid); | 
| 406 |  |  |  | 
| 407 |  |  |  | 
| 408 |  |  |  | 
| 409 |  |  | //Xidtt in units of kcal*fs*mol^-1*Ang^-2 | 
| 410 |  |  | //Xid /= OOPSEConstant::energyConvert; | 
| 411 |  |  | Xid *= OOPSEConstant::kb * temperature; | 
| 412 |  |  |  | 
| 413 | gezelter | 981 | Mat6x6d Xi, D; | 
| 414 | tim | 906 |  | 
| 415 | xsun | 1177 | cd->setCOR(rod); | 
| 416 | gezelter | 981 |  | 
| 417 | xsun | 1177 | cd->setXi(Xid); | 
| 418 | gezelter | 981 |  | 
| 419 |  |  | D.setSubMatrix(0, 0, Ddtt); | 
| 420 |  |  | D.setSubMatrix(0, 3, Ddtr); | 
| 421 |  |  | D.setSubMatrix(3, 0, Ddtr); | 
| 422 |  |  | D.setSubMatrix(3, 3, Ddrr); | 
| 423 |  |  |  | 
| 424 | xsun | 1177 | cd->setD(D); | 
| 425 | gezelter | 981 |  | 
| 426 | tim | 906 | std::cout << "viscosity = " << viscosity << std::endl; | 
| 427 |  |  | std::cout << "temperature = " << temperature << std::endl; | 
| 428 |  |  | std::cout << "center of diffusion :" << std::endl; | 
| 429 |  |  | std::cout << rod << std::endl; | 
| 430 |  |  | std::cout << "diffusion tensor at center of diffusion " << std::endl; | 
| 431 | xsun | 1208 | std::cout << "translation(A^2 / fs) :" << std::endl; | 
| 432 | tim | 906 | std::cout << Ddtt << std::endl; | 
| 433 | xsun | 1208 | std::cout << "translation-rotation(A / fs):" << std::endl; | 
| 434 | tim | 906 | std::cout << Ddtr << std::endl; | 
| 435 | xsun | 1208 | std::cout << "rotation(fs^-1):" << std::endl; | 
| 436 | tim | 906 | std::cout << Ddrr << std::endl; | 
| 437 |  |  |  | 
| 438 |  |  | std::cout << "resistance tensor at center of diffusion " << std::endl; | 
| 439 |  |  | std::cout << "translation(kcal*fs*mol^-1*Ang^-2) :" << std::endl; | 
| 440 |  |  |  | 
| 441 |  |  | Mat3x3d Xidtt; | 
| 442 |  |  | Mat3x3d Xidrt; | 
| 443 |  |  | Mat3x3d Xidtr; | 
| 444 |  |  | Mat3x3d Xidrr; | 
| 445 |  |  | Xid.getSubMatrix(0, 0, Xidtt); | 
| 446 |  |  | Xid.getSubMatrix(0, 3, Xidrt); | 
| 447 |  |  | Xid.getSubMatrix(3, 0, Xidtr); | 
| 448 |  |  | Xid.getSubMatrix(3, 3, Xidrr); | 
| 449 |  |  |  | 
| 450 |  |  | std::cout << Xidtt << std::endl; | 
| 451 | xsun | 1208 | std::cout << "rotation-translation (kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 452 | tim | 906 | std::cout << Xidrt << std::endl; | 
| 453 | xsun | 1208 | std::cout << "translation-rotation(kcal*fs*mol^-1*Ang^-1):" << std::endl; | 
| 454 | tim | 906 | std::cout << Xidtr << std::endl; | 
| 455 | xsun | 1208 | std::cout << "rotation(kcal*fs*mol^-1):" << std::endl; | 
| 456 | tim | 906 | std::cout << Xidrr << std::endl; | 
| 457 |  |  |  | 
| 458 |  |  | return true; | 
| 459 | gezelter | 972 |  | 
| 460 |  |  | } | 
| 461 | tim | 906 |  | 
| 462 | gezelter | 972 | void ApproximationModel::writeBeads(std::ostream& os) { | 
| 463 | tim | 906 | std::vector<BeadParam>::iterator iter; | 
| 464 |  |  | os << beads_.size() << std::endl; | 
| 465 |  |  | os << "Generated by Hydro" << std::endl; | 
| 466 |  |  | for (iter = beads_.begin(); iter != beads_.end(); ++iter) { | 
| 467 | gezelter | 972 | os << iter->atomName << "\t" << iter->pos[0] << "\t" << iter->pos[1] << "\t" << iter->pos[2] << std::endl; | 
| 468 | tim | 906 | } | 
| 469 | gezelter | 972 |  | 
| 470 |  |  | } | 
| 471 | tim | 906 | } |