• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão8e1b5afb7d3da25153560595abb9b7e062808855 (tree)
Hora2011-01-07 20:14:24
AutorMikiya Fujii <mikiya.fujii@gmai...>
CommiterMikiya Fujii

Mensagem de Log

Logic to rotate molecule is added.

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/MolDS/trunk@51 1136aad2-a195-0410-b898-f5ea1d11b9d8

Mudança Sumário

Diff

--- a/src/MolDS.cpp
+++ b/src/MolDS.cpp
@@ -13,6 +13,7 @@
1313 #undef INCLUDED_ENUMS
1414 #define RENUMSTR_BODY 1
1515 #include"base/Enums.h"
16+#include"base/MathUtilities.h"
1617 #include"base/EularAngle.h"
1718 #include"base/Molecule.h"
1819 #include"base/atoms/Atom.h"
--- a/src/base/Enums.h
+++ b/src/base/Enums.h
@@ -18,13 +18,18 @@ RENUMSTR_BEGIN( TheoryType, TheoryTypeStr )
1818 RENUMSTR( TheoryType_end, "TheoryType_end" )
1919 RENUMSTR_END()
2020
21-
2221 RENUMSTR_BEGIN( RotatingType, RotatingTypeStr )
2322 RENUMSTR( Axis, "Axis" )
2423 RENUMSTR( Eular, "EularAngle" )
2524 RENUMSTR( RotatingType_end, "RotatingType_end" )
2625 RENUMSTR_END()
2726
27+RENUMSTR_BEGIN( RotatedObjectType, RotatedObjectTypeStr )
28+ RENUMSTR( System, "System" )
29+ RENUMSTR( Frame, "Frame" )
30+ RENUMSTR( RotatedObjectType_end, "RotatedObjectType_end" )
31+RENUMSTR_END()
32+
2833 RENUMSTR_BEGIN( ShellType, ShellTypeStr )
2934 RENUMSTR( k, "k" )
3035 RENUMSTR( l, "l" )
@@ -32,6 +37,13 @@ RENUMSTR_BEGIN( ShellType, ShellTypeStr )
3237 RENUMSTR( ShellType_end, "ShellType_end" )
3338 RENUMSTR_END()
3439
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+
3547 RENUMSTR_BEGIN( OrbitalType, OrbitalTypeStr )
3648 RENUMSTR( s, "s" )
3749 RENUMSTR( py, "py" )
--- a/src/base/MathUtilities.h
+++ b/src/base/MathUtilities.h
@@ -68,6 +68,57 @@ template <typename T> T min(T a, T b){
6868 }
6969 }
7070
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+
71122
72123 }
73124 #endif
--- a/src/base/Molecule.h
+++ b/src/base/Molecule.h
@@ -29,7 +29,6 @@ public:
2929 void OutputConfiguration();
3030 void CalcPrincipalAxes();
3131 void Rotate();
32- void Rotate(EularAngle eularAngle);
3332 void Translate();
3433 private:
3534 vector<Atom*>* atomVect;
@@ -39,6 +38,7 @@ private:
3938 int totalNumberValenceElectrons;
4039 void CalcInertiaTensor(double** inertiaTensor, double* inertiaTensorOrigin);
4140 void FreeInertiaTensorMoments(double** inertiaTensor, double* inertiaMoments);
41+ void Rotate(EularAngle eularAngle, double* rotatingOrigin, RotatedObjectType rotatedObj);
4242 void OutputPrincipalAxes(double** inertiaTensor, double* inertiaMoments);
4343 void OutputInertiaTensorOrigin(double* inertiaTensorOrigin);
4444 void OutputRotatingConditions(RotatingType rotatingType, double* rotatingOrigin,
@@ -380,9 +380,9 @@ void Molecule::Rotate(){
380380 }
381381 double rotatingOrigin[3] = {this->xyzCOM[0], this->xyzCOM[1], this->xyzCOM[2]};
382382 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];
386386 }
387387
388388 RotatingType rotatingType = Parameters::GetInstance()->GetRotatingType();
@@ -396,16 +396,84 @@ void Molecule::Rotate(){
396396
397397 // rotate
398398 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);
399406 }
400407 else if(rotatingType == Eular){
401- this->Rotate(rotatingEularAngles);
408+ this->Rotate(rotatingEularAngles, rotatingOrigin, System);
402409 }
403-
410+
411+ this->OutputConfiguration();
404412 cout << this->messageDoneRotate;
405413 }
406414
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+ }
409477 }
410478
411479 void Molecule::OutputRotatingConditions(RotatingType rotatingType, double* rotatingOrigin,
--- a/src/input.in
+++ b/src/input.in
@@ -14,22 +14,27 @@ THEORY
1414 THEORY_END
1515
1616 INERTIA
17- origin 1.0 2.0 3.0
17+ origin 1.0 2.0 30.0
1818 INERTIA_END
1919
2020 ROTATE
2121 type axis
2222 //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
2526 angle 30
26- angles 15 25 35
27+ //angles 15 25 35
2728 ROTATE_END
2829
2930 TRANSLATE
3031 //difference 100.0 200.0 300.0
3132 TRANSLATE_END
3233
34+// s
35+GEOMETRY
36+ S 0.0 0.0 1.0
37+GEOMETRY_END
3338
3439
3540 //metane
@@ -61,11 +66,11 @@ TRANSLATE_END
6166 //GEOMETRY_END
6267
6368 // 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
6974
7075 // benzene
7176 //GEOMETRY