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"
|
---|
20 | #include "CodePatterns/Info.hpp"
|
---|
21 | #include "CodePatterns/Log.hpp"
|
---|
22 | #include "CodePatterns/Verbose.hpp"
|
---|
23 | #include "Dynamics/MinimiseConstrainedPotential.hpp"
|
---|
24 | #include "molecule.hpp"
|
---|
25 | #include "parser.hpp"
|
---|
26 | #include "World.hpp"
|
---|
27 |
|
---|
28 | template <class Set>
|
---|
29 | class LinearInterpolationBetweenSteps
|
---|
30 | {
|
---|
31 | public:
|
---|
32 | LinearInterpolationBetweenSteps(AtomSetMixin<Set> &_atoms, unsigned int _MaxOuterStep) :
|
---|
33 | MDSteps(0),
|
---|
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 &prefix path and prefix
|
---|
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 | * \return true - success in writing step files, false - error writing files or only one step in molecule::Trajectories
|
---|
49 | */
|
---|
50 | bool operator()(int startstep, int endstep, std::string prefix, bool MapByIdentity)
|
---|
51 | {
|
---|
52 | // TODO: rewrite permutationMaps using enumeration objects
|
---|
53 | molecule *mol = NULL;
|
---|
54 | bool status = true;
|
---|
55 | int MaxSteps = MaxOuterStep;
|
---|
56 | MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer());
|
---|
57 | // Get the Permutation Map by MinimiseConstrainedPotential
|
---|
58 | atom **PermutationMap = NULL;
|
---|
59 | atom *Sprinter = NULL;
|
---|
60 | if (!MapByIdentity) {
|
---|
61 | molecule::atomSet atoms_list;
|
---|
62 | copy(atoms.begin(), atoms.end(), atoms_list.begin());
|
---|
63 | MinimiseConstrainedPotential Minimiser(atoms_list);
|
---|
64 | Minimiser(PermutationMap, startstep, endstep, IsAngstroem);
|
---|
65 | } else {
|
---|
66 | // TODO: construction of enumeration goes here
|
---|
67 | PermutationMap = new atom *[atoms.size()];
|
---|
68 | for(typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end();++iter){
|
---|
69 | PermutationMap[(*iter)->getNr()] = (*iter);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | // check whether we have sufficient space in Trajectories for each atom
|
---|
74 | for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
---|
75 | (*iter)->ResizeTrajectory(MaxSteps);
|
---|
76 | }
|
---|
77 | // push endstep to last one
|
---|
78 | for(typename AtomSetMixin<Set>::iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
---|
79 | (*iter)->CopyStepOnStep(MaxSteps,endstep);
|
---|
80 | }
|
---|
81 | endstep = MaxSteps;
|
---|
82 |
|
---|
83 | // go through all steps and add the molecular configuration to the list and to the Trajectories of \a this molecule
|
---|
84 | DoLog(1) && (Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl);
|
---|
85 | for (int step = 0; step <= MaxSteps; step++) {
|
---|
86 | mol = World::getInstance().createMolecule();
|
---|
87 | MoleculePerStep->insert(mol);
|
---|
88 | for (typename AtomSetMixin<Set>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
---|
89 | // add to molecule list
|
---|
90 | Sprinter = mol->AddCopyAtom((*iter));
|
---|
91 | // add to Trajectories
|
---|
92 | Vector temp = (*iter)->getPositionAtStep(startstep) + (PermutationMap[(*iter)->getNr()]->getPositionAtStep(endstep) - (*iter)->getPositionAtStep(startstep))*((double)step/(double)MaxSteps);
|
---|
93 | Sprinter->setPosition(temp);
|
---|
94 | (*iter)->setAtomicVelocityAtStep(step, zeroVec);
|
---|
95 | (*iter)->setAtomicForceAtStep(step, zeroVec);
|
---|
96 | //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | MDSteps = MaxSteps+1; // otherwise new Trajectories' points aren't stored on save&exit
|
---|
100 |
|
---|
101 | // store the list to single step files
|
---|
102 | int *SortIndex = new int[atoms.size()];
|
---|
103 | for (int i=atoms.size(); i--; )
|
---|
104 | SortIndex[i] = i;
|
---|
105 |
|
---|
106 | status = MoleculePerStep->OutputConfigForListOfFragments(prefix, SortIndex);
|
---|
107 | delete[](SortIndex);
|
---|
108 |
|
---|
109 | // free and return
|
---|
110 | delete[](PermutationMap);
|
---|
111 | delete(MoleculePerStep);
|
---|
112 | return status;
|
---|
113 | };
|
---|
114 |
|
---|
115 | private:
|
---|
116 | unsigned int MDSteps;
|
---|
117 | unsigned int MaxOuterStep;
|
---|
118 | bool IsAngstroem;
|
---|
119 | AtomSetMixin<Set> atoms;
|
---|
120 |
|
---|
121 | };
|
---|
122 |
|
---|
123 | #endif /* LINEARINTERPOLATIONBETWEENSTEPS_HPP_ */
|
---|