| 1 | /*
 | 
|---|
| 2 |  * PairCorrelationAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 9, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp"
 | 
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 12 | #include "analysis_correlation.hpp"
 | 
|---|
| 13 | #include "boundary.hpp"
 | 
|---|
| 14 | #include "linkedcell.hpp"
 | 
|---|
| 15 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 16 | #include "Helpers/Log.hpp"
 | 
|---|
| 17 | #include "element.hpp"
 | 
|---|
| 18 | #include "molecule.hpp"
 | 
|---|
| 19 | #include "periodentafel.hpp"
 | 
|---|
| 20 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 21 | #include "World.hpp"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include <iostream>
 | 
|---|
| 24 | #include <string>
 | 
|---|
| 25 | 
 | 
|---|
| 26 | using namespace std;
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| 29 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 30 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| 31 | 
 | 
|---|
| 32 | const char AnalysisPairCorrelationAction::NAME[] = "pair-correlation";
 | 
|---|
| 33 | 
 | 
|---|
| 34 | AnalysisPairCorrelationAction::AnalysisPairCorrelationAction() :
 | 
|---|
| 35 |   Action(NAME)
 | 
|---|
| 36 | {}
 | 
|---|
| 37 | 
 | 
|---|
| 38 | AnalysisPairCorrelationAction::~AnalysisPairCorrelationAction()
 | 
|---|
| 39 | {}
 | 
|---|
| 40 | 
 | 
|---|
| 41 | void AnalysisPairCorrelation(std::vector< element *> &elements, double BinStart, double BinWidth, double BinEnd, string &outputname, string &binoutputname, bool periodic) {
 | 
|---|
| 42 |   ValueStorage::getInstance().setCurrentValue("elements", elements);
 | 
|---|
| 43 |   ValueStorage::getInstance().setCurrentValue("bin-start", BinStart);
 | 
|---|
| 44 |   ValueStorage::getInstance().setCurrentValue("bin-width", BinWidth);
 | 
|---|
| 45 |   ValueStorage::getInstance().setCurrentValue("bin-end", BinEnd);
 | 
|---|
| 46 |   ValueStorage::getInstance().setCurrentValue("output-file", outputname);
 | 
|---|
| 47 |   ValueStorage::getInstance().setCurrentValue("bin-output-file", binoutputname);
 | 
|---|
| 48 |   ValueStorage::getInstance().setCurrentValue("periodic", periodic);
 | 
|---|
| 49 |   ActionRegistry::getInstance().getActionByName(AnalysisPairCorrelationAction::NAME)->call(Action::NonInteractive);
 | 
|---|
| 50 | };
 | 
|---|
| 51 | 
 | 
|---|
| 52 | 
 | 
|---|
| 53 | Dialog* AnalysisPairCorrelationAction::fillDialog(Dialog* dialog) {
 | 
|---|
| 54 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
 | 
|---|
| 57 |   dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start"));
 | 
|---|
| 58 |   dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width"));
 | 
|---|
| 59 |   dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end"));
 | 
|---|
| 60 |   dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file"));
 | 
|---|
| 61 |   dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file"));
 | 
|---|
| 62 |   dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
 | 
|---|
| 63 | 
 | 
|---|
| 64 |   return dialog;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | Action::state_ptr AnalysisPairCorrelationAction::performCall() {
 | 
|---|
| 68 |   int ranges[3] = {1, 1, 1};
 | 
|---|
| 69 |   double BinEnd = 0.;
 | 
|---|
| 70 |   double BinStart = 0.;
 | 
|---|
| 71 |   double BinWidth = 0.;
 | 
|---|
| 72 |   string outputname;
 | 
|---|
| 73 |   string binoutputname;
 | 
|---|
| 74 |   bool periodic;
 | 
|---|
| 75 |   ofstream output;
 | 
|---|
| 76 |   ofstream binoutput;
 | 
|---|
| 77 |   std::vector<const element *> elements;
 | 
|---|
| 78 |   string type;
 | 
|---|
| 79 |   Vector Point;
 | 
|---|
| 80 |   BinPairMap *binmap = NULL;
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   // obtain information
 | 
|---|
| 83 |   ValueStorage::getInstance().queryCurrentValue("elements", elements);
 | 
|---|
| 84 |   ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
 | 
|---|
| 85 |   ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
 | 
|---|
| 86 |   ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
 | 
|---|
| 87 |   ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
 | 
|---|
| 88 |   ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
 | 
|---|
| 89 |   ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
 | 
|---|
| 90 | 
 | 
|---|
| 91 |   // execute action
 | 
|---|
| 92 |   output.open(outputname.c_str());
 | 
|---|
| 93 |   binoutput.open(binoutputname.c_str());
 | 
|---|
| 94 |   PairCorrelationMap *correlationmap = NULL;
 | 
|---|
| 95 |   std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| 96 |   if (periodic)
 | 
|---|
| 97 |     correlationmap = PeriodicPairCorrelation(molecules, elements, ranges);
 | 
|---|
| 98 |   else
 | 
|---|
| 99 |     correlationmap = PairCorrelation(molecules, elements);
 | 
|---|
| 100 |   OutputPairCorrelation(&output, correlationmap);
 | 
|---|
| 101 |   binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
 | 
|---|
| 102 |   OutputCorrelation ( &binoutput, binmap );
 | 
|---|
| 103 |   delete(binmap);
 | 
|---|
| 104 |   delete(correlationmap);
 | 
|---|
| 105 |   output.close();
 | 
|---|
| 106 |   binoutput.close();
 | 
|---|
| 107 |   return Action::success;
 | 
|---|
| 108 | }
 | 
|---|
| 109 | 
 | 
|---|
| 110 | Action::state_ptr AnalysisPairCorrelationAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 111 |   return Action::success;
 | 
|---|
| 112 | }
 | 
|---|
| 113 | 
 | 
|---|
| 114 | Action::state_ptr AnalysisPairCorrelationAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 115 |   return Action::success;
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | bool AnalysisPairCorrelationAction::canUndo() {
 | 
|---|
| 119 |   return true;
 | 
|---|
| 120 | }
 | 
|---|
| 121 | 
 | 
|---|
| 122 | bool AnalysisPairCorrelationAction::shouldUndo() {
 | 
|---|
| 123 |   return true;
 | 
|---|
| 124 | }
 | 
|---|
| 125 | 
 | 
|---|
| 126 | const string AnalysisPairCorrelationAction::getName() {
 | 
|---|
| 127 |   return NAME;
 | 
|---|
| 128 | }
 | 
|---|