| 1 |
|
#include <math.h> |
| 2 |
+ |
#include <iostream> |
| 3 |
|
#include "RigidBody.hpp" |
| 4 |
|
#include "VDWAtom.hpp" |
| 5 |
|
#include "MatVec3.h" |
| 16 |
|
void RigidBody::addAtom(VDWAtom* at) { |
| 17 |
|
|
| 18 |
|
vec3 coords; |
| 18 |
– |
vec3 euler; |
| 19 |
– |
mat3x3 Atmp; |
| 19 |
|
|
| 20 |
|
myAtoms.push_back(at); |
| 21 |
|
|
| 48 |
|
A[2][1] = -cos(phi) * sin(theta); |
| 49 |
|
A[2][2] = cos(theta); |
| 50 |
|
|
| 51 |
+ |
printf("A[2][x] = %lf\t%lf\t%lf\n", A[2][0], A[2][1], A[2][2]); |
| 52 |
+ |
|
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
void RigidBody::getQ( double q[4] ){ |
| 176 |
|
|
| 177 |
|
void RigidBody::calcRefCoords( ) { |
| 178 |
|
|
| 179 |
< |
int i,j,k, it, n_linear_coords; |
| 179 |
> |
int i, j, it, n_linear_coords, pAxis, maxAxis, midAxis; |
| 180 |
|
double mtmp; |
| 181 |
|
vec3 apos; |
| 182 |
|
double refCOM[3]; |
| 183 |
|
vec3 ptmp; |
| 184 |
|
double Itmp[3][3]; |
| 185 |
< |
double evals[3]; |
| 186 |
< |
double evects[3][3]; |
| 185 |
> |
double pAxisMat[3][3], pAxisRotMat[3][3]; |
| 186 |
> |
double evals[3]; |
| 187 |
|
double r, r2, len; |
| 188 |
< |
|
| 188 |
> |
double iMat[3][3]; |
| 189 |
> |
double test[3]; |
| 190 |
> |
|
| 191 |
|
// First, find the center of mass: |
| 192 |
|
|
| 193 |
|
mass = 0.0; |
| 199 |
|
mass += mtmp; |
| 200 |
|
|
| 201 |
|
apos = refCoords[i]; |
| 199 |
– |
|
| 202 |
|
for(j = 0; j < 3; j++) { |
| 203 |
|
refCOM[j] += apos[j]*mtmp; |
| 204 |
|
} |
| 262 |
|
if (n_linear_coords > 1) { |
| 263 |
|
printf( |
| 264 |
|
"RigidBody error.\n" |
| 265 |
< |
"\tOOPSE found more than one axis in this rigid body with a vanishing \n" |
| 265 |
> |
"\tSHAPES found more than one axis in this rigid body with a vanishing \n" |
| 266 |
|
"\tmoment of inertia. This can happen in one of three ways:\n" |
| 267 |
|
"\t 1) Only one atom was specified, or \n" |
| 268 |
|
"\t 2) All atoms were specified at the same location, or\n" |
| 271 |
|
); |
| 272 |
|
exit(-1); |
| 273 |
|
} |
| 274 |
< |
|
| 274 |
> |
|
| 275 |
|
// renormalize column vectors: |
| 276 |
|
|
| 277 |
|
for (i=0; i < 3; i++) { |
| 282 |
|
len = sqrt(len); |
| 283 |
|
for (j = 0; j < 3; j++) { |
| 284 |
|
sU[i][j] /= len; |
| 285 |
+ |
} |
| 286 |
+ |
} |
| 287 |
+ |
|
| 288 |
+ |
//sort and reorder the moment axes |
| 289 |
+ |
|
| 290 |
+ |
// The only problem below is for molecules like C60 with 3 nearly identical |
| 291 |
+ |
// non-zero moments of inertia. In this case it doesn't really matter which is |
| 292 |
+ |
// the principal axis, so they get assigned nearly randomly depending on the |
| 293 |
+ |
// floating point comparison between eigenvalues |
| 294 |
+ |
if (! is_linear) { |
| 295 |
+ |
pAxis = 0; |
| 296 |
+ |
maxAxis = 0; |
| 297 |
+ |
|
| 298 |
+ |
for (i = 0; i < 3; i++) { |
| 299 |
+ |
if (evals[i] < evals[pAxis]) pAxis = i; |
| 300 |
+ |
if (evals[i] > evals[maxAxis]) maxAxis = i; |
| 301 |
|
} |
| 302 |
+ |
|
| 303 |
+ |
midAxis = 0; |
| 304 |
+ |
for (i=0; i < 3; i++) { |
| 305 |
+ |
if (pAxis != i && maxAxis != i) midAxis = i; |
| 306 |
+ |
} |
| 307 |
+ |
} else { |
| 308 |
+ |
pAxis = linear_axis; |
| 309 |
+ |
// linear molecules have one zero moment of inertia and two identical |
| 310 |
+ |
// moments of inertia. In this case, it doesn't matter which is chosen |
| 311 |
+ |
// as mid and which is max, so just permute from the pAxis: |
| 312 |
+ |
midAxis = (pAxis + 1)%3; |
| 313 |
+ |
maxAxis = (pAxis + 2)%3; |
| 314 |
|
} |
| 315 |
+ |
|
| 316 |
+ |
//let z be the smallest and x be the largest eigenvalue axes |
| 317 |
+ |
for (i=0; i<3; i++){ |
| 318 |
+ |
pAxisMat[i][2] = sU[i][pAxis]; |
| 319 |
+ |
pAxisMat[i][1] = sU[i][midAxis]; |
| 320 |
+ |
pAxisMat[i][0] = sU[i][maxAxis]; |
| 321 |
+ |
} |
| 322 |
+ |
|
| 323 |
+ |
//calculate the proper rotation matrix |
| 324 |
+ |
transposeMat3(pAxisMat, pAxisRotMat); |
| 325 |
+ |
|
| 326 |
+ |
|
| 327 |
+ |
for (i=0; i<myAtoms.size(); i++){ |
| 328 |
+ |
apos = refCoords[i]; |
| 329 |
+ |
printf("%f\t%f\t%f\n",apos[0],apos[1],apos[2]); |
| 330 |
+ |
} |
| 331 |
+ |
|
| 332 |
+ |
//rotate the rigid body to the principle axis frame |
| 333 |
+ |
for (i = 0; i < myAtoms.size(); i++) { |
| 334 |
+ |
matVecMul3(pAxisRotMat, refCoords[i].vec, refCoords[i].vec); |
| 335 |
+ |
myAtoms[i]->setPos(refCoords[i].vec); |
| 336 |
+ |
} |
| 337 |
+ |
|
| 338 |
+ |
for (i=0; i<myAtoms.size(); i++){ |
| 339 |
+ |
apos = refCoords[i]; |
| 340 |
+ |
printf("%f\t%f\t%f\n",apos[0],apos[1],apos[2]); |
| 341 |
+ |
} |
| 342 |
+ |
|
| 343 |
+ |
identityMat3(iMat); |
| 344 |
+ |
setA(iMat); |
| 345 |
|
} |
| 346 |
|
|
| 347 |
< |
void RigidBody::doEulerToRotMat(vec3 &euler, mat3x3 &myA ){ |
| 347 |
> |
void RigidBody::doEulerToRotMat(double euler[3], double myA[3][3] ){ |
| 348 |
|
|
| 349 |
|
double phi, theta, psi; |
| 350 |
|
|
| 404 |
|
|
| 405 |
|
|
| 406 |
|
double phi,theta,psi,eps; |
| 407 |
< |
double pi; |
| 408 |
< |
double cphi,ctheta,cpsi; |
| 409 |
< |
double sphi,stheta,spsi; |
| 350 |
< |
double b[3]; |
| 351 |
< |
int flip[3]; |
| 352 |
< |
|
| 407 |
> |
double ctheta; |
| 408 |
> |
double stheta; |
| 409 |
> |
|
| 410 |
|
// set the tolerance for Euler angles and rotation elements |
| 411 |
|
|
| 412 |
|
eps = 1.0e-8; |
| 457 |
|
return (x > y) ? y : x; |
| 458 |
|
} |
| 459 |
|
|
| 460 |
+ |
double RigidBody::findMaxExtent(){ |
| 461 |
+ |
int i; |
| 462 |
+ |
double refAtomPos[3]; |
| 463 |
+ |
double maxExtent; |
| 464 |
+ |
double tempExtent; |
| 465 |
+ |
|
| 466 |
+ |
//zero the extent variables |
| 467 |
+ |
maxExtent = 0.0; |
| 468 |
+ |
tempExtent = 0.0; |
| 469 |
+ |
for (i=0; i<3; i++) |
| 470 |
+ |
refAtomPos[i] = 0.0; |
| 471 |
+ |
|
| 472 |
+ |
//loop over all atoms |
| 473 |
+ |
for (i=0; i<myAtoms.size(); i++){ |
| 474 |
+ |
getAtomRefCoor(refAtomPos, i); |
| 475 |
+ |
tempExtent = sqrt(refAtomPos[0]*refAtomPos[0] + refAtomPos[1]*refAtomPos[1] |
| 476 |
+ |
+ refAtomPos[2]*refAtomPos[2]); |
| 477 |
+ |
if (tempExtent > maxExtent) |
| 478 |
+ |
maxExtent = tempExtent; |
| 479 |
+ |
} |
| 480 |
+ |
return maxExtent; |
| 481 |
+ |
} |
| 482 |
+ |
|
| 483 |
|
void RigidBody::findCOM() { |
| 484 |
|
|
| 485 |
|
size_t i; |
| 486 |
|
int j; |
| 487 |
|
double mtmp; |
| 488 |
|
double ptmp[3]; |
| 489 |
< |
double vtmp[3]; |
| 410 |
< |
|
| 489 |
> |
|
| 490 |
|
for(j = 0; j < 3; j++) { |
| 491 |
|
pos[j] = 0.0; |
| 492 |
|
} |
| 536 |
|
pos[2] = ref[2]; |
| 537 |
|
|
| 538 |
|
} |
| 539 |
+ |
|
| 540 |
+ |
double RigidBody::getAtomRpar(int index){ |
| 541 |
+ |
|
| 542 |
+ |
return myAtoms[index]->getRpar(); |
| 543 |
+ |
|
| 544 |
+ |
} |
| 545 |
+ |
|
| 546 |
+ |
double RigidBody::getAtomEps(int index){ |
| 547 |
+ |
|
| 548 |
+ |
return myAtoms[index]->getEps(); |
| 549 |
+ |
|
| 550 |
+ |
} |