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 | * PointCorrelationAction.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/PointCorrelationAction.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 <cmath>
|
---|
36 | #include <iostream>
|
---|
37 | #include <string>
|
---|
38 |
|
---|
39 | using namespace std;
|
---|
40 |
|
---|
41 | #include "UIElements/UIFactory.hpp"
|
---|
42 | #include "UIElements/Dialog.hpp"
|
---|
43 | #include "Actions/ValueStorage.hpp"
|
---|
44 |
|
---|
45 | const char AnalysisPointCorrelationAction::NAME[] = "point-correlation";
|
---|
46 |
|
---|
47 | AnalysisPointCorrelationAction::AnalysisPointCorrelationAction() :
|
---|
48 | Action(NAME)
|
---|
49 | {}
|
---|
50 |
|
---|
51 | AnalysisPointCorrelationAction::~AnalysisPointCorrelationAction()
|
---|
52 | {}
|
---|
53 |
|
---|
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 |
|
---|
66 | Dialog* AnalysisPointCorrelationAction::fillDialog(Dialog *dialog) {
|
---|
67 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
68 |
|
---|
69 | dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
|
---|
70 | dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
|
---|
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"));
|
---|
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;
|
---|
91 | std::vector<const element *> elements;
|
---|
92 | string type;
|
---|
93 | Vector Point;
|
---|
94 | BinPairMap *binmap = NULL;
|
---|
95 |
|
---|
96 | // obtain information
|
---|
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);
|
---|
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;
|
---|
111 | for(std::vector<const element *>::iterator iter = elements.begin(); iter != elements.end(); ++iter)
|
---|
112 | cout << "element is " << (*iter)->getSymbol() << endl;
|
---|
113 | std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
|
---|
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 | }
|
---|