1 | /*
|
---|
2 | * MinimiseConstrainedPotential.hpp
|
---|
3 | *
|
---|
4 | * Created on: Feb 23, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef MINIMISECONSTRAINEDPOTENTIAL_HPP_
|
---|
9 | #define MINIMISECONSTRAINEDPOTENTIAL_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | class atom;
|
---|
17 |
|
---|
18 | #include <vector>
|
---|
19 | #include <map>
|
---|
20 |
|
---|
21 | #include "molecule.hpp"
|
---|
22 |
|
---|
23 | /** Structure to contain parameters needed for evaluation of constraint potential.
|
---|
24 | *
|
---|
25 | */
|
---|
26 | class MinimiseConstrainedPotential
|
---|
27 | {
|
---|
28 | public:
|
---|
29 | MinimiseConstrainedPotential(molecule::atomSet &_atoms);
|
---|
30 | ~MinimiseConstrainedPotential();
|
---|
31 |
|
---|
32 | /** Minimises the extra potential for constrained molecular dynamics and gives forces and the constrained potential energy.
|
---|
33 | * We do the following:
|
---|
34 | * -# Generate a distance list from all source to all target points
|
---|
35 | * -# Sort this per source point
|
---|
36 | * -# Take for each source point the target point with minimum distance, use this as initial permutation
|
---|
37 | * -# check whether molecule::ConstrainedPotential() is greater than injective penalty
|
---|
38 | * -# If so, we go through each source point, stepping down in the sorted target point distance list and re-checking potential.
|
---|
39 | * -# Next, we only apply transformations that keep the injectivity of the permutations list.
|
---|
40 | * -# Hence, for one source point we step down the ladder and seek the corresponding owner of this new target
|
---|
41 | * point and try to change it for one with lesser distance, or for the next one with greater distance, but only
|
---|
42 | * if this decreases the conditional potential.
|
---|
43 | * -# finished.
|
---|
44 | * -# Then, we calculate the forces by taking the spatial derivative, where we scale the potential to such a degree,
|
---|
45 | * that the total force is always pointing in direction of the constraint force (ensuring that we move in the
|
---|
46 | * right direction).
|
---|
47 | * -# Finally, we calculate the potential energy and return.
|
---|
48 | * \param *out output stream for debugging
|
---|
49 | * \param **PermutationMap on return: mapping between the atom label of the initial and the final configuration
|
---|
50 | * \param startstep current MD step giving initial position between which and \a endstep we perform the constrained MD (as further steps are always concatenated)
|
---|
51 | * \param endstep step giving final position in constrained MD
|
---|
52 | * \param IsAngstroem whether coordinates are in angstroem (true) or bohrradius (false)
|
---|
53 | * \sa molecule::VerletForceIntegration()
|
---|
54 | * \return potential energy (and allocated **PermutationMap (array of molecule::AtomCount ^2)
|
---|
55 | * \todo The constrained potential's constants are set to fixed values right now, but they should scale based on checks of the system in order
|
---|
56 | * to ensure they're properties (e.g. constants[2] always greater than the energy of the system).
|
---|
57 | * \bug this all is not O(N log N) but O(N^2)
|
---|
58 | */
|
---|
59 | double operator()(atom **&PermutationMap, int startstep, int endstep, bool IsAngstroem);
|
---|
60 |
|
---|
61 | /** Evaluates the (distance-related part) of the constrained potential for the constrained forces.
|
---|
62 | * \param *out output stream for debugging
|
---|
63 | * \param startstep current MD step giving initial position between which and \a endstep we perform the constrained MD (as further steps are always concatenated)
|
---|
64 | * \param endstep step giving final position in constrained MD
|
---|
65 | * \param **PermutationMap mapping between the atom label of the initial and the final configuration
|
---|
66 | * \param *Force ForceMatrix containing force vectors from the external energy functional minimisation.
|
---|
67 | * \todo the constant for the constrained potential distance part is hard-coded independently of the hard-coded value in MinimiseConstrainedPotential()
|
---|
68 | */
|
---|
69 | void EvaluateConstrainedForces(ForceMatrix *Force);
|
---|
70 |
|
---|
71 | private:
|
---|
72 | typedef std::pair < double, atom* > DistancePair;
|
---|
73 | typedef std::multimap < double, atom* > DistanceMap;
|
---|
74 | typedef std::pair < DistanceMap::iterator, bool> DistanceTestPair;
|
---|
75 |
|
---|
76 | molecule::atomSet atoms;
|
---|
77 | int startstep; //!< start configuration (MDStep in atom::trajectory)
|
---|
78 | int endstep; //!< end configuration (MDStep in atom::trajectory)
|
---|
79 | atom **PermutationMap; //!< gives target ptr for each atom, array of size molecule::AtomCount (this is "x" in \f$ V^{con}(x) \f$ )
|
---|
80 | DistanceMap **DistanceList; //!< distance list of each atom to each atom
|
---|
81 | DistanceMap::iterator *StepList; //!< iterator to ascend through NearestNeighbours \a **DistanceList
|
---|
82 | int *DoubleList; //!< count of which sources want to move to this target, basically the injective measure (>1 -> not injective)
|
---|
83 | DistanceMap::iterator *DistanceIterators; //!< marks which was the last picked target as injective candidate with smallest distance
|
---|
84 | bool IsAngstroem; //!< whether coordinates are in angstroem (true) or bohrradius (false)
|
---|
85 | double *PenaltyConstants; //!< penalty constant in front of each term
|
---|
86 |
|
---|
87 | /** \f$O(N^2)\f$ operation of calculation distance between each atom pair and putting into DistanceList.
|
---|
88 | * \param *mol molecule to scan distances in
|
---|
89 | * \param &Params constrained potential parameters
|
---|
90 | */
|
---|
91 | void FillDistanceList();
|
---|
92 |
|
---|
93 | /** Initialize lists.
|
---|
94 | * \param *out output stream for debugging
|
---|
95 | * \param *mol molecule to scan distances in
|
---|
96 | * \param &Params constrained potential parameters
|
---|
97 | */
|
---|
98 | void CreateInitialLists();
|
---|
99 |
|
---|
100 | /** Permutes \a **&PermutationMap until the penalty is below constants[2].
|
---|
101 | * \param *out output stream for debugging
|
---|
102 | * \param *mol molecule to scan distances in
|
---|
103 | * \param &Params constrained potential parameters
|
---|
104 | */
|
---|
105 | void MakeInjectivePermutation();
|
---|
106 |
|
---|
107 | /** Print the current permutation map.
|
---|
108 | * \param *out output stream for debugging
|
---|
109 | * \param &Params constrained potential parameters
|
---|
110 | * \param AtomCount number of atoms
|
---|
111 | */
|
---|
112 | void PrintPermutationMap() const;
|
---|
113 |
|
---|
114 | /** Evaluates the potential energy used for constrained molecular dynamics.
|
---|
115 | * \f$V_i^{con} = c^{bond} \cdot | r_{P(i)} - R_i | + sum_{i \neq j} C^{min} \cdot \frac{1}{C_{ij}} + C^{inj} \Bigl (1 - \theta \bigl (\prod_{i \neq j} (P(i) - P(j)) \bigr ) \Bigr )\f$
|
---|
116 | * where the first term points to the target in minimum distance, the second is a penalty for trajectories lying too close to each other (\f$C_{ij}\f$ is minimum distance between
|
---|
117 | * trajectories i and j) and the third term is a penalty for two atoms trying to each the same target point.
|
---|
118 | * Note that for the second term we have to solve the following linear system:
|
---|
119 | * \f$-c_1 \cdot n_1 + c_2 \cdot n_2 + C \cdot n_3 = - p_2 + p_1\f$, where \f$c_1\f$, \f$c_2\f$ and \f$C\f$ are constants,
|
---|
120 | * offset vector \f$p_1\f$ in direction \f$n_1\f$, offset vector \f$p_2\f$ in direction \f$n_2\f$,
|
---|
121 | * \f$n_3\f$ is the normal vector to both directions. \f$C\f$ would be the minimum distance between the two lines.
|
---|
122 | * \sa molecule::MinimiseConstrainedPotential(), molecule::VerletForceIntegration()
|
---|
123 | * \param *out output stream for debugging
|
---|
124 | * \param &Params constrained potential parameters
|
---|
125 | * \return potential energy
|
---|
126 | * \note This routine is scaling quadratically which is not optimal.
|
---|
127 | * \todo There's a bit double counting going on for the first time, bu nothing to worry really about.
|
---|
128 | */
|
---|
129 | double ConstrainedPotential();
|
---|
130 |
|
---|
131 | /** Try the next nearest neighbour in order to make the permutation map injective.
|
---|
132 | * \param *out output stream for debugging
|
---|
133 | * \param *mol molecule
|
---|
134 | * \param *Walker atom to change its target
|
---|
135 | * \param &OldPotential old value of constraint potential to see if we do better with new target
|
---|
136 | * \param &Params constrained potential parameters
|
---|
137 | */
|
---|
138 | double TryNextNearestNeighbourForInjectivePermutation(atom *Walker, double &OldPotential);
|
---|
139 |
|
---|
140 | /** Penalizes atoms heading to same target.
|
---|
141 | * \param *Walker atom to check against others
|
---|
142 | * \param *mol molecule with other atoms
|
---|
143 | * \param &Params constrained potential parameters
|
---|
144 | * \return \a penalty times the number of equal targets
|
---|
145 | */
|
---|
146 | double PenalizeEqualTargets(atom *Walker);
|
---|
147 |
|
---|
148 | /** Penalizes long trajectories.
|
---|
149 | * \param *Walker atom to check against others
|
---|
150 | * \param *mol molecule with other atoms
|
---|
151 | * \param &Params constraint potential parameters
|
---|
152 | * \return penalty times each distance
|
---|
153 | */
|
---|
154 | double SumDistanceOfTrajectories(atom *Walker);
|
---|
155 |
|
---|
156 | };
|
---|
157 |
|
---|
158 |
|
---|
159 | #endif /* MINIMISECONSTRAINEDPOTENTIAL_HPP_ */
|
---|