Chemical Data Processing Library C++ API - Version 1.1.1
AutoCorrelation3DVectorCalculator.hpp
Go to the documentation of this file.
1 /*
2  * AutoCorrelation3DVectorCalculator.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_DESCR_AUTOCORRELATION3DVECTORCALCULATOR_HPP
30 #define CDPL_DESCR_AUTOCORRELATION3DVECTORCALCULATOR_HPP
31 
32 #include <cstddef>
33 #include <iterator>
34 #include <cmath>
35 #include <functional>
36 
37 #include "CDPL/Math/Matrix.hpp"
39 
40 
41 namespace CDPL
42 {
43 
44  namespace Descr
45  {
46 
50  template <typename T>
52  {
53 
54  public:
55  typedef T EntityType;
56 
64  typedef std::function<double(const EntityType&, const EntityType&)> EntityPairWeightFunction;
65 
73  typedef std::function<const Math::Vector3D&(const EntityType&)> Entity3DCoordinatesFunction;
74 
79 
85  void setStartRadius(double start_radius);
86 
91  double getStartRadius() const;
92 
98  void setRadiusIncrement(double radius_inc);
99 
104  double getRadiusIncrement() const;
105 
115  void setNumSteps(std::size_t num_steps);
116 
121  std::size_t getNumSteps() const;
122 
129 
137 
149  template <typename Iter, typename Vec>
150  void calculate(Iter beg, Iter end, Vec& vec);
151 
152  private:
153  template <typename Iter>
154  void init(Iter beg, Iter end);
155 
156  double startRadius;
157  double radiusIncrement;
158  std::size_t numSteps;
159  std::size_t numEntities;
160  EntityPairWeightFunction weightFunc;
161  Entity3DCoordinatesFunction coordsFunc;
162  Math::DMatrix weightMatrix;
163  Math::Vector3DArray entityPositions;
164  };
165  } // namespace Descr
166 } // namespace CDPL
167 
168 
169 // Implementation
170 
171 template <typename T>
173  startRadius(0.0), radiusIncrement(0.1), numSteps(99)
174 {}
175 
176 template <typename T>
178 {
179  startRadius = start_radius;
180 }
181 
182 template <typename T>
184 {
185  radiusIncrement = radius_inc;
186 }
187 
188 template <typename T>
190 {
191  numSteps = num_steps;
192 }
193 
194 template <typename T>
196 {
197  return startRadius;
198 }
199 
200 template <typename T>
202 {
203  return radiusIncrement;
204 }
205 
206 template <typename T>
208 {
209  return numSteps;
210 }
211 
212 template <typename T>
214 {
215  weightFunc = func;
216 }
217 
218 template <typename T>
220 {
221  coordsFunc = func;
222 }
223 
224 template <typename T>
225 template <typename Iter, typename Vec>
227 {
228  init(beg, end);
229 
230  for (std::size_t i = 0; i <= numSteps; i++)
231  vec[i] = 0.0;
232 
233  Math::Vector3D tmp;
234  const double max_radius = startRadius + (numSteps + 1) * radiusIncrement;
235 
236  for (std::size_t i = 0; i < numEntities; i++) {
237  for (std::size_t j = i; j < numEntities; j++) {
238  double dist = 0.0;
239 
240  if (i != j) {
241  tmp.assign(entityPositions[i] - entityPositions[j]);
242  dist = length(tmp);
243  }
244 
245  if (dist < startRadius || dist >= max_radius)
246  continue;
247 
248  std::size_t idx = std::floor((dist - startRadius) / radiusIncrement);
249 
250  vec[idx] = weightMatrix(i, j);
251  }
252  }
253 }
254 
255 template <typename T>
256 template <typename Iter>
258 {
259  numEntities = std::distance(beg, end);
260 
261  weightMatrix.resize(numEntities, numEntities, false);
262  entityPositions.resize(numEntities);
263 
264  for (std::size_t i = 0; beg != end; i++, ++beg) {
265  const EntityType& entity1 = *beg;
266 
267  if (coordsFunc)
268  entityPositions[i] = coordsFunc(entity1);
269  else
270  entityPositions[i].clear(0.0);
271 
272  std::size_t j = i;
273 
274  for (Iter it = beg; it != end; ++it, j++) {
275  const EntityType& entity2 = *it;
276 
277  if (!weightFunc)
278  weightMatrix(i, j) = 1.0;
279  else
280  weightMatrix(i, j) = weightFunc(entity1, entity2);
281  }
282  }
283 }
284 
285 #endif // CDPL_DESCR_AUTOCORRELATION3DVECTORCALCULATOR_HPP
CDPL::Descr::AutoCorrelation3DVectorCalculator::setEntity3DCoordinatesFunction
void setEntity3DCoordinatesFunction(const Entity3DCoordinatesFunction &func)
Allows to specify the entity 3D coordinates function.
Definition: AutoCorrelation3DVectorCalculator.hpp:219
VectorArray.hpp
Definition of the class CDPL::Math::VectorArray.
CDPL::Math::Vector3D
CVector< double, 3 > Vector3D
A bounded 3 element vector holding floating point values of type double.
Definition: Vector.hpp:1637
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Descr::AutoCorrelation3DVectorCalculator::AutoCorrelation3DVectorCalculator
AutoCorrelation3DVectorCalculator()
Constructs the AutoCorrelation3DVectorCalculator instance.
Definition: AutoCorrelation3DVectorCalculator.hpp:172
CDPL::Descr::AutoCorrelation3DVectorCalculator::EntityType
T EntityType
Definition: AutoCorrelation3DVectorCalculator.hpp:55
VectorArray< Vector3D >
double
CDPL::Descr::AutoCorrelation3DVectorCalculator::setEntityPairWeightFunction
void setEntityPairWeightFunction(const EntityPairWeightFunction &func)
Allows to specify a custom entity pair weight function.
Definition: AutoCorrelation3DVectorCalculator.hpp:213
CDPL::Descr::AutoCorrelation3DVectorCalculator::getRadiusIncrement
double getRadiusIncrement() const
Returns the radius step size between successive autocorrelation vector elements.
Definition: AutoCorrelation3DVectorCalculator.hpp:201
CDPL::Math::vec
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Descr::AutoCorrelation3DVectorCalculator< Chem::Atom >::Entity3DCoordinatesFunction
std::function< const Math::Vector3D &(const EntityType &)> Entity3DCoordinatesFunction
Type of the generic functor class used to store a user-defined entity 3D coordinates function.
Definition: AutoCorrelation3DVectorCalculator.hpp:73
CDPL::Descr::AutoCorrelation3DVectorCalculator::getStartRadius
double getStartRadius() const
Returns the starting value of the radius.
Definition: AutoCorrelation3DVectorCalculator.hpp:195
CDPL::Descr::AutoCorrelation3DVectorCalculator::EntityPairWeightFunction
std::function< double(const EntityType &, const EntityType &)> EntityPairWeightFunction
Type of the generic functor class used to store a user-defined entity pair weight function.
Definition: AutoCorrelation3DVectorCalculator.hpp:64
CDPL::Math::Matrix< double >
CDPL::Descr::AutoCorrelation3DVectorCalculator::setRadiusIncrement
void setRadiusIncrement(double radius_inc)
Sets the radius step size between successive autocorrelation vector elements.
Definition: AutoCorrelation3DVectorCalculator.hpp:183
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Descr::AutoCorrelation3DVectorCalculator::getNumSteps
std::size_t getNumSteps() const
Returns the number of performed radius incrementation steps.
Definition: AutoCorrelation3DVectorCalculator.hpp:207
Matrix.hpp
Definition of matrix data types.
CDPL::Descr::AutoCorrelation3DVectorCalculator
AutoCorrelation3DVectorCalculator.
Definition: AutoCorrelation3DVectorCalculator.hpp:52
CDPL::Descr::AutoCorrelation3DVectorCalculator::calculate
void calculate(Iter beg, Iter end, Vec &vec)
Calculates the RDF code of an entity sequence.
Definition: AutoCorrelation3DVectorCalculator.hpp:226
CDPL::Descr::AutoCorrelation3DVectorCalculator::setStartRadius
void setStartRadius(double start_radius)
Sets the starting value of the radius.
Definition: AutoCorrelation3DVectorCalculator.hpp:177
CDPL::Math::length
VectorNorm2< E >::ResultType length(const VectorExpression< E > &e)
Definition: VectorExpression.hpp:553
CDPL::Descr::AutoCorrelation3DVectorCalculator::setNumSteps
void setNumSteps(std::size_t num_steps)
Sets the number of desired radius incrementation steps.
Definition: AutoCorrelation3DVectorCalculator.hpp:189