source: src/Dynamics/BondVectors.hpp@ 07d4b1

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 07d4b1 was 07d4b1, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

BondVectors::getRemnant...() now requires atom's gradient.

  • No more default anneal() without bondgraph, and can't store remnant gradient in force.
  • Property mode set to 100644
File size: 5.5 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 _walkerGradient gradient of atom to get BondVectors for
132 * \param _BondVectors precalculated bond vectors for given \a _walker
133 * \param _weights weight per bond vector (as it is a frame, not a basis)
134 * \param _step time step for which the bond vector is request
135 * \param _forcestore additional function which may be used to store each
136 * calculated bond force in a bound container
137 */
138 Vector getRemnantGradientForAtomAtStep(
139 const atom &_walker,
140 const Vector &_walkerGradient,
141 const std::vector<Vector> _BondVectors,
142 const BondVectors::weights_t &_weights,
143 const size_t &_step,
144 forcestore_t _forcestore) const;
145
146private:
147 /** Calculates the bond vector for each bond in the internal container.
148 *
149 * \param _step time step for which the bond vector is request
150 */
151 void recalculateBondVectorsAtStep(const size_t &_step) const;
152
153 /** Helper function to check whether weights sum up to one for each
154 * Bond Vector.
155 *
156 * \param _walker atom to get BondVectors for
157 * \param _BondVectors precalculated bond vectors for given \a _walker
158 * \param _weights weight per bond vector (as it is a frame, not a basis)
159 * \param _step time step for which the bond vector is request
160 */
161 bool getCheckWeightSumForAtomAtStep(
162 const atom &_walker,
163 const std::vector<Vector> _BondVectors,
164 const BondVectors::weights_t &_weights,
165 const size_t &_step) const;
166
167private:
168 //!> internal container for sorted bonds
169 container_t container;
170
171 //!> states whether map needs update or not
172 mutable bool map_is_dirty;
173
174 //!> contains the step for which the map was calculated
175 mutable size_t current_step_for_map;
176
177 //!> internal map for bond Bondvector association
178 mutable mapped_t current_mapped_vectors;
179};
180
181#include "BondVectors_impl.hpp"
182
183#endif /* DYNAMICS_BONDVECTORS_HPP_ */
Note: See TracBrowser for help on using the repository browser.