Changes in src/molecule_geometry.cpp [673c7f:a67d19]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_geometry.cpp
r673c7f ra67d19 27 27 bool status = true; 28 28 const Vector *Center = DetermineCenterOfAll(); 29 double * const cell_size = World::get Instance().getDomain();29 double * const cell_size = World::get()->cell_size; 30 30 double *M = ReturnFullMatrixforSymmetric(cell_size); 31 31 double *Minv = InverseMatrix(M); 32 32 33 33 // go through all atoms 34 ActOnAllVectors( &Vector::SubtractVector, *Center);34 ActOnAllVectors( &Vector::SubtractVector, Center); 35 35 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 36 36 … … 48 48 { 49 49 bool status = true; 50 double * const cell_size = World::get Instance().getDomain();50 double * const cell_size = World::get()->cell_size; 51 51 double *M = ReturnFullMatrixforSymmetric(cell_size); 52 52 double *Minv = InverseMatrix(M); … … 72 72 if (ptr != end) { //list not empty? 73 73 for (int i=NDIM;i--;) { 74 max-> at(i) = ptr->x[i];75 min-> at(i) = ptr->x[i];74 max->x[i] = ptr->x.x[i]; 75 min->x[i] = ptr->x.x[i]; 76 76 } 77 77 while (ptr->next != end) { // continue with second if present … … 79 79 //ptr->Output(1,1,out); 80 80 for (int i=NDIM;i--;) { 81 max-> at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i);82 min-> at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i);81 max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i]; 82 min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i]; 83 83 } 84 84 } … … 89 89 // Log() << Verbose(0) << endl; 90 90 min->Scale(-1.); 91 (*max) += (*min);91 max->AddVector(min); 92 92 Translate(min); 93 93 Center.Zero(); … … 109 109 110 110 if (ptr->next != end) { //list not empty? 111 while (ptr->next != end) { 111 while (ptr->next != end) { // continue with second if present 112 112 ptr = ptr->next; 113 113 Num++; 114 Center += ptr->x;114 Center.AddVector(&ptr->x); 115 115 } 116 116 Center.Scale(-1./Num); // divide through total number (and sign for direction) … … 124 124 */ 125 125 Vector * molecule::DetermineCenterOfAll() const 126 {127 atom *ptr = start; // start at first in list128 Vector *a = new Vector();129 double Num = 0;130 131 a->Zero();132 133 if (ptr->next != end) { //list not empty?134 while (ptr->next != end) {135 ptr = ptr->next;136 Num += 1.;137 (*a) += ptr->x;138 }139 a->Scale(1./Num); // divide through total mass (and sign for direction)140 }141 return a;142 };143 144 /** Returns vector pointing to center of gravity.145 * \param *out output stream for debugging146 * \return pointer to center of gravity vector147 */148 Vector * molecule::DetermineCenterOfGravity()149 126 { 150 127 atom *ptr = start->next; // start at first in list … … 158 135 while (ptr->next != end) { // continue with second if present 159 136 ptr = ptr->next; 137 Num += 1.; 138 tmp.CopyVector(&ptr->x); 139 a->AddVector(&tmp); 140 } 141 a->Scale(1./Num); // divide through total mass (and sign for direction) 142 } 143 return a; 144 }; 145 146 /** Returns vector pointing to center of gravity. 147 * \param *out output stream for debugging 148 * \return pointer to center of gravity vector 149 */ 150 Vector * molecule::DetermineCenterOfGravity() 151 { 152 atom *ptr = start->next; // start at first in list 153 Vector *a = new Vector(); 154 Vector tmp; 155 double Num = 0; 156 157 a->Zero(); 158 159 if (ptr != end) { //list not empty? 160 while (ptr->next != end) { // continue with second if present 161 ptr = ptr->next; 160 162 Num += ptr->type->mass; 161 tmp = ptr->type->mass * ptr->x; 162 (*a) += tmp; 163 tmp.CopyVector(&ptr->x); 164 tmp.Scale(ptr->type->mass); // scale by mass 165 a->AddVector(&tmp); 163 166 } 164 167 a->Scale(-1./Num); // divide through total mass (and sign for direction) … … 186 189 void molecule::CenterAtVector(Vector *newcenter) 187 190 { 188 Center = *newcenter;191 Center.CopyVector(newcenter); 189 192 }; 190 193 … … 192 195 /** Scales all atoms by \a *factor. 193 196 * \param *factor pointer to scaling factor 194 *195 * TODO: Is this realy what is meant, i.e.196 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)197 * or rather198 * x=(**factor) * x (as suggested by comment)199 197 */ 200 198 void molecule::Scale(const double ** const factor) … … 205 203 ptr = ptr->next; 206 204 for (int j=0;j<MDSteps;j++) 207 ptr->Trajectory.R.at(j).Scale All(*factor);208 ptr->x.Scale All(*factor);205 ptr->Trajectory.R.at(j).Scale(factor); 206 ptr->x.Scale(factor); 209 207 } 210 208 }; … … 220 218 ptr = ptr->next; 221 219 for (int j=0;j<MDSteps;j++) 222 ptr->Trajectory.R.at(j) += (*trans);223 ptr->x += (*trans);220 ptr->Trajectory.R.at(j).Translate(trans); 221 ptr->x.Translate(trans); 224 222 } 225 223 }; … … 231 229 void molecule::TranslatePeriodically(const Vector *trans) 232 230 { 233 double * const cell_size = World::get Instance().getDomain();231 double * const cell_size = World::get()->cell_size; 234 232 double *M = ReturnFullMatrixforSymmetric(cell_size); 235 233 double *Minv = InverseMatrix(M); 236 234 237 235 // go through all atoms 238 ActOnAllVectors( &Vector::SubtractVector, *trans);236 ActOnAllVectors( &Vector::SubtractVector, trans); 239 237 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 240 238 … … 249 247 void molecule::Mirror(const Vector *n) 250 248 { 251 ActOnAllVectors( &Vector::Mirror, *n );249 ActOnAllVectors( &Vector::Mirror, n ); 252 250 }; 253 251 … … 258 256 { 259 257 atom *Walker = start; 260 double * const cell_size = World::get Instance().getDomain();258 double * const cell_size = World::get()->cell_size; 261 259 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 262 260 double *inversematrix = InverseMatrix(cell_size); … … 273 271 if (Walker->type->Z != 1) { 274 272 #endif 275 Testvector = Walker->x;273 Testvector.CopyVector(&Walker->x); 276 274 Testvector.MatrixMultiplication(inversematrix); 277 275 Translationvector.Zero(); … … 279 277 if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing 280 278 for (int j=0;j<NDIM;j++) { 281 tmp = Walker->x [j] - (*Runner)->GetOtherAtom(Walker)->x[j];279 tmp = Walker->x.x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j]; 282 280 if ((fabs(tmp)) > BondDistance) { 283 281 flag = false; 284 282 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl); 285 283 if (tmp > 0) 286 Translationvector [j] -= 1.;284 Translationvector.x[j] -= 1.; 287 285 else 288 Translationvector [j] += 1.;286 Translationvector.x[j] += 1.; 289 287 } 290 288 } 291 289 } 292 Testvector += Translationvector;290 Testvector.AddVector(&Translationvector); 293 291 Testvector.MatrixMultiplication(matrix); 294 Center += Testvector; 295 Log() << Verbose(1) << "vector is: " << Testvector << endl; 292 Center.AddVector(&Testvector); 293 DoLog(1) && (Log() << Verbose(1) << "vector is: "); 294 Testvector.Output(); 295 DoLog(0) && (Log() << Verbose(0) << endl); 296 296 #ifdef ADDHYDROGEN 297 297 // now also change all hydrogens 298 298 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 299 299 if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) { 300 Testvector = (*Runner)->GetOtherAtom(Walker)->x;300 Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x); 301 301 Testvector.MatrixMultiplication(inversematrix); 302 Testvector += Translationvector;302 Testvector.AddVector(&Translationvector); 303 303 Testvector.MatrixMultiplication(matrix); 304 Center += Testvector; 305 Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl; 304 Center.AddVector(&Testvector); 305 DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: "); 306 Testvector.Output(); 307 DoLog(0) && (Log() << Verbose(0) << endl); 306 308 } 307 309 } … … 336 338 while (ptr->next != end) { 337 339 ptr = ptr->next; 338 Vector x = ptr->x; 340 Vector x; 341 x.CopyVector(&ptr->x); 339 342 //x.SubtractVector(CenterOfGravity); 340 InertiaTensor[0] += ptr->type->mass*(x [1]*x[1] + x[2]*x[2]);341 InertiaTensor[1] += ptr->type->mass*(-x [0]*x[1]);342 InertiaTensor[2] += ptr->type->mass*(-x [0]*x[2]);343 InertiaTensor[3] += ptr->type->mass*(-x [1]*x[0]);344 InertiaTensor[4] += ptr->type->mass*(x [0]*x[0] + x[2]*x[2]);345 InertiaTensor[5] += ptr->type->mass*(-x [1]*x[2]);346 InertiaTensor[6] += ptr->type->mass*(-x [2]*x[0]);347 InertiaTensor[7] += ptr->type->mass*(-x [2]*x[1]);348 InertiaTensor[8] += ptr->type->mass*(x [0]*x[0] + x[1]*x[1]);343 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]); 344 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]); 345 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]); 346 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]); 347 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]); 348 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]); 349 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]); 350 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]); 351 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]); 349 352 } 350 353 // print InertiaTensor for debugging … … 387 390 while (ptr->next != end) { 388 391 ptr = ptr->next; 389 Vector x = ptr->x; 392 Vector x; 393 x.CopyVector(&ptr->x); 390 394 //x.SubtractVector(CenterOfGravity); 391 InertiaTensor[0] += ptr->type->mass*(x [1]*x[1] + x[2]*x[2]);392 InertiaTensor[1] += ptr->type->mass*(-x [0]*x[1]);393 InertiaTensor[2] += ptr->type->mass*(-x [0]*x[2]);394 InertiaTensor[3] += ptr->type->mass*(-x [1]*x[0]);395 InertiaTensor[4] += ptr->type->mass*(x [0]*x[0] + x[2]*x[2]);396 InertiaTensor[5] += ptr->type->mass*(-x [1]*x[2]);397 InertiaTensor[6] += ptr->type->mass*(-x [2]*x[0]);398 InertiaTensor[7] += ptr->type->mass*(-x [2]*x[1]);399 InertiaTensor[8] += ptr->type->mass*(x [0]*x[0] + x[1]*x[1]);395 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]); 396 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]); 397 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]); 398 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]); 399 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]); 400 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]); 401 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]); 402 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]); 403 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]); 400 404 } 401 405 // print InertiaTensor for debugging … … 424 428 double alpha, tmp; 425 429 Vector z_axis; 426 z_axis [0] = 0.;427 z_axis [1] = 0.;428 z_axis [2] = 1.;430 z_axis.x[0] = 0.; 431 z_axis.x[1] = 0.; 432 z_axis.x[2] = 1.; 429 433 430 434 // rotate on z-x plane 431 435 DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl); 432 alpha = atan(-n-> at(0)/n->at(2));436 alpha = atan(-n->x[0]/n->x[2]); 433 437 DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... "); 434 438 while (ptr->next != end) { 435 439 ptr = ptr->next; 436 tmp = ptr->x [0];437 ptr->x [0] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];438 ptr->x [2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];440 tmp = ptr->x.x[0]; 441 ptr->x.x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2]; 442 ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2]; 439 443 for (int j=0;j<MDSteps;j++) { 440 tmp = ptr->Trajectory.R.at(j) [0];441 ptr->Trajectory.R.at(j) [0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];442 ptr->Trajectory.R.at(j) [2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];444 tmp = ptr->Trajectory.R.at(j).x[0]; 445 ptr->Trajectory.R.at(j).x[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2]; 446 ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2]; 443 447 } 444 448 } 445 449 // rotate n vector 446 tmp = n->at(0); 447 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2); 448 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 449 DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl); 450 tmp = n->x[0]; 451 n->x[0] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 452 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 453 DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: "); 454 n->Output(); 455 DoLog(0) && (Log() << Verbose(0) << endl); 450 456 451 457 // rotate on z-y plane 452 458 ptr = start; 453 alpha = atan(-n-> at(1)/n->at(2));459 alpha = atan(-n->x[1]/n->x[2]); 454 460 DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... "); 455 461 while (ptr->next != end) { 456 462 ptr = ptr->next; 457 tmp = ptr->x [1];458 ptr->x [1] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];459 ptr->x [2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];463 tmp = ptr->x.x[1]; 464 ptr->x.x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2]; 465 ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2]; 460 466 for (int j=0;j<MDSteps;j++) { 461 tmp = ptr->Trajectory.R.at(j) [1];462 ptr->Trajectory.R.at(j) [1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];463 ptr->Trajectory.R.at(j) [2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];467 tmp = ptr->Trajectory.R.at(j).x[1]; 468 ptr->Trajectory.R.at(j).x[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2]; 469 ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2]; 464 470 } 465 471 } 466 472 // rotate n vector (for consistency check) 467 tmp = n->at(1); 468 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2); 469 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 470 471 472 DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl); 473 tmp = n->x[1]; 474 n->x[1] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 475 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 476 477 DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: "); 478 n->Output(); 479 DoLog(1) && (Log() << Verbose(1) << endl); 473 480 DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl); 474 481 }; … … 488 495 489 496 // initialize vectors 490 a [0] = gsl_vector_get(x,0);491 a [1] = gsl_vector_get(x,1);492 a [2] = gsl_vector_get(x,2);493 b [0] = gsl_vector_get(x,3);494 b [1] = gsl_vector_get(x,4);495 b [2] = gsl_vector_get(x,5);497 a.x[0] = gsl_vector_get(x,0); 498 a.x[1] = gsl_vector_get(x,1); 499 a.x[2] = gsl_vector_get(x,2); 500 b.x[0] = gsl_vector_get(x,3); 501 b.x[1] = gsl_vector_get(x,4); 502 b.x[2] = gsl_vector_get(x,5); 496 503 // go through all atoms 497 504 while (ptr != par->mol->end) { 498 505 ptr = ptr->next; 499 506 if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type 500 c = ptr->x - a; 501 t = c.ScalarProduct(b); // get direction parameter 502 d = t*b; // and create vector 503 c -= d; // ... yielding distance vector 504 res += d.ScalarProduct(d); // add squared distance 507 c.CopyVector(&ptr->x); // copy vector to temporary one 508 c.SubtractVector(&a); // subtract offset vector 509 t = c.ScalarProduct(&b); // get direction parameter 510 d.CopyVector(&b); // and create vector 511 d.Scale(&t); 512 c.SubtractVector(&d); // ... yielding distance vector 513 res += d.ScalarProduct((const Vector *)&d); // add squared distance 505 514 } 506 515 }
Note:
See TracChangeset
for help on using the changeset viewer.