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