| [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 | 
 | 
|---|
 | 18 | #include "atom.hpp"
 | 
|---|
 | 19 | #include "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 "parser.hpp"
 | 
|---|
 | 28 | #include "World.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | template <class Set>
 | 
|---|
 | 31 | class LinearInterpolationBetweenSteps
 | 
|---|
 | 32 | {
 | 
|---|
 | 33 | public:
 | 
|---|
 | 34 |   LinearInterpolationBetweenSteps(AtomSetMixin<Set> &_atoms, unsigned int _MaxOuterStep) :
 | 
|---|
 | 35 |     MaxOuterStep(_MaxOuterStep),
 | 
|---|
 | 36 |     IsAngstroem(true),
 | 
|---|
 | 37 |     atoms(_atoms)
 | 
|---|
 | 38 |   {}
 | 
|---|
 | 39 |   ~LinearInterpolationBetweenSteps()
 | 
|---|
 | 40 |   {}
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |   /** Performs a linear interpolation between two desired atomic configurations with a given number of steps.
 | 
|---|
 | 43 |    * Note, step number is config::MaxOuterStep
 | 
|---|
 | 44 |    * \param *out output stream for debugging
 | 
|---|
 | 45 |    * \param startstep stating initial configuration in molecule::Trajectories
 | 
|---|
 | 46 |    * \param endstep stating final configuration in molecule::Trajectories
 | 
|---|
 | 47 |    * \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()
 | 
|---|
 | 48 |    */
 | 
|---|
| [eb33c4] | 49 |   void operator()(int startstep, int endstep, bool MapByIdentity)
 | 
|---|
| [20943b] | 50 |   {
 | 
|---|
 | 51 |     // TODO: rewrite permutationMaps using enumeration objects
 | 
|---|
 | 52 |     int MaxSteps = MaxOuterStep;
 | 
|---|
| [eb33c4] | 53 | 
 | 
|---|
| [20943b] | 54 |     // Get the Permutation Map by MinimiseConstrainedPotential
 | 
|---|
| [eb33c4] | 55 |     std::map<atom*, atom *> PermutationMap;
 | 
|---|
| [20943b] | 56 |     if (!MapByIdentity) {
 | 
|---|
| [eb33c4] | 57 |       LOG(1, "STATUS: Constructing atom mapping from start to end position.");
 | 
|---|
| [20943b] | 58 |       molecule::atomSet atoms_list;
 | 
|---|
 | 59 |       copy(atoms.begin(), atoms.end(), atoms_list.begin());
 | 
|---|
| [e355762] | 60 |       MinimiseConstrainedPotential Minimiser(atoms_list, PermutationMap);
 | 
|---|
 | 61 |       Minimiser(startstep, endstep, IsAngstroem);
 | 
|---|
| [20943b] | 62 |     } else {
 | 
|---|
| [eb33c4] | 63 |       LOG(1, "STATUS: Using identity mapping.");
 | 
|---|
| [20943b] | 64 |       // TODO: construction of enumeration goes here
 | 
|---|
 | 65 |       for(typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end();++iter){
 | 
|---|
| [eb33c4] | 66 |         PermutationMap[(*iter)] = (*iter);
 | 
|---|
| [20943b] | 67 |       }
 | 
|---|
 | 68 |     }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 |     // check whether we have sufficient space in Trajectories for each atom
 | 
|---|
| [eb33c4] | 71 |     LOG(1, "STATUS: Extending trajectories.");
 | 
|---|
| [20943b] | 72 |     for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 73 |       (*iter)->ResizeTrajectory(MaxSteps);
 | 
|---|
 | 74 |     }
 | 
|---|
 | 75 |     // push endstep to last one
 | 
|---|
 | 76 |     for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 77 |       (*iter)->CopyStepOnStep(MaxSteps,endstep);
 | 
|---|
 | 78 |     }
 | 
|---|
 | 79 |     endstep = MaxSteps;
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |     // go through all steps and add the molecular configuration to the list and to the Trajectories of \a this molecule
 | 
|---|
| [eb33c4] | 82 |     LOG(1, "STATUS: Filling intermediate " << MaxSteps << " steps." << endl);
 | 
|---|
| [20943b] | 83 |     for (int step = 0; step <= MaxSteps; step++) {
 | 
|---|
| [eb33c4] | 84 |       LOG(2, "INFO: Current step is " << step << "." << endl);
 | 
|---|
| [20943b] | 85 |       for (typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
 | 
|---|
 | 86 |         // add to Trajectories
 | 
|---|
| [eb33c4] | 87 |         ASSERT(PermutationMap.count((*iter)),
 | 
|---|
 | 88 |             "LinearInterpolationBetweenSteps::operator() - atom "+toString(**iter)+" not found in PermutationMap.");
 | 
|---|
 | 89 |         Vector temp = (*iter)->getPositionAtStep(startstep) + (PermutationMap[(*iter)]->getPositionAtStep(endstep) - (*iter)->getPositionAtStep(startstep))*((double)step/(double)MaxSteps);
 | 
|---|
 | 90 |         (*iter)->setPositionAtStep(step,temp);
 | 
|---|
| [20943b] | 91 |         (*iter)->setAtomicVelocityAtStep(step, zeroVec);
 | 
|---|
 | 92 |         (*iter)->setAtomicForceAtStep(step, zeroVec);
 | 
|---|
| [eb33c4] | 93 |         LOG(2, "INFO: Adding trajectory point for atom " << **iter << " at " << temp << ".");
 | 
|---|
| [20943b] | 94 |       }
 | 
|---|
 | 95 |     }
 | 
|---|
 | 96 | 
 | 
|---|
| [eb33c4] | 97 | //    // store the list to single step files
 | 
|---|
 | 98 | //    int *SortIndex = new int[atoms.size()];
 | 
|---|
 | 99 | //    for (int i=atoms.size(); i--; )
 | 
|---|
 | 100 | //      SortIndex[i] = i;
 | 
|---|
 | 101 | //
 | 
|---|
 | 102 | //    status = MoleculePerStep->OutputConfigForListOfFragments(prefix, SortIndex);
 | 
|---|
 | 103 | //    delete[](SortIndex);
 | 
|---|
| [20943b] | 104 |   };
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | private:
 | 
|---|
 | 107 |   unsigned int MaxOuterStep;
 | 
|---|
 | 108 |   bool IsAngstroem;
 | 
|---|
 | 109 |   AtomSetMixin<Set> atoms;
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 | };
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 | #endif /* LINEARINTERPOLATIONBETWEENSTEPS_HPP_ */
 | 
|---|