source: src/Dynamics/BondVectors.hpp@ f433ec

AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since f433ec was f433ec, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

We now obtain weights via levmar minimization.

  • this should yield the best possible weights within the interval of [1/n,1.].
  • note that we cannot always get an exact solution because of this constraint.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * BondVectors.hpp
3 *
4 * Created on: Jun 13, 2017
5 * Author: heber
6 */
7
8
9#ifndef DYNAMICS_BONDVECTORS_HPP_
10#define DYNAMICS_BONDVECTORS_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <map>
18#include <vector>
19
20#include <boost/function.hpp>
21
22#include "CodePatterns/Assert.hpp"
23
24#include "LinearAlgebra/Vector.hpp"
25
26#include "Bond/bond.hpp"
27
28/** This class represents all bond vectors, i.e. the normalized direction
29 * along a list of bonds, and provides means to extract them from a set of
30 * atoms such that for an arbitrary bond the vector can be quickly retrieved.
31 */
32class BondVectors
33{
34public:
35 //!> typedef for the internal container of the bonds
36 typedef std::vector<bond::ptr> container_t;
37
38 //!> typedef for the association of bonds to bond vectors
39 typedef std::map<bond::ptr, Vector> mapped_t;
40
41 /** Default cstor for class BondVectors.
42 *
43 */
44 BondVectors();
45
46 /** Prepares the internal container from the bonds of a range of atoms.
47 *
48 * \param _start start of range
49 * \param _end end of range
50 * \param _step time step to request bonds for
51 */
52 template <class T>
53 void setFromAtomRange(
54 typename T::iterator _start,
55 typename T::iterator _end,
56 const size_t &_step);
57
58 /** Getter for the sorted bonds.
59 *
60 * \return const ref to internal container
61 */
62 const container_t& getSorted() const;
63
64 /** Getter for the Bondvectors.
65 *
66 * \param _step time step for which the bond vector is request
67 * \return a map from bond to bond vector
68 */
69 const mapped_t& getBondVectorsAtStep(const size_t &_step) const;
70
71 /** Get the position in the internal container for a specific bond.
72 *
73 * \param _bond given bond
74 * \return position in the vector, -1 if not present
75 */
76 size_t getIndexForBond(const bond::ptr &_bond) const;
77
78 /** Gather the subset of BondVectors for the given atom.
79 *
80 * \param _walker atom to get BondVectors for
81 * \param _step time step for which the bond vector is request
82 */
83 std::vector<Vector> getAtomsBondVectorsAtStep(
84 const atom &_walker,
85 const size_t &_step) const;
86
87 //!> typedef for the weights for the Bondvectors of a single atom
88 typedef std::deque<double> weights_t;
89
90 /** Calculates the weights for a frame where each Bondvector of the
91 * given atom is a vector of the frame.
92 *
93 * The idea is that we can represent any vector by appropriate weights such
94 * that is still sums up to one.
95 *
96 * \param _walker atom to get BondVectors for
97 * \param _bondvectors precalculated bond vectors for given \a _walker
98 * \param _step time step for which the bond vector is request
99 */
100 weights_t getWeightsForAtomAtStep(
101 const atom &_walker,
102 const std::vector<Vector> &_bondvectors,
103 const size_t &_step) const;
104
105 /** Calculates the weights for a frame where each Bondvector of the
106 * given atom is a vector of the frame.
107 *
108 * The idea is that we can represent any vector by appropriate weights such
109 * that is still sums up to one.
110 *
111 * \param _walker atom to get BondVectors for
112 * \param _step time step for which the bond vector is request
113 */
114 weights_t getWeightsForAtomAtStep(
115 const atom &_walker,
116 const size_t &_step) const;
117
118 /** Function typedef to store the bond gradient into a specific container
119 * depending on the atom, its current bond and the time step.
120 */
121 typedef boost::function<void (
122 const atom &,
123 const bond::ptr &,
124 const size_t &,
125 const double)> forcestore_t;
126
127 /** Function calculates the remaining part of the atomic gradient that is
128 * not captured by the sum of the force along the Bond Vectors.
129 *
130 * \param _walker atom to get BondVectors for
131 * \param _BondVectors precalculated bond vectors for given \a _walker
132 * \param _weights weight per bond vector (as it is a frame, not a basis)
133 * \param _step time step for which the bond vector is request
134 * \param _forcestore additional function which may be used to store each
135 * calculated bond force in a bound container
136 */
137 Vector getRemnantGradientForAtomAtStep(
138 const atom &_walker,
139 const std::vector<Vector> _BondVectors,
140 const BondVectors::weights_t &_weights,
141 const size_t &_step,
142 forcestore_t _forcestore) const;
143
144private:
145 /** Calculates the bond vector for each bond in the internal container.
146 *
147 * \param _step time step for which the bond vector is request
148 */
149 void recalculateBondVectorsAtStep(const size_t &_step) const;
150
151 /** Helper function to check whether weights sum up to one for each
152 * Bond Vector.
153 *
154 * \param _walker atom to get BondVectors for
155 * \param _BondVectors precalculated bond vectors for given \a _walker
156 * \param _weights weight per bond vector (as it is a frame, not a basis)
157 * \param _step time step for which the bond vector is request
158 */
159 bool getCheckWeightSumForAtomAtStep(
160 const atom &_walker,
161 const std::vector<Vector> _BondVectors,
162 const BondVectors::weights_t &_weights,
163 const size_t &_step) const;
164
165private:
166 //!> internal container for sorted bonds
167 container_t container;
168
169 //!> states whether map needs update or not
170 mutable bool map_is_dirty;
171
172 //!> contains the step for which the map was calculated
173 mutable size_t current_step_for_map;
174
175 //!> internal map for bond Bondvector association
176 mutable mapped_t current_mapped_vectors;
177};
178
179#include "BondVectors_impl.hpp"
180
181#endif /* DYNAMICS_BONDVECTORS_HPP_ */
Note: See TracBrowser for help on using the repository browser.