Revisão | 8e1b5afb7d3da25153560595abb9b7e062808855 (tree) |
---|---|
Hora | 2011-01-07 20:14:24 |
Autor | Mikiya Fujii <mikiya.fujii@gmai...> |
Commiter | Mikiya Fujii |
Logic to rotate molecule is added.
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/MolDS/trunk@51 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -13,6 +13,7 @@ | ||
13 | 13 | #undef INCLUDED_ENUMS |
14 | 14 | #define RENUMSTR_BODY 1 |
15 | 15 | #include"base/Enums.h" |
16 | +#include"base/MathUtilities.h" | |
16 | 17 | #include"base/EularAngle.h" |
17 | 18 | #include"base/Molecule.h" |
18 | 19 | #include"base/atoms/Atom.h" |
@@ -18,13 +18,18 @@ RENUMSTR_BEGIN( TheoryType, TheoryTypeStr ) | ||
18 | 18 | RENUMSTR( TheoryType_end, "TheoryType_end" ) |
19 | 19 | RENUMSTR_END() |
20 | 20 | |
21 | - | |
22 | 21 | RENUMSTR_BEGIN( RotatingType, RotatingTypeStr ) |
23 | 22 | RENUMSTR( Axis, "Axis" ) |
24 | 23 | RENUMSTR( Eular, "EularAngle" ) |
25 | 24 | RENUMSTR( RotatingType_end, "RotatingType_end" ) |
26 | 25 | RENUMSTR_END() |
27 | 26 | |
27 | +RENUMSTR_BEGIN( RotatedObjectType, RotatedObjectTypeStr ) | |
28 | + RENUMSTR( System, "System" ) | |
29 | + RENUMSTR( Frame, "Frame" ) | |
30 | + RENUMSTR( RotatedObjectType_end, "RotatedObjectType_end" ) | |
31 | +RENUMSTR_END() | |
32 | + | |
28 | 33 | RENUMSTR_BEGIN( ShellType, ShellTypeStr ) |
29 | 34 | RENUMSTR( k, "k" ) |
30 | 35 | RENUMSTR( l, "l" ) |
@@ -32,6 +37,13 @@ RENUMSTR_BEGIN( ShellType, ShellTypeStr ) | ||
32 | 37 | RENUMSTR( ShellType_end, "ShellType_end" ) |
33 | 38 | RENUMSTR_END() |
34 | 39 | |
40 | +RENUMSTR_BEGIN( CartesianType, CartesianTypeStr ) | |
41 | + RENUMSTR( XAxis, "XAxis" ) | |
42 | + RENUMSTR( YAxis, "YAxis" ) | |
43 | + RENUMSTR( ZAxis, "ZAxis" ) | |
44 | + RENUMSTR( CartesianType_end, "CartesianType_end" ) | |
45 | +RENUMSTR_END() | |
46 | + | |
35 | 47 | RENUMSTR_BEGIN( OrbitalType, OrbitalTypeStr ) |
36 | 48 | RENUMSTR( s, "s" ) |
37 | 49 | RENUMSTR( py, "py" ) |
@@ -68,6 +68,57 @@ template <typename T> T min(T a, T b){ | ||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | +void CalcRotatingMatrix(double matrix[][3], double sita, CartesianType cartesianType){ | |
72 | + if(cartesianType == XAxis){ | |
73 | + matrix[0][0] = 1.0; | |
74 | + matrix[0][1] = 0.0; | |
75 | + matrix[0][2] = 0.0; | |
76 | + | |
77 | + matrix[1][0] = 0.0; | |
78 | + matrix[1][1] = cos(sita); | |
79 | + matrix[1][2] = sin(sita); | |
80 | + | |
81 | + matrix[2][0] = 0.0; | |
82 | + matrix[2][1] = -sin(sita); | |
83 | + matrix[2][2] = cos(sita); | |
84 | + } | |
85 | + else if(cartesianType == YAxis){ | |
86 | + matrix[0][0] = cos(sita); | |
87 | + matrix[0][1] = 0.0; | |
88 | + matrix[0][2] = -sin(sita); | |
89 | + | |
90 | + matrix[1][0] = 0.0; | |
91 | + matrix[1][1] = 1.0; | |
92 | + matrix[1][2] = 0.0; | |
93 | + | |
94 | + matrix[2][0] = sin(sita); | |
95 | + matrix[2][1] = 0.0; | |
96 | + matrix[2][2] = cos(sita); | |
97 | + } | |
98 | + else if(cartesianType == ZAxis){ | |
99 | + matrix[0][0] = cos(sita); | |
100 | + matrix[0][1] = sin(sita); | |
101 | + matrix[0][2] = 0.0; | |
102 | + | |
103 | + matrix[1][0] = -sin(sita); | |
104 | + matrix[1][1] = cos(sita); | |
105 | + matrix[1][2] = 0.0; | |
106 | + | |
107 | + matrix[2][0] = 0.0; | |
108 | + matrix[2][1] = 0.0; | |
109 | + matrix[2][2] = 1.0; | |
110 | + } | |
111 | + else{ | |
112 | + stringstream ss; | |
113 | + ss << "Error in base::MathUtility::CalcRotatingMatrix: invalid cartesianType \n"; | |
114 | + throw MolDSException(ss.str()); | |
115 | + } | |
116 | +} | |
117 | + | |
118 | + | |
119 | + | |
120 | + | |
121 | + | |
71 | 122 | |
72 | 123 | } |
73 | 124 | #endif |
@@ -29,7 +29,6 @@ public: | ||
29 | 29 | void OutputConfiguration(); |
30 | 30 | void CalcPrincipalAxes(); |
31 | 31 | void Rotate(); |
32 | - void Rotate(EularAngle eularAngle); | |
33 | 32 | void Translate(); |
34 | 33 | private: |
35 | 34 | vector<Atom*>* atomVect; |
@@ -39,6 +38,7 @@ private: | ||
39 | 38 | int totalNumberValenceElectrons; |
40 | 39 | void CalcInertiaTensor(double** inertiaTensor, double* inertiaTensorOrigin); |
41 | 40 | void FreeInertiaTensorMoments(double** inertiaTensor, double* inertiaMoments); |
41 | + void Rotate(EularAngle eularAngle, double* rotatingOrigin, RotatedObjectType rotatedObj); | |
42 | 42 | void OutputPrincipalAxes(double** inertiaTensor, double* inertiaMoments); |
43 | 43 | void OutputInertiaTensorOrigin(double* inertiaTensorOrigin); |
44 | 44 | void OutputRotatingConditions(RotatingType rotatingType, double* rotatingOrigin, |
@@ -380,9 +380,9 @@ void Molecule::Rotate(){ | ||
380 | 380 | } |
381 | 381 | double rotatingOrigin[3] = {this->xyzCOM[0], this->xyzCOM[1], this->xyzCOM[2]}; |
382 | 382 | if(Parameters::GetInstance()->GetRotatingOrigin() != NULL){ |
383 | - rotatingOrigin[0] = Parameters::GetInstance()->GetInertiaTensorOrigin()[0]; | |
384 | - rotatingOrigin[1] = Parameters::GetInstance()->GetInertiaTensorOrigin()[1]; | |
385 | - rotatingOrigin[2] = Parameters::GetInstance()->GetInertiaTensorOrigin()[2]; | |
383 | + rotatingOrigin[0] = Parameters::GetInstance()->GetRotatingOrigin()[0]; | |
384 | + rotatingOrigin[1] = Parameters::GetInstance()->GetRotatingOrigin()[1]; | |
385 | + rotatingOrigin[2] = Parameters::GetInstance()->GetRotatingOrigin()[2]; | |
386 | 386 | } |
387 | 387 | |
388 | 388 | RotatingType rotatingType = Parameters::GetInstance()->GetRotatingType(); |
@@ -396,16 +396,84 @@ void Molecule::Rotate(){ | ||
396 | 396 | |
397 | 397 | // rotate |
398 | 398 | if(rotatingType == Axis){ |
399 | + EularAngle setZAxisEularAngles(rotatingAxis[0], rotatingAxis[1], rotatingAxis[2]); | |
400 | + EularAngle angleAroundAxis; | |
401 | + angleAroundAxis.SetAlpha(rotatingAngle); | |
402 | + | |
403 | + this->Rotate(setZAxisEularAngles, rotatingOrigin, Frame); | |
404 | + this->Rotate(angleAroundAxis, rotatingOrigin, System); | |
405 | + this->Rotate(setZAxisEularAngles, rotatingOrigin, System); | |
399 | 406 | } |
400 | 407 | else if(rotatingType == Eular){ |
401 | - this->Rotate(rotatingEularAngles); | |
408 | + this->Rotate(rotatingEularAngles, rotatingOrigin, System); | |
402 | 409 | } |
403 | - | |
410 | + | |
411 | + this->OutputConfiguration(); | |
404 | 412 | cout << this->messageDoneRotate; |
405 | 413 | } |
406 | 414 | |
407 | -void Molecule::Rotate(EularAngle eularAngle){ | |
408 | - // ToDo: rotate | |
415 | +/*** | |
416 | + * rotatedObj == System: Molecule is rotated. | |
417 | + * rotatedObj == Frame: De Cartesian is rotated. | |
418 | + */ | |
419 | +void Molecule::Rotate(EularAngle eularAngle, double* rotatingOrigin, RotatedObjectType rotatedObj){ | |
420 | + | |
421 | + double rotatingMatrixAlpha[3][3]; | |
422 | + double rotatingMatrixBeta[3][3]; | |
423 | + double rotatingMatrixGamma[3][3]; | |
424 | + double inv = 1.0; | |
425 | + if(rotatedObj == System){ | |
426 | + inv = -1.0; | |
427 | + } | |
428 | + | |
429 | + CalcRotatingMatrix(rotatingMatrixAlpha, inv*eularAngle.GetAlpha(), ZAxis); | |
430 | + CalcRotatingMatrix(rotatingMatrixBeta, inv*eularAngle.GetBeta(), YAxis); | |
431 | + CalcRotatingMatrix(rotatingMatrixGamma, inv*eularAngle.GetGamma(), ZAxis); | |
432 | + | |
433 | + double temp1[3][3]; | |
434 | + for(int i=0; i<3; i++){ | |
435 | + for(int j=0; j<3; j++){ | |
436 | + temp1[i][j] = 0.0; | |
437 | + for(int k=0; k<3; k++){ | |
438 | + if(rotatedObj == System){ | |
439 | + temp1[i][j] += rotatingMatrixBeta[i][k] * rotatingMatrixGamma[k][j]; | |
440 | + } | |
441 | + else if(rotatedObj == Frame){ | |
442 | + temp1[i][j] += rotatingMatrixBeta[i][k] * rotatingMatrixAlpha[k][j]; | |
443 | + } | |
444 | + } | |
445 | + } | |
446 | + } | |
447 | + | |
448 | + double temp2[3][3]; | |
449 | + for(int i=0; i<3; i++){ | |
450 | + for(int j=0; j<3; j++){ | |
451 | + temp2[i][j] = 0.0; | |
452 | + for(int k=0; k<3; k++){ | |
453 | + if(rotatedObj == System){ | |
454 | + temp2[i][j] += rotatingMatrixAlpha[i][k] * temp1[k][j]; | |
455 | + } | |
456 | + else if(rotatedObj == Frame){ | |
457 | + temp2[i][j] += rotatingMatrixGamma[i][k] * temp1[k][j]; | |
458 | + } | |
459 | + } | |
460 | + } | |
461 | + } | |
462 | + | |
463 | + double rotatedXyz[3]; | |
464 | + Atom* atom; | |
465 | + for(int i=0; i<this->atomVect->size(); i++){ | |
466 | + atom = (*this->atomVect)[i]; | |
467 | + for(int j=0; j<3; j++){ | |
468 | + rotatedXyz[j] = 0.0; | |
469 | + for(int k=0; k<3; k++){ | |
470 | + rotatedXyz[j] += temp2[j][k] * (atom->GetXyz()[k] - rotatingOrigin[k]); | |
471 | + } | |
472 | + } | |
473 | + for(int j=0; j<3; j++){ | |
474 | + atom->GetXyz()[j] = rotatedXyz[j] + rotatingOrigin[j]; | |
475 | + } | |
476 | + } | |
409 | 477 | } |
410 | 478 | |
411 | 479 | void Molecule::OutputRotatingConditions(RotatingType rotatingType, double* rotatingOrigin, |
@@ -14,22 +14,27 @@ THEORY | ||
14 | 14 | THEORY_END |
15 | 15 | |
16 | 16 | INERTIA |
17 | - origin 1.0 2.0 3.0 | |
17 | + origin 1.0 2.0 30.0 | |
18 | 18 | INERTIA_END |
19 | 19 | |
20 | 20 | ROTATE |
21 | 21 | type axis |
22 | 22 | //type eular_angle |
23 | - origin 1.0 2.0 3.0 | |
24 | - axis 3.0 4.0 5.0 | |
23 | + //origin 1.0 2.0 3.0 | |
24 | + origin 0.0 0.0 0.0 | |
25 | + axis 10.0 0.0 0.0 | |
25 | 26 | angle 30 |
26 | - angles 15 25 35 | |
27 | + //angles 15 25 35 | |
27 | 28 | ROTATE_END |
28 | 29 | |
29 | 30 | TRANSLATE |
30 | 31 | //difference 100.0 200.0 300.0 |
31 | 32 | TRANSLATE_END |
32 | 33 | |
34 | +// s | |
35 | +GEOMETRY | |
36 | + S 0.0 0.0 1.0 | |
37 | +GEOMETRY_END | |
33 | 38 | |
34 | 39 | |
35 | 40 | //metane |
@@ -61,11 +66,11 @@ TRANSLATE_END | ||
61 | 66 | //GEOMETRY_END |
62 | 67 | |
63 | 68 | // sh2 |
64 | -GEOMETRY | |
65 | - S -0.559299 0.471698 0.000000 | |
66 | - H 0.750701 0.471698 0.000000 | |
67 | - H -0.996586 1.706558 0.000000 | |
68 | -GEOMETRY_END | |
69 | +//GEOMETRY | |
70 | +// S -0.559299 0.471698 0.000000 | |
71 | +// H 0.750701 0.471698 0.000000 | |
72 | +// H -0.996586 1.706558 0.000000 | |
73 | +//GEOMETRY_END | |
69 | 74 | |
70 | 75 | // benzene |
71 | 76 | //GEOMETRY |