| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * PairCorrelationAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 9, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [bf3817] | 8 | // include config.h
 | 
|---|
 | 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 10 | #include <config.h>
 | 
|---|
 | 11 | #endif
 | 
|---|
 | 12 | 
 | 
|---|
| [112b09] | 13 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 14 | 
 | 
|---|
| [97ebf8] | 15 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp"
 | 
|---|
| [0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [97ebf8] | 17 | #include "analysis_correlation.hpp"
 | 
|---|
| [104524] | 18 | #include "boundary.hpp"
 | 
|---|
 | 19 | #include "linkedcell.hpp"
 | 
|---|
| [952f38] | 20 | #include "Helpers/Verbose.hpp"
 | 
|---|
 | 21 | #include "Helpers/Log.hpp"
 | 
|---|
| [97ebf8] | 22 | #include "element.hpp"
 | 
|---|
| [104524] | 23 | #include "molecule.hpp"
 | 
|---|
| [97ebf8] | 24 | #include "periodentafel.hpp"
 | 
|---|
| [57f243] | 25 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [97ebf8] | 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"
 | 
|---|
| [861874] | 35 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [97ebf8] | 36 | 
 | 
|---|
 | 37 | const char AnalysisPairCorrelationAction::NAME[] = "pair-correlation";
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | AnalysisPairCorrelationAction::AnalysisPairCorrelationAction() :
 | 
|---|
 | 40 |   Action(NAME)
 | 
|---|
 | 41 | {}
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | AnalysisPairCorrelationAction::~AnalysisPairCorrelationAction()
 | 
|---|
 | 44 | {}
 | 
|---|
 | 45 | 
 | 
|---|
| [b31cfa] | 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 | 
 | 
|---|
| [047878] | 58 | Dialog* AnalysisPairCorrelationAction::fillDialog(Dialog* dialog) {
 | 
|---|
 | 59 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [104524] | 60 | 
 | 
|---|
| [e65de8] | 61 |   dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
 | 
|---|
| [9d33ba] | 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"));
 | 
|---|
| [97ebf8] | 68 | 
 | 
|---|
| [d02e07] | 69 |   return dialog;
 | 
|---|
| [97ebf8] | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
| [d02e07] | 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;
 | 
|---|
| [e5c0a1] | 82 |   std::vector<const element *> elements;
 | 
|---|
| [d02e07] | 83 |   string type;
 | 
|---|
 | 84 |   Vector Point;
 | 
|---|
 | 85 |   BinPairMap *binmap = NULL;
 | 
|---|
| [97ebf8] | 86 | 
 | 
|---|
| [d02e07] | 87 |   // obtain information
 | 
|---|
| [9d33ba] | 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);
 | 
|---|
| [d02e07] | 95 | 
 | 
|---|
 | 96 |   // execute action
 | 
|---|
 | 97 |   output.open(outputname.c_str());
 | 
|---|
 | 98 |   binoutput.open(binoutputname.c_str());
 | 
|---|
 | 99 |   PairCorrelationMap *correlationmap = NULL;
 | 
|---|
| [e65de8] | 100 |   std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| [d02e07] | 101 |   if (periodic)
 | 
|---|
| [e65de8] | 102 |     correlationmap = PeriodicPairCorrelation(molecules, elements, ranges);
 | 
|---|
| [d02e07] | 103 |   else
 | 
|---|
| [e65de8] | 104 |     correlationmap = PairCorrelation(molecules, elements);
 | 
|---|
| [d02e07] | 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;
 | 
|---|
| [97ebf8] | 117 | }
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 | Action::state_ptr AnalysisPairCorrelationAction::performRedo(Action::state_ptr _state){
 | 
|---|
| [d02e07] | 120 |   return Action::success;
 | 
|---|
| [97ebf8] | 121 | }
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | bool AnalysisPairCorrelationAction::canUndo() {
 | 
|---|
| [d02e07] | 124 |   return true;
 | 
|---|
| [97ebf8] | 125 | }
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | bool AnalysisPairCorrelationAction::shouldUndo() {
 | 
|---|
| [d02e07] | 128 |   return true;
 | 
|---|
| [97ebf8] | 129 | }
 | 
|---|
 | 130 | 
 | 
|---|
 | 131 | const string AnalysisPairCorrelationAction::getName() {
 | 
|---|
 | 132 |   return NAME;
 | 
|---|
 | 133 | }
 | 
|---|