| 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 | 
 | 
|---|
| 8 | /*
 | 
|---|
| 9 |  * PrincipalAxisSystemAction.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: May 12, 2010
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "Helpers/Log.hpp"
 | 
|---|
| 23 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 24 | #include "LinearAlgebra/Matrix.hpp"
 | 
|---|
| 25 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 26 | #include "element.hpp"
 | 
|---|
| 27 | #include "molecule.hpp"
 | 
|---|
| 28 | 
 | 
|---|
| 29 | #include <iostream>
 | 
|---|
| 30 | #include <string>
 | 
|---|
| 31 | 
 | 
|---|
| 32 | using namespace std;
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
 | 
|---|
| 35 | 
 | 
|---|
| 36 | // and construct the stuff
 | 
|---|
| 37 | #include "PrincipalAxisSystemAction.def"
 | 
|---|
| 38 | #include "Action_impl_pre.hpp"
 | 
|---|
| 39 | 
 | 
|---|
| 40 | /** =========== define the function ====================== */
 | 
|---|
| 41 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performCall() {
 | 
|---|
| 42 |   Matrix InertiaTensor;
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
 | 
|---|
| 45 |   for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
 | 
|---|
| 46 |     molecule *mol = iter->second;
 | 
|---|
| 47 |     Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
 | 
|---|
| 48 | 
 | 
|---|
| 49 |     // reset inertia tensor
 | 
|---|
| 50 |     InertiaTensor.zero();
 | 
|---|
| 51 | 
 | 
|---|
| 52 |     // sum up inertia tensor
 | 
|---|
| 53 |     for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
 | 
|---|
| 54 |       Vector x = (*iter)->getPosition();
 | 
|---|
| 55 |       x -= *CenterOfGravity;
 | 
|---|
| 56 |       const double mass = (*iter)->getType()->getMass();
 | 
|---|
| 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]);
 | 
|---|
| 66 |     }
 | 
|---|
| 67 |     // print InertiaTensor for debugging
 | 
|---|
| 68 |     DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << InertiaTensor << endl);
 | 
|---|
| 69 |   }
 | 
|---|
| 70 |   return Action::success;
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 74 |   return Action::success;
 | 
|---|
| 75 | }
 | 
|---|
| 76 | 
 | 
|---|
| 77 | Action::state_ptr AnalysisPrincipalAxisSystemAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 78 |   return Action::success;
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | bool AnalysisPrincipalAxisSystemAction::canUndo() {
 | 
|---|
| 82 |   return true;
 | 
|---|
| 83 | }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | bool AnalysisPrincipalAxisSystemAction::shouldUndo() {
 | 
|---|
| 86 |   return true;
 | 
|---|
| 87 | }
 | 
|---|
| 88 | /** =========== end of function ====================== */
 | 
|---|