Debian Codegraph @

include/BALL/MOLMEC/COMMON/gradient.h

raw symbols SCIP
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: gradient.h,v 1.20.20.1 2007/05/18 12:02:44 oliver Exp $
5 //
6 // Author:
7 // Oliver Kohlbacher
8 //
9
10 // A conjugate gradient minimizer for geometry optimisation
11
12 #ifndef BALL_MOLMEC_COMMON_GRADIENT_H
13 #define BALL_MOLMEC_COMMON_GRADIENT_H
14
15 #ifndef BALL_COMMON_H
16 # include <BALL/common.h>
17 #endif
18
19 #ifndef BALL_MATHS_VECTOR3_H
20 # include <BALL/MATHS/vector3.h>
21 #endif
22
23 #include <vector>
24
25 namespace BALL
26 {
27 class AtomVector;
28
29 /** Gradient class.
30 This class is used in the Minimizers to represent gradients and
31 directions.
32 These gradients are extracted from a vector of atom pointers, if the
33 forces of the atoms are correctly set (e.g. using ForceField::updateForces()).
34 The gradient contains the negative forces from each atom. Forces are converted from Newton (N)
35 to units of f$kJ/(mol \AA)f$.
36 A gradient may be invalidated by calling \link invalidate invalidate \endlink . This method only
37 flags the gradient as invalid, the data is untouched. This may be used to
38 initiate automatic recalculations of the gradient.
39 This class is used by all minimizer classes. \par
40
41 \ingroup MolmecCommon
42 */
43 class BALL_EXPORT Gradient
44 : private std::vector<Vector3>
45 {
46 public:
47
48 BALL_CREATE_DEEP(Gradient)
49
50 /** Type definitions
51 */
52 //@{
53
54 /** Iterator type
55 */
56 typedef std::vector<Vector3>::iterator Iterator;
57
58 /** Const iterator type
59 */
60 typedef std::vector<Vector3>::const_iterator ConstIterator;
61
62 /** Iterator type
63 */
64 typedef std::vector<Vector3>::reverse_iterator ReverseIterator;
65
66 /** Const iterator type
67 */
68 typedef std::vector<Vector3>::const_reverse_iterator ConstReverseIterator;
69
70
71 //@}
72 /** @name Constructors and Destructors
73 */
74 //@{
75
76 /** Default constructor.
77 */
78 Gradient();
79
80 /** Construct from atom forces
81 */
82 Gradient(const AtomVector& atoms);
83
84 /** Copy constructor
85 */
86 Gradient(const Gradient& gradient, bool deep = true);
87
88 /** Destructor.
89 */
90 virtual ~Gradient();
91 //@}
92
93 /** @name Assignments
94 */
95 //@{
96
97 /** Assignment operator
98 */
99 Gradient& operator = (const Gradient& rhs);
100
101 /** Assign from an array of atom pointers.
102 */
103 Gradient& operator = (const AtomVector& rhs);
104
105 /** Assign from another gradient
106 */
107 void set(const Gradient& gradient);
108
109 /** Assign from an array of atom pointers.
110 */
111 void set(const AtomVector& atoms);
112
113 /** Negate the gradient.
114 Iterate over all force vectors of the gradient and
115 invert the signs.
116 */
117 void negate();
118
119 /** Normalize the gradient.
120 Rescale to unity length
121 */
122 void normalize();
123
124 /** Dot product operator
125 @exception InvalidRange if the two gradients have different sizes
126 */
127 double operator * (const Gradient& gradient) const;
128 //@}
129
130 /** @name Accessors
131 */
132 //@{
133
134 /* Return the number of components of the gradient.
135 */
136 using std::vector<Vector3>::size;
137
138 /* Return the component for an atom.
139 */
140 //?????: GCC3 using std::vector<Vector3>::operator [];
141 const Vector3& operator [] (int i) const { return std::vector<Vector3>::operator [] (i); }
142 Vector3& operator [] (int i) { return std::vector<Vector3>::operator [] (i); }
143
144 /** Invalidate the gradient.
145 */
146 void invalidate();
147
148 /** Return the validity flag.
149 */
150 bool isValid() const;
151 //@}
152
153
154 /** @name Iteration
155 */
156 //@{
157
158 /** Return an iterator to the begining of the vector
159 */
160 //?????: GCC3 using std::vector<Vector3>::begin;
161 Iterator begin() { return vector<Vector3>::begin(); }
162 ConstIterator begin() const { return vector<Vector3>::begin(); }
163
164 /** Return a past-the-end vector.
165 */
166 //?????: GCC3 using std::vector<Vector3>::end;
167 Iterator end() { return vector<Vector3>::end(); }
168 ConstIterator end() const { return vector<Vector3>::end(); }
169
170 /** Return an iterator to the reverse begining of the vector
171 */
172 //?????: GCC3 using std::vector<Vector3>::begin;
173 ReverseIterator rbegin() { return vector<Vector3>::rbegin(); }
174 ConstReverseIterator rbegin() const { return vector<Vector3>::rbegin(); }
175
176 /** Return a reverse past-the-end vector.
177 */
178 //?????: GCC3 using std::vector<Vector3>::end;
179 ReverseIterator rend() { return vector<Vector3>::rend(); }
180 ConstReverseIterator rend() const { return vector<Vector3>::rend(); }
181 //@}
182
183 /** @name Public Attributes
184 */
185 //@{
186
187 /** The gradient norm.
188 */
189 double norm;
190
191 /** The inverse of the gradient norm.
192 */
193 double inv_norm;
194
195 /** The root mean square of the gradient.
196 */
197 double rms;
198
199 //@}
200
201 protected:
202
203 /*_ The validity flag.
204 */
205 bool valid_;
206
207 };
208 } // end of namespace BALL
209
210 #endif // BALL_MOLMEC_COMMON_GRADIENT_H