Changes in src/molecule_geometry.cpp [68f03d:a67d19]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_geometry.cpp
r68f03d 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(); … … 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) … … 136 136 ptr = ptr->next; 137 137 Num += 1.; 138 tmp = ptr->x;139 (*a) += tmp;138 tmp.CopyVector(&ptr->x); 139 a->AddVector(&tmp); 140 140 } 141 141 a->Scale(1./Num); // divide through total mass (and sign for direction) … … 161 161 ptr = ptr->next; 162 162 Num += ptr->type->mass; 163 tmp = ptr->type->mass * ptr->x; 164 (*a) += tmp; 163 tmp.CopyVector(&ptr->x); 164 tmp.Scale(ptr->type->mass); // scale by mass 165 a->AddVector(&tmp); 165 166 } 166 167 a->Scale(-1./Num); // divide through total mass (and sign for direction) … … 188 189 void molecule::CenterAtVector(Vector *newcenter) 189 190 { 190 Center = *newcenter;191 Center.CopyVector(newcenter); 191 192 }; 192 193 … … 194 195 /** Scales all atoms by \a *factor. 195 196 * \param *factor pointer to scaling factor 196 *197 * TODO: Is this realy what is meant, i.e.198 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)199 * or rather200 * x=(**factor) * x (as suggested by comment)201 197 */ 202 198 void molecule::Scale(const double ** const factor) … … 207 203 ptr = ptr->next; 208 204 for (int j=0;j<MDSteps;j++) 209 ptr->Trajectory.R.at(j).Scale All(*factor);210 ptr->x.Scale All(*factor);205 ptr->Trajectory.R.at(j).Scale(factor); 206 ptr->x.Scale(factor); 211 207 } 212 208 }; … … 222 218 ptr = ptr->next; 223 219 for (int j=0;j<MDSteps;j++) 224 ptr->Trajectory.R.at(j) += (*trans);225 ptr->x += (*trans);220 ptr->Trajectory.R.at(j).Translate(trans); 221 ptr->x.Translate(trans); 226 222 } 227 223 }; … … 233 229 void molecule::TranslatePeriodically(const Vector *trans) 234 230 { 235 double * const cell_size = World::get Instance().getDomain();231 double * const cell_size = World::get()->cell_size; 236 232 double *M = ReturnFullMatrixforSymmetric(cell_size); 237 233 double *Minv = InverseMatrix(M); 238 234 239 235 // go through all atoms 240 ActOnAllVectors( &Vector::SubtractVector, *trans);236 ActOnAllVectors( &Vector::SubtractVector, trans); 241 237 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 242 238 … … 251 247 void molecule::Mirror(const Vector *n) 252 248 { 253 ActOnAllVectors( &Vector::Mirror, *n );249 ActOnAllVectors( &Vector::Mirror, n ); 254 250 }; 255 251 … … 260 256 { 261 257 atom *Walker = start; 262 double * const cell_size = World::get Instance().getDomain();258 double * const cell_size = World::get()->cell_size; 263 259 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 264 260 double *inversematrix = InverseMatrix(cell_size); … … 275 271 if (Walker->type->Z != 1) { 276 272 #endif 277 Testvector = Walker->x;273 Testvector.CopyVector(&Walker->x); 278 274 Testvector.MatrixMultiplication(inversematrix); 279 275 Translationvector.Zero(); … … 281 277 if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing 282 278 for (int j=0;j<NDIM;j++) { 283 tmp = Walker->x [j] - (*Runner)->GetOtherAtom(Walker)->x[j];279 tmp = Walker->x.x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j]; 284 280 if ((fabs(tmp)) > BondDistance) { 285 281 flag = false; 286 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker-> getName()<< " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);282 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl); 287 283 if (tmp > 0) 288 Translationvector [j] -= 1.;284 Translationvector.x[j] -= 1.; 289 285 else 290 Translationvector [j] += 1.;286 Translationvector.x[j] += 1.; 291 287 } 292 288 } 293 289 } 294 Testvector += Translationvector;290 Testvector.AddVector(&Translationvector); 295 291 Testvector.MatrixMultiplication(matrix); 296 Center += Testvector; 297 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); 298 296 #ifdef ADDHYDROGEN 299 297 // now also change all hydrogens 300 298 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 301 299 if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) { 302 Testvector = (*Runner)->GetOtherAtom(Walker)->x;300 Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x); 303 301 Testvector.MatrixMultiplication(inversematrix); 304 Testvector += Translationvector;302 Testvector.AddVector(&Translationvector); 305 303 Testvector.MatrixMultiplication(matrix); 306 Center += Testvector; 307 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); 308 308 } 309 309 } … … 338 338 while (ptr->next != end) { 339 339 ptr = ptr->next; 340 Vector x = ptr->x; 340 Vector x; 341 x.CopyVector(&ptr->x); 341 342 //x.SubtractVector(CenterOfGravity); 342 InertiaTensor[0] += ptr->type->mass*(x [1]*x[1] + x[2]*x[2]);343 InertiaTensor[1] += ptr->type->mass*(-x [0]*x[1]);344 InertiaTensor[2] += ptr->type->mass*(-x [0]*x[2]);345 InertiaTensor[3] += ptr->type->mass*(-x [1]*x[0]);346 InertiaTensor[4] += ptr->type->mass*(x [0]*x[0] + x[2]*x[2]);347 InertiaTensor[5] += ptr->type->mass*(-x [1]*x[2]);348 InertiaTensor[6] += ptr->type->mass*(-x [2]*x[0]);349 InertiaTensor[7] += ptr->type->mass*(-x [2]*x[1]);350 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]); 351 352 } 352 353 // print InertiaTensor for debugging … … 389 390 while (ptr->next != end) { 390 391 ptr = ptr->next; 391 Vector x = ptr->x; 392 Vector x; 393 x.CopyVector(&ptr->x); 392 394 //x.SubtractVector(CenterOfGravity); 393 InertiaTensor[0] += ptr->type->mass*(x [1]*x[1] + x[2]*x[2]);394 InertiaTensor[1] += ptr->type->mass*(-x [0]*x[1]);395 InertiaTensor[2] += ptr->type->mass*(-x [0]*x[2]);396 InertiaTensor[3] += ptr->type->mass*(-x [1]*x[0]);397 InertiaTensor[4] += ptr->type->mass*(x [0]*x[0] + x[2]*x[2]);398 InertiaTensor[5] += ptr->type->mass*(-x [1]*x[2]);399 InertiaTensor[6] += ptr->type->mass*(-x [2]*x[0]);400 InertiaTensor[7] += ptr->type->mass*(-x [2]*x[1]);401 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]); 402 404 } 403 405 // print InertiaTensor for debugging … … 426 428 double alpha, tmp; 427 429 Vector z_axis; 428 z_axis [0] = 0.;429 z_axis [1] = 0.;430 z_axis [2] = 1.;430 z_axis.x[0] = 0.; 431 z_axis.x[1] = 0.; 432 z_axis.x[2] = 1.; 431 433 432 434 // rotate on z-x plane 433 435 DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl); 434 alpha = atan(-n-> at(0)/n->at(2));436 alpha = atan(-n->x[0]/n->x[2]); 435 437 DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... "); 436 438 while (ptr->next != end) { 437 439 ptr = ptr->next; 438 tmp = ptr->x [0];439 ptr->x [0] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];440 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]; 441 443 for (int j=0;j<MDSteps;j++) { 442 tmp = ptr->Trajectory.R.at(j) [0];443 ptr->Trajectory.R.at(j) [0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];444 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]; 445 447 } 446 448 } 447 449 // rotate n vector 448 tmp = n->at(0); 449 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2); 450 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 451 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); 452 456 453 457 // rotate on z-y plane 454 458 ptr = start; 455 alpha = atan(-n-> at(1)/n->at(2));459 alpha = atan(-n->x[1]/n->x[2]); 456 460 DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... "); 457 461 while (ptr->next != end) { 458 462 ptr = ptr->next; 459 tmp = ptr->x [1];460 ptr->x [1] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];461 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]; 462 466 for (int j=0;j<MDSteps;j++) { 463 tmp = ptr->Trajectory.R.at(j) [1];464 ptr->Trajectory.R.at(j) [1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];465 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]; 466 470 } 467 471 } 468 472 // rotate n vector (for consistency check) 469 tmp = n->at(1); 470 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2); 471 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 472 473 474 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); 475 480 DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl); 476 481 }; … … 490 495 491 496 // initialize vectors 492 a [0] = gsl_vector_get(x,0);493 a [1] = gsl_vector_get(x,1);494 a [2] = gsl_vector_get(x,2);495 b [0] = gsl_vector_get(x,3);496 b [1] = gsl_vector_get(x,4);497 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); 498 503 // go through all atoms 499 504 while (ptr != par->mol->end) { 500 505 ptr = ptr->next; 501 506 if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type 502 c = ptr->x - a; 503 t = c.ScalarProduct(b); // get direction parameter 504 d = t*b; // and create vector 505 c -= d; // ... yielding distance vector 506 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 507 514 } 508 515 }
Note:
See TracChangeset
for help on using the changeset viewer.