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