| [20943b] | 1 | /*
 | 
|---|
 | 2 |  * LinearInterpolationBetweenSteps.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Feb 23, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef LINEARINTERPOLATIONBETWEENSTEPS_HPP_
 | 
|---|
 | 9 | #define LINEARINTERPOLATIONBETWEENSTEPS_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <vector>
 | 
|---|
 | 17 | 
 | 
|---|
| [6f0841] | 18 | #include "Atom/atom.hpp"
 | 
|---|
 | 19 | #include "Atom/AtomSet.hpp"
 | 
|---|
| [eb33c4] | 20 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| [20943b] | 21 | #include "CodePatterns/Info.hpp"
 | 
|---|
 | 22 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [eb33c4] | 23 | #include "CodePatterns/toString.hpp"
 | 
|---|
| [20943b] | 24 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
 | 25 | #include "Dynamics/MinimiseConstrainedPotential.hpp"
 | 
|---|
 | 26 | #include "molecule.hpp"
 | 
|---|
 | 27 | #include "World.hpp"
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | template <class Set>
 | 
|---|
 | 30 | class LinearInterpolationBetweenSteps
 | 
|---|
 | 31 | {
 | 
|---|
 | 32 | public:
 | 
|---|
 | 33 |   LinearInterpolationBetweenSteps(AtomSetMixin<Set> &_atoms, unsigned int _MaxOuterStep) :
 | 
|---|
 | 34 |     MaxOuterStep(_MaxOuterStep),
 | 
|---|
 | 35 |     IsAngstroem(true),
 | 
|---|
 | 36 |     atoms(_atoms)
 | 
|---|
 | 37 |   {}
 | 
|---|
 | 38 |   ~LinearInterpolationBetweenSteps()
 | 
|---|
 | 39 |   {}
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 |   /** Performs a linear interpolation between two desired atomic configurations with a given number of steps.
 | 
|---|
 | 42 |    * Note, step number is config::MaxOuterStep
 | 
|---|
 | 43 |    * \param *out output stream for debugging
 | 
|---|
 | 44 |    * \param startstep stating initial configuration in molecule::Trajectories
 | 
|---|
 | 45 |    * \param endstep stating final configuration in molecule::Trajectories
 | 
|---|
 | 46 |    * \param MapByIdentity if true we just use the identity to map atoms in start config to end config, if not we find mapping by \sa MinimiseConstrainedPotential()
 | 
|---|
 | 47 |    */
 | 
|---|
| [eb33c4] | 48 |   void operator()(int startstep, int endstep, bool MapByIdentity)
 | 
|---|
| [20943b] | 49 |   {
 | 
|---|
 | 50 |     // TODO: rewrite permutationMaps using enumeration objects
 | 
|---|
 | 51 |     int MaxSteps = MaxOuterStep;
 | 
|---|
| [eb33c4] | 52 | 
 | 
|---|
| [20943b] | 53 |     // Get the Permutation Map by MinimiseConstrainedPotential
 | 
|---|
| [eb33c4] | 54 |     std::map<atom*, atom *> PermutationMap;
 | 
|---|
| [20943b] | 55 |     if (!MapByIdentity) {
 | 
|---|
| [eb33c4] | 56 |       LOG(1, "STATUS: Constructing atom mapping from start to end position.");
 | 
|---|
| [adb5cda] | 57 |       MinimiseConstrainedPotential Minimiser(atoms, PermutationMap);
 | 
|---|
| [e355762] | 58 |       Minimiser(startstep, endstep, IsAngstroem);
 | 
|---|
| [20943b] | 59 |     } else {
 | 
|---|
| [eb33c4] | 60 |       LOG(1, "STATUS: Using identity mapping.");
 | 
|---|
| [20943b] | 61 |       // TODO: construction of enumeration goes here
 | 
|---|
 | 62 |       for(typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end();++iter){
 | 
|---|
| [eb33c4] | 63 |         PermutationMap[(*iter)] = (*iter);
 | 
|---|
| [20943b] | 64 |       }
 | 
|---|
 | 65 |     }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 |     // check whether we have sufficient space in Trajectories for each atom
 | 
|---|
| [eb33c4] | 68 |     LOG(1, "STATUS: Extending trajectories.");
 | 
|---|
| [20943b] | 69 |     for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 70 |       (*iter)->ResizeTrajectory(MaxSteps);
 | 
|---|
 | 71 |     }
 | 
|---|
 | 72 |     // push endstep to last one
 | 
|---|
 | 73 |     for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 74 |       (*iter)->CopyStepOnStep(MaxSteps,endstep);
 | 
|---|
 | 75 |     }
 | 
|---|
 | 76 |     endstep = MaxSteps;
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 |     // go through all steps and add the molecular configuration to the list and to the Trajectories of \a this molecule
 | 
|---|
| [eb33c4] | 79 |     LOG(1, "STATUS: Filling intermediate " << MaxSteps << " steps." << endl);
 | 
|---|
| [20943b] | 80 |     for (int step = 0; step <= MaxSteps; step++) {
 | 
|---|
| [eb33c4] | 81 |       LOG(2, "INFO: Current step is " << step << "." << endl);
 | 
|---|
| [20943b] | 82 |       for (typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 83 |         // add to Trajectories
 | 
|---|
| [eb33c4] | 84 |         ASSERT(PermutationMap.count((*iter)),
 | 
|---|
 | 85 |             "LinearInterpolationBetweenSteps::operator() - atom "+toString(**iter)+" not found in PermutationMap.");
 | 
|---|
 | 86 |         Vector temp = (*iter)->getPositionAtStep(startstep) + (PermutationMap[(*iter)]->getPositionAtStep(endstep) - (*iter)->getPositionAtStep(startstep))*((double)step/(double)MaxSteps);
 | 
|---|
 | 87 |         (*iter)->setPositionAtStep(step,temp);
 | 
|---|
| [20943b] | 88 |         (*iter)->setAtomicVelocityAtStep(step, zeroVec);
 | 
|---|
 | 89 |         (*iter)->setAtomicForceAtStep(step, zeroVec);
 | 
|---|
| [eb33c4] | 90 |         LOG(2, "INFO: Adding trajectory point for atom " << **iter << " at " << temp << ".");
 | 
|---|
| [20943b] | 91 |       }
 | 
|---|
 | 92 |     }
 | 
|---|
 | 93 |   };
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | private:
 | 
|---|
 | 96 |   unsigned int MaxOuterStep;
 | 
|---|
 | 97 |   bool IsAngstroem;
 | 
|---|
 | 98 |   AtomSetMixin<Set> atoms;
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | };
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | #endif /* LINEARINTERPOLATIONBETWEENSTEPS_HPP_ */
 | 
|---|