| [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 | 
 | 
|---|
| [d02e07] | 8 | /*
 | 
|---|
 | 9 |  * PointCorrelationAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: May 9, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [d02e07] | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "Actions/AnalysisAction/PointCorrelationAction.hpp"
 | 
|---|
| [0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [d02e07] | 24 | #include "analysis_correlation.hpp"
 | 
|---|
 | 25 | #include "boundary.hpp"
 | 
|---|
 | 26 | #include "linkedcell.hpp"
 | 
|---|
| [952f38] | 27 | #include "Helpers/Verbose.hpp"
 | 
|---|
 | 28 | #include "Helpers/Log.hpp"
 | 
|---|
| [d02e07] | 29 | #include "element.hpp"
 | 
|---|
 | 30 | #include "molecule.hpp"
 | 
|---|
 | 31 | #include "periodentafel.hpp"
 | 
|---|
| [57f243] | 32 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [d02e07] | 33 | #include "World.hpp"
 | 
|---|
 | 34 | 
 | 
|---|
| [146cff2] | 35 | #include <cmath>
 | 
|---|
| [d02e07] | 36 | #include <iostream>
 | 
|---|
 | 37 | #include <string>
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | using namespace std;
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 42 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [861874] | 43 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [d02e07] | 44 | 
 | 
|---|
 | 45 | const char AnalysisPointCorrelationAction::NAME[] = "point-correlation";
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | AnalysisPointCorrelationAction::AnalysisPointCorrelationAction() :
 | 
|---|
 | 48 |   Action(NAME)
 | 
|---|
 | 49 | {}
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | AnalysisPointCorrelationAction::~AnalysisPointCorrelationAction()
 | 
|---|
 | 52 | {}
 | 
|---|
 | 53 | 
 | 
|---|
| [b31cfa] | 54 | void AnalysisPointCorrelation(std::vector< element *> &elements, Vector &position, double BinStart, double BinWidth, double BinEnd, string &outputname, string &binoutputname, bool periodic) {
 | 
|---|
 | 55 |   ValueStorage::getInstance().setCurrentValue("elements", elements);
 | 
|---|
 | 56 |   ValueStorage::getInstance().setCurrentValue("position", position);
 | 
|---|
 | 57 |   ValueStorage::getInstance().setCurrentValue("bin-start", BinStart);
 | 
|---|
 | 58 |   ValueStorage::getInstance().setCurrentValue("bin-width", BinWidth);
 | 
|---|
 | 59 |   ValueStorage::getInstance().setCurrentValue("bin-end", BinEnd);
 | 
|---|
 | 60 |   ValueStorage::getInstance().setCurrentValue("output-file", outputname);
 | 
|---|
 | 61 |   ValueStorage::getInstance().setCurrentValue("bin-output-file", binoutputname);
 | 
|---|
 | 62 |   ValueStorage::getInstance().setCurrentValue("periodic", periodic);
 | 
|---|
 | 63 |   ActionRegistry::getInstance().getActionByName(AnalysisPointCorrelationAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 64 | };
 | 
|---|
 | 65 | 
 | 
|---|
| [047878] | 66 | Dialog* AnalysisPointCorrelationAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 67 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [d02e07] | 68 | 
 | 
|---|
| [9d33ba] | 69 |   dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
 | 
|---|
| [e65de8] | 70 |   dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
 | 
|---|
| [9d33ba] | 71 |   dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start"));
 | 
|---|
 | 72 |   dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width"));
 | 
|---|
 | 73 |   dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end"));
 | 
|---|
 | 74 |   dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file"));
 | 
|---|
 | 75 |   dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file"));
 | 
|---|
 | 76 |   dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
 | 
|---|
| [d02e07] | 77 | 
 | 
|---|
 | 78 |   return dialog;
 | 
|---|
 | 79 | }
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | Action::state_ptr AnalysisPointCorrelationAction::performCall() {
 | 
|---|
 | 82 |   int ranges[3] = {1, 1, 1};
 | 
|---|
 | 83 |   double BinEnd = 0.;
 | 
|---|
 | 84 |   double BinStart = 0.;
 | 
|---|
 | 85 |   double BinWidth = 0.;
 | 
|---|
 | 86 |   string outputname;
 | 
|---|
 | 87 |   string binoutputname;
 | 
|---|
 | 88 |   bool periodic;
 | 
|---|
 | 89 |   ofstream output;
 | 
|---|
 | 90 |   ofstream binoutput;
 | 
|---|
| [e5c0a1] | 91 |   std::vector<const element *> elements;
 | 
|---|
| [d02e07] | 92 |   string type;
 | 
|---|
 | 93 |   Vector Point;
 | 
|---|
 | 94 |   BinPairMap *binmap = NULL;
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |   // obtain information
 | 
|---|
| [9d33ba] | 97 |   ValueStorage::getInstance().queryCurrentValue("position", Point);
 | 
|---|
 | 98 |   ValueStorage::getInstance().queryCurrentValue("elements", elements);
 | 
|---|
 | 99 |   ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
 | 
|---|
 | 100 |   ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
 | 
|---|
 | 101 |   ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
 | 
|---|
 | 102 |   ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
 | 
|---|
 | 103 |   ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
 | 
|---|
 | 104 |   ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
 | 
|---|
| [d02e07] | 105 | 
 | 
|---|
 | 106 |   // execute action
 | 
|---|
 | 107 |   output.open(outputname.c_str());
 | 
|---|
 | 108 |   binoutput.open(binoutputname.c_str());
 | 
|---|
 | 109 |   cout << "Point to correlate to is  " << Point << endl;
 | 
|---|
 | 110 |   CorrelationToPointMap *correlationmap = NULL;
 | 
|---|
| [e5c0a1] | 111 |   for(std::vector<const element *>::iterator iter = elements.begin(); iter != elements.end(); ++iter)
 | 
|---|
| [2fe971] | 112 |     cout << "element is " << (*iter)->getSymbol() << endl;
 | 
|---|
| [e65de8] | 113 |   std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| [d02e07] | 114 |   if (periodic)
 | 
|---|
 | 115 |     correlationmap  = PeriodicCorrelationToPoint(molecules, elements, &Point, ranges);
 | 
|---|
 | 116 |   else
 | 
|---|
 | 117 |     correlationmap = CorrelationToPoint(molecules, elements, &Point);
 | 
|---|
 | 118 |   OutputCorrelationToPoint(&output, correlationmap);
 | 
|---|
 | 119 |   binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
 | 
|---|
 | 120 |   OutputCorrelation ( &binoutput, binmap );
 | 
|---|
 | 121 |   delete(binmap);
 | 
|---|
 | 122 |   delete(correlationmap);
 | 
|---|
 | 123 |   output.close();
 | 
|---|
 | 124 |   binoutput.close();
 | 
|---|
 | 125 |   return Action::success;
 | 
|---|
 | 126 | }
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 | Action::state_ptr AnalysisPointCorrelationAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 129 |   return Action::success;
 | 
|---|
 | 130 | }
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | Action::state_ptr AnalysisPointCorrelationAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 133 |   return Action::success;
 | 
|---|
 | 134 | }
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 | bool AnalysisPointCorrelationAction::canUndo() {
 | 
|---|
 | 137 |   return true;
 | 
|---|
 | 138 | }
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | bool AnalysisPointCorrelationAction::shouldUndo() {
 | 
|---|
 | 141 |   return true;
 | 
|---|
 | 142 | }
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | const string AnalysisPointCorrelationAction::getName() {
 | 
|---|
 | 145 |   return NAME;
 | 
|---|
 | 146 | }
 | 
|---|