Changes in src/molecule_geometry.cpp [9291d04:833b15]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_geometry.cpp
r9291d04 r833b15 58 58 /************************************* Functions for class molecule *********************************/ 59 59 60 /** Returns vector pointing to center of the domain. 61 * \return pointer to center of the domain 62 */ 63 #ifdef HAVE_INLINE 64 inline 65 #else 66 static 67 #endif 68 const Vector DetermineCenterOfBox() 69 { 70 Vector a(0.5,0.5,0.5); 71 const RealSpaceMatrix &M = World::getInstance().getDomain().getM(); 72 a *= M; 73 return a; 74 } 60 75 61 76 /** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths. … … 65 80 { 66 81 bool status = true; 67 const Vector *Center = DetermineCenterOfAll();68 const Vector *CenterBox = DetermineCenterOfBox();82 const Vector Center = DetermineCenterOfAll(); 83 const Vector CenterBox = DetermineCenterOfBox(); 69 84 Box &domain = World::getInstance().getDomain(); 70 85 71 86 // go through all atoms 72 for (iterator iter = begin(); iter != end(); ++iter) { 73 if (DoLog(4) && (*Center != *CenterBox)) 74 LOG(4, "INFO: atom before is at " << **iter); 75 **iter -= *Center; 76 **iter += *CenterBox; 77 if (DoLog(4) && (*Center != *CenterBox)) 78 LOG(4, "INFO: atom after is at " << **iter); 79 } 87 Translate(CenterBox - Center); 80 88 getAtomSet().transformNodes(boost::bind(&Box::enforceBoundaryConditions,domain,_1)); 81 89 82 delete(Center);83 delete(CenterBox);84 90 return status; 85 } ;91 } 86 92 87 93 … … 98 104 99 105 return status; 100 } ;106 } 101 107 102 108 /** Centers the edge of the atoms at (0,0,0). 103 * \param *out output stream for debugging 104 * \param *max coordinates of other edge, specifying box dimensions. 105 */ 106 void molecule::CenterEdge(Vector *max) 107 { 108 // Info info(__func__); 109 Vector *min = new Vector; 110 111 const_iterator iter = begin(); // start at first in list 112 if (iter != end()) { //list not empty? 113 for (int i=NDIM;i--;) { 114 max->at(i) = (*iter)->at(i); 115 min->at(i) = (*iter)->at(i); 116 } 117 for (; iter != end(); ++iter) {// continue with second if present 118 //(*iter)->Output(1,1,out); 119 for (int i=NDIM;i--;) { 120 max->at(i) = (max->at(i) < (*iter)->at(i)) ? (*iter)->at(i) : max->at(i); 121 min->at(i) = (min->at(i) > (*iter)->at(i)) ? (*iter)->at(i) : min->at(i); 122 } 123 } 124 LOG(1, "INFO: Maximum is " << *max << ", Minimum is " << *min << "."); 125 min->Scale(-1.); 126 (*max) += (*min); 127 Translate(min); 128 } 129 delete(min); 130 }; 109 */ 110 void molecule::CenterEdge() 111 { 112 const_iterator iter = begin(); 113 if (iter != end()) { //list not empty? 114 Vector min = (*begin())->getPosition(); 115 for (;iter != end(); ++iter) { // continue with second if present 116 const Vector ¤tPos = (*iter)->getPosition(); 117 for (size_t i=0;i<NDIM;++i) 118 if (min[i] > currentPos[i]) 119 min[i] = currentPos[i]; 120 } 121 Translate(-1.*min); 122 } 123 } 131 124 132 125 /** Centers the center of the atoms at (0,0,0). … … 147 140 } 148 141 Center.Scale(-1./(double)Num); // divide through total number (and sign for direction) 149 Translate( &Center);150 } 151 } ;142 Translate(Center); 143 } 144 } 152 145 153 146 /** Returns vector pointing to center of all atoms. 154 147 * \return pointer to center of all vector 155 148 */ 156 Vector *molecule::DetermineCenterOfAll() const149 const Vector molecule::DetermineCenterOfAll() const 157 150 { 158 151 const_iterator iter = begin(); // start at first in list 159 Vector *a = new Vector();152 Vector a; 160 153 double Num = 0; 161 154 162 a ->Zero();155 a.Zero(); 163 156 164 157 if (iter != end()) { //list not empty? 165 158 for (; iter != end(); ++iter) { // continue with second if present 166 159 Num++; 167 (*a)+= (*iter)->getPosition();168 } 169 a ->Scale(1./(double)Num); // divide through total mass (and sign for direction)160 a += (*iter)->getPosition(); 161 } 162 a.Scale(1./(double)Num); // divide through total mass (and sign for direction) 170 163 } 171 164 return a; 172 }; 173 174 /** Returns vector pointing to center of the domain. 175 * \return pointer to center of the domain 176 */ 177 Vector * molecule::DetermineCenterOfBox() const 178 { 179 Vector *a = new Vector(0.5,0.5,0.5); 180 const RealSpaceMatrix &M = World::getInstance().getDomain().getM(); 181 (*a) *= M; 182 return a; 183 }; 165 } 166 184 167 185 168 /** Returns vector pointing to center of gravity. … … 187 170 * \return pointer to center of gravity vector 188 171 */ 189 Vector *molecule::DetermineCenterOfGravity() const172 const Vector molecule::DetermineCenterOfGravity() const 190 173 { 191 174 const_iterator iter = begin(); // start at first in list 192 Vector *a = new Vector();175 Vector a; 193 176 Vector tmp; 194 177 double Num = 0; 195 178 196 a ->Zero();179 a.Zero(); 197 180 198 181 if (iter != end()) { //list not empty? … … 200 183 Num += (*iter)->getType()->getMass(); 201 184 tmp = (*iter)->getType()->getMass() * (*iter)->getPosition(); 202 (*a)+= tmp;203 } 204 a ->Scale(1./Num); // divide through total mass205 } 206 LOG(1, "INFO: Resulting center of gravity: " << *a << ".");185 a += tmp; 186 } 187 a.Scale(1./Num); // divide through total mass 188 } 189 LOG(1, "INFO: Resulting center of gravity: " << a << "."); 207 190 return a; 208 } ;191 } 209 192 210 193 /** Centers the center of gravity of the atoms at (0,0,0). … … 216 199 Vector NewCenter; 217 200 DeterminePeriodicCenter(NewCenter); 218 // go through all atoms 219 for (iterator iter = begin(); iter != end(); ++iter) { 220 **iter -= NewCenter; 221 } 222 }; 201 Translate(-1.*NewCenter); 202 } 223 203 224 204 … … 227 207 * \param *center return vector for translation vector 228 208 */ 229 void molecule::CenterAtVector(Vector *newcenter) 230 { 231 // go through all atoms 232 for (iterator iter = begin(); iter != end(); ++iter) { 233 **iter -= *newcenter; 234 } 235 }; 209 void molecule::CenterAtVector(const Vector &newcenter) 210 { 211 Translate(-1.*newcenter); 212 } 236 213 237 214 /** Calculate the inertia tensor of a the molecule. … … 242 219 { 243 220 RealSpaceMatrix InertiaTensor; 244 Vector *CenterOfGravity = DetermineCenterOfGravity();221 const Vector CenterOfGravity = DetermineCenterOfGravity(); 245 222 246 223 // reset inertia tensor … … 250 227 for (const_iterator iter = begin(); iter != end(); ++iter) { 251 228 Vector x = (*iter)->getPosition(); 252 x -= *CenterOfGravity;229 x -= CenterOfGravity; 253 230 const double mass = (*iter)->getType()->getMass(); 254 231 InertiaTensor.at(0,0) += mass*(x[1]*x[1] + x[2]*x[2]); … … 265 242 LOG(1, "INFO: The inertia tensor of molecule " << getName() << " is:" << InertiaTensor); 266 243 267 delete CenterOfGravity;268 244 return InertiaTensor; 269 245 } … … 276 252 void molecule::RotateToPrincipalAxisSystem(const Vector &Axis) 277 253 { 278 Vector *CenterOfGravity = DetermineCenterOfGravity();254 const Vector CenterOfGravity = DetermineCenterOfGravity(); 279 255 RealSpaceMatrix InertiaTensor = getInertiaTensor(); 280 256 … … 288 264 289 265 // obtain first column, eigenvector to biggest eigenvalue 290 Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent()));266 const Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent())); 291 267 Vector DesiredAxis(Axis.getNormalized()); 292 268 … … 302 278 // and rotate 303 279 for (iterator iter = begin(); iter != end(); ++iter) { 304 *(*iter) -= *CenterOfGravity;280 *(*iter) -= CenterOfGravity; 305 281 (*iter)->setPosition(RotationAxis.rotateVector((*iter)->getPosition(), alpha)); 306 *(*iter) += *CenterOfGravity;282 *(*iter) += CenterOfGravity; 307 283 } 308 284 LOG(0, "STATUS: done."); 309 310 delete CenterOfGravity;311 285 } 312 286 … … 319 293 * x=(**factor) * x (as suggested by comment) 320 294 */ 321 void molecule::Scale(const double * * constfactor)295 void molecule::Scale(const double *factor) 322 296 { 323 297 for (iterator iter = begin(); iter != end(); ++iter) { 324 298 for (size_t j=0;j<(*iter)->getTrajectorySize();j++) { 325 299 Vector temp = (*iter)->getPositionAtStep(j); 326 temp.ScaleAll( *factor);300 temp.ScaleAll(factor); 327 301 (*iter)->setPositionAtStep(j,temp); 328 302 } … … 333 307 * \param trans[] translation vector. 334 308 */ 335 void molecule::Translate(const Vector *trans) 336 { 337 for (iterator iter = begin(); iter != end(); ++iter) { 338 for (size_t j=0;j<(*iter)->getTrajectorySize();j++) { 339 (*iter)->setPositionAtStep(j, (*iter)->getPositionAtStep(j) + (*trans)); 340 } 341 } 309 void molecule::Translate(const Vector &trans) 310 { 311 getAtomSet().translate(trans); 342 312 }; 343 313 … … 346 316 * TODO treatment of trajectories missing 347 317 */ 348 void molecule::TranslatePeriodically(const Vector *trans) 349 { 318 void molecule::TranslatePeriodically(const Vector &trans) 319 { 320 Translate(trans); 350 321 Box &domain = World::getInstance().getDomain(); 351 352 // go through all atoms353 for (iterator iter = begin(); iter != end(); ++iter) {354 **iter += *trans;355 }356 322 getAtomSet().transformNodes(boost::bind(&Box::enforceBoundaryConditions,domain,_1)); 357 358 323 }; 359 324 … … 362 327 * \param n[] normal vector of mirror plane. 363 328 */ 364 void molecule::Mirror(const Vector *n) 365 { 366 OBSERVE; 367 Plane p(*n,0); 329 void molecule::Mirror(const Vector &n) 330 { 331 Plane p(n,0); 368 332 getAtomSet().transformNodes(boost::bind(&Plane::mirrorVector,p,_1)); 369 333 }; … … 381 345 Vector Testvector, Translationvector; 382 346 Vector Center; 383 BondGraph *BG = World::getInstance().getBondGraph();347 const BondGraph * const BG = World::getInstance().getBondGraph(); 384 348 385 349 do { … … 432 396 433 397 Center.Scale(1./static_cast<double>(getAtomCount())); 434 CenterAtVector( &Center);398 CenterAtVector(Center); 435 399 }; 436 400 … … 438 402 * \param n[] alignment vector. 439 403 */ 440 void molecule::Align( Vector *n)404 void molecule::Align(const Vector &n) 441 405 { 442 406 double alpha, tmp; 443 407 Vector z_axis; 408 Vector alignment(n); 444 409 z_axis[0] = 0.; 445 410 z_axis[1] = 0.; … … 448 413 // rotate on z-x plane 449 414 LOG(0, "Begin of Aligning all atoms."); 450 alpha = atan(- n->at(0)/n->at(2));415 alpha = atan(-alignment.at(0)/alignment.at(2)); 451 416 LOG(1, "INFO: Z-X-angle: " << alpha << " ... "); 452 417 for (iterator iter = begin(); iter != end(); ++iter) { … … 462 427 } 463 428 // rotate n vector 464 tmp = n->at(0);465 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2);466 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2);467 LOG(1, "alignment vector after first rotation: " << n);429 tmp = alignment.at(0); 430 alignment.at(0) = cos(alpha) * tmp + sin(alpha) * alignment.at(2); 431 alignment.at(2) = -sin(alpha) * tmp + cos(alpha) * alignment.at(2); 432 LOG(1, "alignment vector after first rotation: " << alignment); 468 433 469 434 // rotate on z-y plane 470 alpha = atan(- n->at(1)/n->at(2));435 alpha = atan(-alignment.at(1)/alignment.at(2)); 471 436 LOG(1, "INFO: Z-Y-angle: " << alpha << " ... "); 472 437 for (iterator iter = begin(); iter != end(); ++iter) { … … 482 447 } 483 448 // rotate n vector (for consistency check) 484 tmp = n->at(1); 485 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2); 486 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 487 488 489 LOG(1, "alignment vector after second rotation: " << n); 449 tmp = alignment.at(1); 450 alignment.at(1) = cos(alpha) * tmp + sin(alpha) * alignment.at(2); 451 alignment.at(2) = -sin(alpha) * tmp + cos(alpha) * alignment.at(2); 452 453 LOG(1, "alignment vector after second rotation: " << alignment); 490 454 LOG(0, "End of Aligning all atoms."); 491 455 };
Note:
See TracChangeset
for help on using the changeset viewer.