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