修订版 | a4c877c5b378cf4244531dffe42910db615ca627 (tree) |
---|---|
时间 | 2011-01-06 20:30:44 |
作者 | Mikiya Fujii <mikiya.fujii@gmai...> |
Commiter | Mikiya Fujii |
Logic for translating molecule is added.
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/MolDS/trunk@41 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -75,4 +75,23 @@ Rotate Molecule: | ||
75 | 75 | ROTATE_END |
76 | 76 | |
77 | 77 | |
78 | +Translate Molecule: | |
79 | + Write "translate" in theory-directive. | |
80 | + | |
81 | + E.g. | |
82 | + THEORY | |
83 | + translate | |
84 | + THEORY_END | |
85 | + | |
86 | + -options | |
87 | + "difference" indicates difference for the translation in angstrom unit. | |
88 | + This option is written in translate-directive. | |
89 | + Default values are 0, 0, and 0. | |
90 | + | |
91 | + E.g. | |
92 | + TRANSLATE | |
93 | + difference 12 30 45 | |
94 | + TRANSLATE_END | |
95 | + | |
96 | + | |
78 | 97 |
@@ -120,6 +120,18 @@ int main(){ | ||
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | + // Translate molecule | |
124 | + else if(Parameters::GetInstance()->GetCurrentTheory() == Translate && runingNormally){ | |
125 | + try{ | |
126 | + molecule->Translate(); | |
127 | + } | |
128 | + catch(MolDSException ex){ | |
129 | + cout << ex.what() << endl; | |
130 | + runingNormally = false; | |
131 | + } | |
132 | + | |
133 | + } | |
134 | + | |
123 | 135 | // Rotate molecule |
124 | 136 | else if(Parameters::GetInstance()->GetCurrentTheory() == Rotate && runingNormally){ |
125 | 137 | try{ |
@@ -12,6 +12,7 @@ RENUMSTR_BEGIN( TheoryType, TheoryTypeStr ) | ||
12 | 12 | RENUMSTR( INDO, "INDO" ) |
13 | 13 | RENUMSTR( ZINDOS, "ZINDO/S" ) |
14 | 14 | RENUMSTR( PrincipalAxes, "PrincipalAxes" ) |
15 | + RENUMSTR( Translate, "Translate" ) | |
15 | 16 | RENUMSTR( Rotate, "Rotate" ) |
16 | 17 | RENUMSTR( NONE, "NONE" ) |
17 | 18 | RENUMSTR( TheoryType_end, "TheoryType_end" ) |
@@ -46,6 +46,7 @@ private: | ||
46 | 46 | string stringTheoryINDO; |
47 | 47 | string stringTheoryZINDOS; |
48 | 48 | string stringTheoryPrincipalAxes; |
49 | + string stringTheoryTranslate; | |
49 | 50 | string stringTheoryRotate; |
50 | 51 | string stringTheoryNONE; |
51 | 52 | string stringGeometry; |
@@ -66,6 +67,9 @@ private: | ||
66 | 67 | string stringRotatingType; |
67 | 68 | string stringRotatingTypeAxis; |
68 | 69 | string stringRotatingTypeEularAngle; |
70 | + string stringTranslate; | |
71 | + string stringTranslateEnd; | |
72 | + string stringTranslatingDifference; | |
69 | 73 | void CalcMolecularBasics(Molecule* molecule); |
70 | 74 | void OutputMolecularBasics(Molecule* molecule); |
71 | 75 | void OutputScfConditions(); |
@@ -91,6 +95,7 @@ InputParser::InputParser(){ | ||
91 | 95 | this->stringTheoryINDO = "indo"; |
92 | 96 | this->stringTheoryZINDOS = "zindo/s"; |
93 | 97 | this->stringTheoryPrincipalAxes = "principal_axes"; |
98 | + this->stringTheoryTranslate = "translate"; | |
94 | 99 | this->stringTheoryRotate = "rotate"; |
95 | 100 | this->stringTheoryNONE = "none"; |
96 | 101 | this->stringGeometry = "geometry"; |
@@ -113,6 +118,9 @@ InputParser::InputParser(){ | ||
113 | 118 | this->stringRotatingType = "type"; |
114 | 119 | this->stringRotatingTypeAxis = "axis"; |
115 | 120 | this->stringRotatingTypeEularAngle = "eular_angle"; |
121 | + this->stringTranslate = "translate"; | |
122 | + this->stringTranslateEnd = "translate_end"; | |
123 | + this->stringTranslatingDifference = "difference"; | |
116 | 124 | } |
117 | 125 | |
118 | 126 | InputParser::~InputParser(){ |
@@ -241,6 +249,23 @@ void InputParser::Parse(Molecule* molecule){ | ||
241 | 249 | i = j; |
242 | 250 | } |
243 | 251 | |
252 | + // translating condition | |
253 | + if(inputTerms[i].compare(this->stringTranslate) == 0){ | |
254 | + int j=i+1; | |
255 | + while(inputTerms[j].compare(this->stringTranslateEnd) != 0){ | |
256 | + // origin | |
257 | + if(inputTerms[j].compare(this->stringTranslatingDifference) == 0){ | |
258 | + double x = atof(inputTerms[j+1].c_str()) * Parameters::GetInstance()->GetAngstrom2AU(); | |
259 | + double y = atof(inputTerms[j+2].c_str()) * Parameters::GetInstance()->GetAngstrom2AU(); | |
260 | + double z = atof(inputTerms[j+3].c_str()) * Parameters::GetInstance()->GetAngstrom2AU(); | |
261 | + molecule->SetTranslatingDifference(x, y, z); | |
262 | + j+=3; | |
263 | + } | |
264 | + j++; | |
265 | + } | |
266 | + i = j; | |
267 | + } | |
268 | + | |
244 | 269 | // rotating condition |
245 | 270 | if(inputTerms[i].compare(this->stringRotate) == 0){ |
246 | 271 | int j=i+1; |
@@ -315,6 +340,11 @@ void InputParser::Parse(Molecule* molecule){ | ||
315 | 340 | Parameters::GetInstance()->SetCurrentTheory(PrincipalAxes); |
316 | 341 | } |
317 | 342 | |
343 | + // Translate | |
344 | + else if(inputTerms[j].compare(this->stringTheoryTranslate) == 0){ | |
345 | + Parameters::GetInstance()->SetCurrentTheory(Translate); | |
346 | + } | |
347 | + | |
318 | 348 | // Rotate |
319 | 349 | else if(inputTerms[j].compare(this->stringTheoryRotate) == 0){ |
320 | 350 | Parameters::GetInstance()->SetCurrentTheory(Rotate); |
@@ -35,6 +35,8 @@ public: | ||
35 | 35 | void SetRotatingAngle(double angle); |
36 | 36 | void SetRotatingEularAngles(double alpha, double beta, double gamma); |
37 | 37 | void SetRotatingType(RotatingType rotatingType); |
38 | + void SetTranslatingDifference(double x, double y, double z); | |
39 | + void Translate(); | |
38 | 40 | private: |
39 | 41 | vector<Atom*>* atomVect; |
40 | 42 | double* COMXyz; |
@@ -42,6 +44,7 @@ private: | ||
42 | 44 | double* rotatingOrigin; |
43 | 45 | double* rotatingAxis; |
44 | 46 | double rotatingAngle; |
47 | + double* translatingDifference; | |
45 | 48 | EularAngle* rotatingEularAngles; |
46 | 49 | RotatingType rotatingType; |
47 | 50 | bool wasCalculatedCOMXyz; |
@@ -52,6 +55,7 @@ private: | ||
52 | 55 | void OutputPrincipalAxes(double** inertiaTensor, double* inertiaMoments); |
53 | 56 | void OutputInertiaTensorOrigin(); |
54 | 57 | void OutputRotatingConditions(); |
58 | + void OutputTranslatingConditions(); | |
55 | 59 | string messageTotalNumberAOs; |
56 | 60 | string messageTotalNumberAtoms; |
57 | 61 | string messageTotalNumberValenceElectrons; |
@@ -81,6 +85,11 @@ private: | ||
81 | 85 | string messageRotatingType; |
82 | 86 | string messageRotatingEularAngles; |
83 | 87 | string messageRotatingEularAnglesTitle; |
88 | + string messageStartTranslate; | |
89 | + string messageDoneTranslate; | |
90 | + string messageTranslatingDifference; | |
91 | + string messageTranslatingDifferenceTitleAU; | |
92 | + string messageTranslatingDifferenceTitleAng; | |
84 | 93 | }; |
85 | 94 | |
86 | 95 | Molecule::Molecule(){ |
@@ -102,8 +111,8 @@ Molecule::Molecule(){ | ||
102 | 111 | this->messageCOM = "\tCenter of Mass:\n"; |
103 | 112 | this->messageCOMTitleAU = "\t\t| x [a.u.] | y[a.u.] | z[a.u.] |\n"; |
104 | 113 | this->messageCOMTitleAng = "\t\t| x [angst.] | y[angst.] | z[angst.] |\n"; |
105 | - this->messageStartPrincipalAxes = "********** START: Principal Axes Analysis **********\n"; | |
106 | - this->messageDonePrincipalAxes = "********** DONE: Principal Axes Analysis ***********\n\n\n"; | |
114 | + this->messageStartPrincipalAxes = "********** START: Principal Axes of Inertia **********\n"; | |
115 | + this->messageDonePrincipalAxes = "********** DONE: Principal Axes of Inertia ***********\n\n\n"; | |
107 | 116 | this->messagePrincipalAxes = "\tPrincipal Axes:\n"; |
108 | 117 | this->messagePrincipalAxesTitleAU = "\t\t| inertia moments [a.u.] | x [a.u.] | y[a.u.] | z[a.u.] | (normalized)\n"; |
109 | 118 | this->messagePrincipalAxesTitleAng = "\t\t| inertia moments [g*angust**2/mol] | x [angst.] | y[angst.] | z[angst.] | (not normalized)\n"; |
@@ -122,6 +131,11 @@ Molecule::Molecule(){ | ||
122 | 131 | this->messageRotatingType = "\tType: "; |
123 | 132 | this->messageRotatingEularAngles = "\tEular Angles:\n"; |
124 | 133 | this->messageRotatingEularAnglesTitle = "\t\t| alpha[degree] | beta[degree] | gamma[degree] |\n"; |
134 | + this->messageStartTranslate = "********** START: Translate molecule **********\n"; | |
135 | + this->messageDoneTranslate = "********** DONE: Translate molecule ***********\n\n\n"; | |
136 | + this->messageTranslatingDifference = "\tTranslating Difference:\n"; | |
137 | + this->messageTranslatingDifferenceTitleAU = "\t\t| x [a.u.] | y[a.u.] | z[a.u.] |\n"; | |
138 | + this->messageTranslatingDifferenceTitleAng = "\t\t| x [angst.] | y[angst.] | z[angst.] |\n"; | |
125 | 139 | } |
126 | 140 | |
127 | 141 | Molecule::~Molecule(){ |
@@ -159,6 +173,11 @@ Molecule::~Molecule(){ | ||
159 | 173 | this->rotatingEularAngles = NULL; |
160 | 174 | //cout << "rotatingEularAngles deleted\n"; |
161 | 175 | } |
176 | + if(this->translatingDifference != NULL){ | |
177 | + MallocerFreer::GetInstance()->FreeDoubleMatrix1d(this->translatingDifference); | |
178 | + this->translatingDifference = NULL; | |
179 | + //cout << "translatingDifference deleted\n"; | |
180 | + } | |
162 | 181 | } |
163 | 182 | |
164 | 183 | vector<Atom*>* Molecule::GetAtomVect(){ |
@@ -180,7 +199,7 @@ void Molecule::CalcCOMXyz(){ | ||
180 | 199 | double atomicMass; |
181 | 200 | |
182 | 201 | for(int j=0; j<3; j++){ |
183 | - this->COMXyz[j] += 0.0; | |
202 | + this->COMXyz[j] = 0.0; | |
184 | 203 | } |
185 | 204 | |
186 | 205 | for(int i=0; i<this->atomVect->size(); i++){ |
@@ -514,6 +533,62 @@ void Molecule::OutputRotatingConditions(){ | ||
514 | 533 | this->rotatingEularAngles->GetGamma()/degree2Radian); |
515 | 534 | } |
516 | 535 | |
536 | +} | |
537 | + | |
538 | +void Molecule::SetTranslatingDifference(double x, double y, double z){ | |
539 | + if(this->translatingDifference == NULL){ | |
540 | + this->translatingDifference = MallocerFreer::GetInstance()->MallocDoubleMatrix1d(3); | |
541 | + } | |
542 | + | |
543 | + this->translatingDifference[0] = x; | |
544 | + this->translatingDifference[1] = y; | |
545 | + this->translatingDifference[2] = z; | |
546 | + | |
547 | +} | |
548 | + | |
549 | +void Molecule::Translate(){ | |
550 | + | |
551 | + cout << this->messageStartTranslate; | |
552 | + | |
553 | + if(this->translatingDifference == NULL){ | |
554 | + this->SetTranslatingDifference(0.0, 0.0, 0.0); | |
555 | + } | |
556 | + | |
557 | + | |
558 | + this->OutputTranslatingConditions(); | |
559 | + | |
560 | + Atom* atom; | |
561 | + for(int i=0; i<this->atomVect->size(); i++){ | |
562 | + atom = (*this->atomVect)[i]; | |
563 | + atom->GetXyz()[0] += this->translatingDifference[0]; | |
564 | + atom->GetXyz()[1] += this->translatingDifference[1]; | |
565 | + atom->GetXyz()[2] += this->translatingDifference[2]; | |
566 | + } | |
567 | + | |
568 | + this->wasCalculatedCOMXyz = false; | |
569 | + this->CalcCOMXyz(); | |
570 | + | |
571 | + this->OutputConfiguration(); | |
572 | + this->OutputCOMXyz(); | |
573 | + | |
574 | + cout << this->messageDoneTranslate; | |
575 | +} | |
576 | + | |
577 | +void Molecule::OutputTranslatingConditions(){ | |
578 | + | |
579 | + double angst2AU = Parameters::GetInstance()->GetAngstrom2AU(); | |
580 | + | |
581 | + // rotating origin | |
582 | + cout << this->messageTranslatingDifference; | |
583 | + cout << this->messageTranslatingDifferenceTitleAng; | |
584 | + printf("\t\t%e\t%e\t%e\n\n",this->translatingDifference[0]/angst2AU, | |
585 | + this->translatingDifference[1]/angst2AU, | |
586 | + this->translatingDifference[2]/angst2AU); | |
587 | + | |
588 | + cout << this->messageTranslatingDifferenceTitleAU; | |
589 | + printf("\t\t%e\t%e\t%e\n\n",this->translatingDifference[0], | |
590 | + this->translatingDifference[1], | |
591 | + this->translatingDifference[2]); | |
517 | 592 | |
518 | 593 | } |
519 | 594 |
@@ -8,7 +8,8 @@ THEORY | ||
8 | 8 | //indo |
9 | 9 | //zindo/s |
10 | 10 | //none |
11 | - principal_axes | |
11 | + //principal_axes | |
12 | + translate | |
12 | 13 | //rotate |
13 | 14 | THEORY_END |
14 | 15 |
@@ -17,14 +18,20 @@ INERTIA | ||
17 | 18 | INERTIA_END |
18 | 19 | |
19 | 20 | ROTATE |
20 | - type axis | |
21 | + //type axis | |
21 | 22 | //type eular_angle |
22 | - origin 1.0 2.0 3.0 | |
23 | - axis 3.0 4.0 5.0 | |
24 | - angle 30 | |
25 | - angles 15 25 35 | |
23 | + //origin 1.0 2.0 3.0 | |
24 | + //axis 3.0 4.0 5.0 | |
25 | + //angle 30 | |
26 | + //angles 15 25 35 | |
26 | 27 | ROTATE_END |
27 | 28 | |
29 | +TRANSLATE | |
30 | + //difference 100.0 200.0 300.0 | |
31 | +TRANSLATE_END | |
32 | + | |
33 | + | |
34 | + | |
28 | 35 | //metane |
29 | 36 | //GEOMETRY |
30 | 37 | // C -0.37687006 0.95490165 0.00000000 |