| [be945c] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [d103d3] | 4 |  * Copyright (C)  2010-2011 University of Bonn. All rights reserved.
 | 
|---|
| [be945c] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /*
 | 
|---|
 | 9 |  * DipoleAngularCorrelationAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
| [208237b] | 11 |  *  Created on: Feb 11, 2011
 | 
|---|
| [be945c] | 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 | 
 | 
|---|
| [9b5a2c] | 22 | #include "Analysis/analysis_correlation.hpp"
 | 
|---|
| [be945c] | 23 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [e65878] | 24 | #include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
 | 
|---|
 | 25 | #include "Descriptors/MoleculeFormulaDescriptor.hpp"
 | 
|---|
| [3bdb6d] | 26 | #include "Element/element.hpp"
 | 
|---|
 | 27 | #include "Element/periodentafel.hpp"
 | 
|---|
| [be945c] | 28 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [e65878] | 29 | #include "molecule.hpp"
 | 
|---|
| [be945c] | 30 | #include "World.hpp"
 | 
|---|
| [bef3b9] | 31 | #include "WorldTime.hpp"
 | 
|---|
| [be945c] | 32 | 
 | 
|---|
 | 33 | #include <iostream>
 | 
|---|
| [325687] | 34 | #include <map>
 | 
|---|
| [be945c] | 35 | #include <string>
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | #include "Actions/AnalysisAction/DipoleAngularCorrelationAction.hpp"
 | 
|---|
 | 38 | 
 | 
|---|
| [ce7fdc] | 39 | using namespace MoleCuilder;
 | 
|---|
 | 40 | 
 | 
|---|
| [be945c] | 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();
 | 
|---|
| [cda81d] | 52 |   ASSERT(!params.periodic, "AnalysisDipoleAngularCorrelationAction() - periodic case not implemented.");
 | 
|---|
| [bef3b9] | 53 | 
 | 
|---|
 | 54 |   // get selected atoms
 | 
|---|
| [e65878] | 55 |   std::vector<atom*> old_atom_selection = World::getInstance().getSelectedAtoms();
 | 
|---|
 | 56 |   std::vector<molecule*> old_molecule_selection = World::getInstance().getSelectedMolecules();
 | 
|---|
| [bef3b9] | 57 | 
 | 
|---|
| [cda81d] | 58 |   // get current time step
 | 
|---|
| [9e1709] | 59 |   const unsigned int oldtime = WorldTime::getTime();
 | 
|---|
| [cda81d] | 60 | 
 | 
|---|
| [e65878] | 61 |   // select atoms and obtain zero dipole orientation
 | 
|---|
 | 62 |   Formula DipoleFormula(params.DipoleFormula);
 | 
|---|
| [c3a70d] | 63 |   World::getInstance().setTime(params.timestepzero);
 | 
|---|
| [e65878] | 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);
 | 
|---|
| [9e1709] | 68 | 
 | 
|---|
| [cda81d] | 69 |   // go through each step of common trajectory of all atoms in set
 | 
|---|
| [e65878] | 70 |   World::getInstance().clearAtomSelection();
 | 
|---|
 | 71 |   World::getInstance().selectAllAtoms(AtomsByMoleculeSelection());
 | 
|---|
 | 72 |   std::vector<atom *> atoms = World::getInstance().getSelectedAtoms();
 | 
|---|
| [c3a70d] | 73 |   ASSERT(!atoms.empty(),
 | 
|---|
 | 74 |       "AnalysisDipoleAngularCorrelationAction::performCall() - "
 | 
|---|
 | 75 |       +toString(DipoleFormula)+" selects no atoms.");
 | 
|---|
| [cda81d] | 76 |   range<size_t> timesteps = getMaximumTrajectoryBounds(atoms);
 | 
|---|
| [c3a70d] | 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) {
 | 
|---|
| [cda81d] | 82 |     // calculate dipoles relative to zero orientation
 | 
|---|
 | 83 |     DipoleAngularCorrelationMap *correlationmap = NULL;
 | 
|---|
| [e65878] | 84 |     correlationmap = DipoleAngularCorrelation(DipoleFormula, step, ZeroVector, DontResetTime);
 | 
|---|
| [cda81d] | 85 | 
 | 
|---|
| [a2b0ce] | 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 | 
 | 
|---|
| [cda81d] | 91 |     // output correlation map
 | 
|---|
 | 92 |     ofstream output;
 | 
|---|
| [a2b0ce] | 93 |     std::string filename = params.outputname.string()+"."+stepname+".dat";
 | 
|---|
| [cda81d] | 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;
 | 
|---|
| [a2b0ce] | 106 |     std::string binfilename = params.binoutputname.string()+"."+stepname+".dat";
 | 
|---|
| [cda81d] | 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);
 | 
|---|
| [bef3b9] | 117 | 
 | 
|---|
| [e65878] | 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 | 
 | 
|---|
| [bef3b9] | 128 |   // exit
 | 
|---|
| [be945c] | 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 ====================== */
 | 
|---|