1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2011 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * DipoleAngularCorrelationAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: Feb 11, 2011
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Analysis/analysis_correlation.hpp"
|
---|
23 | #include "CodePatterns/Log.hpp"
|
---|
24 | #include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
|
---|
25 | #include "Descriptors/MoleculeFormulaDescriptor.hpp"
|
---|
26 | #include "Element/element.hpp"
|
---|
27 | #include "Element/periodentafel.hpp"
|
---|
28 | #include "LinearAlgebra/Vector.hpp"
|
---|
29 | #include "molecule.hpp"
|
---|
30 | #include "World.hpp"
|
---|
31 | #include "WorldTime.hpp"
|
---|
32 |
|
---|
33 | #include <iostream>
|
---|
34 | #include <map>
|
---|
35 | #include <string>
|
---|
36 |
|
---|
37 | #include "Actions/AnalysisAction/DipoleAngularCorrelationAction.hpp"
|
---|
38 |
|
---|
39 | using namespace MoleCuilder;
|
---|
40 |
|
---|
41 | // and construct the stuff
|
---|
42 | #include "DipoleAngularCorrelationAction.def"
|
---|
43 | #include "Action_impl_pre.hpp"
|
---|
44 |
|
---|
45 | /** =========== define the function ====================== */
|
---|
46 | Action::state_ptr AnalysisDipoleAngularCorrelationAction::performCall() {
|
---|
47 | //int ranges[3] = {1, 1, 1};
|
---|
48 | string type;
|
---|
49 |
|
---|
50 | // obtain information
|
---|
51 | getParametersfromValueStorage();
|
---|
52 | ASSERT(!params.periodic, "AnalysisDipoleAngularCorrelationAction() - periodic case not implemented.");
|
---|
53 |
|
---|
54 | // get selected atoms
|
---|
55 | std::vector<atom*> old_atom_selection = World::getInstance().getSelectedAtoms();
|
---|
56 | std::vector<molecule*> old_molecule_selection = World::getInstance().getSelectedMolecules();
|
---|
57 |
|
---|
58 | // get current time step
|
---|
59 | const unsigned int oldtime = WorldTime::getTime();
|
---|
60 |
|
---|
61 | // select atoms and obtain zero dipole orientation
|
---|
62 | Formula DipoleFormula(params.DipoleFormula);
|
---|
63 | World::getInstance().setTime(params.timestepzero);
|
---|
64 | World::getInstance().clearMoleculeSelection(); // TODO: This should be done in setTime or where molecules are re-done
|
---|
65 | World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
|
---|
66 | std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
|
---|
67 | std::map<atomId_t, Vector> ZeroVector = CalculateZeroAngularDipole(molecules);
|
---|
68 |
|
---|
69 | // go through each step of common trajectory of all atoms in set
|
---|
70 | World::getInstance().clearAtomSelection();
|
---|
71 | World::getInstance().selectAllAtoms(AtomsByMoleculeSelection());
|
---|
72 | std::vector<atom *> atoms = World::getInstance().getSelectedAtoms();
|
---|
73 | ASSERT(!atoms.empty(),
|
---|
74 | "AnalysisDipoleAngularCorrelationAction::performCall() - "
|
---|
75 | +toString(DipoleFormula)+" selects no atoms.");
|
---|
76 | range<size_t> timesteps = getMaximumTrajectoryBounds(atoms);
|
---|
77 | ASSERT(params.timestepzero < timesteps.first,
|
---|
78 | "AnalysisDipoleAngularCorrelationAction::performCall() - time step zero "
|
---|
79 | +toString(params.timestepzero)+" is beyond trajectory range ("
|
---|
80 | +toString(timesteps.first)+") of some atoms.");
|
---|
81 | for (size_t step = params.timestepzero; step < timesteps.first; ++step) {
|
---|
82 | // calculate dipoles relative to zero orientation
|
---|
83 | DipoleAngularCorrelationMap *correlationmap = NULL;
|
---|
84 | correlationmap = DipoleAngularCorrelation(DipoleFormula, step, ZeroVector, DontResetTime);
|
---|
85 |
|
---|
86 | // prepare step string in filename
|
---|
87 | std::stringstream stepstream;
|
---|
88 | stepstream << std::setw(4) << std::setfill('0') << step;
|
---|
89 | const std::string stepname(stepstream.str());
|
---|
90 |
|
---|
91 | // output correlation map
|
---|
92 | ofstream output;
|
---|
93 | std::string filename = params.outputname.string()+"."+stepname+".dat";
|
---|
94 | output.open(filename.c_str());
|
---|
95 | OutputCorrelationMap<DipoleAngularCorrelationMap>(&output, correlationmap, OutputDipoleAngularCorrelation_Header, OutputDipoleAngularCorrelation_Value);
|
---|
96 | output.close();
|
---|
97 |
|
---|
98 | // bin map
|
---|
99 | BinPairMap *binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
|
---|
100 |
|
---|
101 | // free correlation map
|
---|
102 | delete(correlationmap);
|
---|
103 |
|
---|
104 | // output binned map
|
---|
105 | ofstream binoutput;
|
---|
106 | std::string binfilename = params.binoutputname.string()+"."+stepname+".dat";
|
---|
107 | binoutput.open(binfilename.c_str());
|
---|
108 | OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
109 | binoutput.close();
|
---|
110 |
|
---|
111 | // free binned map
|
---|
112 | delete(binmap);
|
---|
113 | }
|
---|
114 |
|
---|
115 | // reset to old time step
|
---|
116 | World::getInstance().setTime(oldtime);
|
---|
117 |
|
---|
118 | // reset to old selections
|
---|
119 | World::getInstance().clearAtomSelection();
|
---|
120 | BOOST_FOREACH(atom *_atom, old_atom_selection) {
|
---|
121 | World::getInstance().selectAtom(_atom);
|
---|
122 | }
|
---|
123 | World::getInstance().clearMoleculeSelection();
|
---|
124 | BOOST_FOREACH(molecule *_mol, old_molecule_selection) {
|
---|
125 | World::getInstance().selectMolecule(_mol);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // exit
|
---|
129 | return Action::success;
|
---|
130 | }
|
---|
131 |
|
---|
132 | Action::state_ptr AnalysisDipoleAngularCorrelationAction::performUndo(Action::state_ptr _state) {
|
---|
133 | return Action::success;
|
---|
134 | }
|
---|
135 |
|
---|
136 | Action::state_ptr AnalysisDipoleAngularCorrelationAction::performRedo(Action::state_ptr _state){
|
---|
137 | return Action::success;
|
---|
138 | }
|
---|
139 |
|
---|
140 | bool AnalysisDipoleAngularCorrelationAction::canUndo() {
|
---|
141 | return true;
|
---|
142 | }
|
---|
143 |
|
---|
144 | bool AnalysisDipoleAngularCorrelationAction::shouldUndo() {
|
---|
145 | return true;
|
---|
146 | }
|
---|
147 | /** =========== end of function ====================== */
|
---|