| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [97ebf8] | 8 | /*
 | 
|---|
 | 9 |  * PrincipalAxisSystemAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: May 12, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [112b09] | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
| [952f38] | 22 | #include "Helpers/Log.hpp"
 | 
|---|
 | 23 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [cca9ef] | 24 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [6e5084] | 25 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 26 | #include "element.hpp"
 | 
|---|
 | 27 | #include "molecule.hpp"
 | 
|---|
| [97ebf8] | 28 | 
 | 
|---|
 | 29 | #include <iostream>
 | 
|---|
 | 30 | #include <string>
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | using namespace std;
 | 
|---|
 | 33 | 
 | 
|---|
| [9ee38b] | 34 | #include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
 | 
|---|
| [ca1ba5] | 35 | 
 | 
|---|
| [9ee38b] | 36 | // and construct the stuff
 | 
|---|
 | 37 | #include "PrincipalAxisSystemAction.def"
 | 
|---|
 | 38 | #include "Action_impl_pre.hpp"
 | 
|---|
| [ca1ba5] | 39 | 
 | 
|---|
| [9ee38b] | 40 | /** =========== define the function ====================== */
 | 
|---|
| [ca1ba5] | 41 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performCall() {
 | 
|---|
| [cca9ef] | 42 |   RealSpaceMatrix InertiaTensor;
 | 
|---|
| [97ebf8] | 43 | 
 | 
|---|
| [ca1ba5] | 44 |   DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
 | 
|---|
| [b76394] | 45 |   for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
 | 
|---|
 | 46 |     molecule *mol = iter->second;
 | 
|---|
| [6e5084] | 47 |     Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |     // reset inertia tensor
 | 
|---|
| [9eb7580] | 50 |     InertiaTensor.setZero();
 | 
|---|
| [6e5084] | 51 | 
 | 
|---|
 | 52 |     // sum up inertia tensor
 | 
|---|
 | 53 |     for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
 | 
|---|
| [8f4df1] | 54 |       Vector x = (*iter)->getPosition();
 | 
|---|
| [6e5084] | 55 |       x -= *CenterOfGravity;
 | 
|---|
| [83f176] | 56 |       const double mass = (*iter)->getType()->getMass();
 | 
|---|
| [8f4df1] | 57 |       InertiaTensor.at(0,0) += mass*(x[1]*x[1] + x[2]*x[2]);
 | 
|---|
 | 58 |       InertiaTensor.at(0,1) += mass*(-x[0]*x[1]);
 | 
|---|
 | 59 |       InertiaTensor.at(0,2) += mass*(-x[0]*x[2]);
 | 
|---|
 | 60 |       InertiaTensor.at(1,0) += mass*(-x[1]*x[0]);
 | 
|---|
 | 61 |       InertiaTensor.at(1,1) += mass*(x[0]*x[0] + x[2]*x[2]);
 | 
|---|
 | 62 |       InertiaTensor.at(1,2) += mass*(-x[1]*x[2]);
 | 
|---|
 | 63 |       InertiaTensor.at(2,0) += mass*(-x[2]*x[0]);
 | 
|---|
 | 64 |       InertiaTensor.at(2,1) += mass*(-x[2]*x[1]);
 | 
|---|
 | 65 |       InertiaTensor.at(2,2) += mass*(x[0]*x[0] + x[1]*x[1]);
 | 
|---|
| [6e5084] | 66 |     }
 | 
|---|
 | 67 |     // print InertiaTensor for debugging
 | 
|---|
 | 68 |     DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << InertiaTensor << endl);
 | 
|---|
| [b76394] | 69 |   }
 | 
|---|
| [ca1ba5] | 70 |   return Action::success;
 | 
|---|
| [97ebf8] | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| [ca1ba5] | 74 |   return Action::success;
 | 
|---|
| [97ebf8] | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performRedo(Action::state_ptr _state){
 | 
|---|
| [ca1ba5] | 78 |   return Action::success;
 | 
|---|
| [97ebf8] | 79 | }
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | bool AnalysisPrincipalAxisSystemAction::canUndo() {
 | 
|---|
| [ca1ba5] | 82 |   return true;
 | 
|---|
| [97ebf8] | 83 | }
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | bool AnalysisPrincipalAxisSystemAction::shouldUndo() {
 | 
|---|
| [ca1ba5] | 86 |   return true;
 | 
|---|
| [97ebf8] | 87 | }
 | 
|---|
| [9ee38b] | 88 | /** =========== end of function ====================== */
 | 
|---|