Chemical Data Processing Library C++ API - Version 1.2.0
GaussianShapeFunctionAlignment.hpp
Go to the documentation of this file.
1 /*
2  * GaussianShapeFunctionAlignment.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_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
30 #define CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <memory>
35 
36 #include "CDPL/Shape/APIPrefix.hpp"
40 #include "CDPL/Math/Matrix.hpp"
43 
44 
45 namespace CDPL
46 {
47 
48  namespace Shape
49  {
50 
52  {
53 
54  public:
55  class Result;
56 
57  private:
58  typedef std::vector<Result> ResultList;
59 
60  public:
61  static constexpr double DEF_OPTIMIZATION_STOP_GRADIENT = 1.0;
62  static constexpr std::size_t DEF_MAX_OPTIMIZATION_ITERATIONS = 20;
63 
64  typedef std::shared_ptr<GaussianShapeFunctionAlignment> SharedPointer;
65 
66  typedef ResultList::const_iterator ConstResultIterator;
67 
70 
71  class Result
72  {
73 
74  public:
75  Result(const Math::Matrix4D& xform, double overlap, double col_overlap):
76  transform(xform), overlap(overlap), colOverlap(col_overlap) {}
77 
79  {
80  return transform;
81  }
82 
83  double getOverlap() const
84  {
85  return overlap;
86  }
87 
88  double getColorOverlap() const
89  {
90  return colOverlap;
91  }
92 
93  private:
95 
96  Result():
97  transform(), overlap(0.0), colOverlap(0.0) {}
98 
100  double overlap;
101  double colOverlap;
102  };
103 
105 
106  GaussianShapeFunctionAlignment(const GaussianShapeFunction& ref_func, unsigned int sym_class);
107 
109 
111 
113 
115 
117 
119 
121 
123 
125 
127 
129 
131 
133 
135 
137 
138  void performAlignment(bool perf_align);
139 
140  bool performAlignment() const;
141 
142  void optimizeOverlap(bool optimize);
143 
144  bool optimizeOverlap() const;
145 
146  void greedyOptimization(bool greedy);
147 
148  bool greedyOptimization() const;
149 
150  void setMaxNumOptimizationIterations(std::size_t max_iter);
151 
152  std::size_t getMaxNumOptimizationIterations() const;
153 
154  void setOptimizationStopGradient(double grad_norm);
155 
157 
158  unsigned int setupReference(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
159 
160  unsigned int setupAligned(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
161 
162  void setReference(const GaussianShapeFunction& func, unsigned int sym_class);
163 
165 
167 
169 
170  void calcColorOverlaps(bool calc);
171 
172  bool calcColorOverlaps() const;
173 
174  bool align(const GaussianShapeFunction& func, unsigned int sym_class);
175 
176  std::size_t getNumResults() const;
177 
178  const Result& getResult(std::size_t idx) const;
179 
181 
183 
185 
187 
188  private:
189  bool checkValidity(const GaussianShapeFunction& func) const;
190 
191  double calcAlignmentFunctionValue(const QuaternionTransformation& xform_quat);
192  double calcAlignmentFunctionGradient(const QuaternionTransformation& xform_quat, QuaternionTransformation& xform_grad);
193 
195 
196  FastGaussianShapeOverlapFunction defOverlapFunc;
198  GaussianShapeOverlapFunction* overlapFunc;
200  const GaussianShapeFunction* refShapeFunc;
201  unsigned int refShapeSymClass;
202  bool perfAlignment;
203  bool calcColOverlaps;
204  bool optOverlap;
205  bool greedyOpt;
206  std::size_t maxNumOptIters;
207  double optStopGrad;
208  Math::Vector3DArray startPoseCoords;
209  Math::Vector3DArray optPoseCoords;
210  Math::Vector3DArray optPoseCoordsGrad;
211  BFGSMinimizer minimizer;
212  ResultList results;
213  };
214  } // namespace Shape
215 } // namespace CDPL
216 
217 #endif // CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
Implementation of the BFGS optimization algorithm.
Definition of the class CDPL::Shape::FastGaussianShapeOverlapFunction.
Definition of matrix data types.
Definition of the class CDPL::Shape::PrincipalAxesAlignmentStartGenerator.
Definition of the type CDPL::Shape::QuaternionTransformation.
Definition of the preprocessor macro CDPL_SHAPE_API.
#define CDPL_SHAPE_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of the class CDPL::Math::VectorArray.
Definition: Vector.hpp:1053
Definition: FastGaussianShapeOverlapFunction.hpp:47
Definition: GaussianShapeAlignmentStartGenerator.hpp:49
Definition: GaussianShapeFunctionAlignment.hpp:72
double getOverlap() const
Definition: GaussianShapeFunctionAlignment.hpp:83
const Math::Matrix4D & getTransform() const
Definition: GaussianShapeFunctionAlignment.hpp:78
Result(const Math::Matrix4D &xform, double overlap, double col_overlap)
Definition: GaussianShapeFunctionAlignment.hpp:75
double getColorOverlap() const
Definition: GaussianShapeFunctionAlignment.hpp:88
Definition: GaussianShapeFunctionAlignment.hpp:52
void setOptimizationStopGradient(double grad_norm)
void setColorFilterFunction(const ColorFilterFunction &func)
FastGaussianShapeOverlapFunction & getDefaultOverlapFunction()
GaussianShapeFunctionAlignment & operator=(const GaussianShapeFunctionAlignment &alignment)=delete
const Result & getResult(std::size_t idx) const
GaussianShapeFunctionAlignment(const GaussianShapeFunctionAlignment &alignment)=delete
GaussianShapeFunctionAlignment(const GaussianShapeFunction &ref_func, unsigned int sym_class)
double calcColorSelfOverlap(const GaussianShapeFunction &func)
const GaussianShapeFunction * getReference() const
unsigned int setupReference(GaussianShapeFunction &func, Math::Matrix4D &xform) const
const ColorFilterFunction & getColorFilterFunction() const
ResultList::const_iterator ConstResultIterator
Definition: GaussianShapeFunctionAlignment.hpp:66
bool align(const GaussianShapeFunction &func, unsigned int sym_class)
void setColorMatchFunction(const ColorMatchFunction &func)
const ColorMatchFunction & getColorMatchFunction() const
const PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator() const
double calcSelfOverlap(const GaussianShapeFunction &func)
void setReference(const GaussianShapeFunction &func, unsigned int sym_class)
GaussianShapeOverlapFunction::ColorMatchFunction ColorMatchFunction
Definition: GaussianShapeFunctionAlignment.hpp:69
const FastGaussianShapeOverlapFunction & getDefaultOverlapFunction() const
PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator()
GaussianShapeAlignmentStartGenerator & getStartGenerator() const
GaussianShapeOverlapFunction & getOverlapFunction() const
void setOverlapFunction(GaussianShapeOverlapFunction &func)
ConstResultIterator getResultsBegin() const
void setMaxNumOptimizationIterations(std::size_t max_iter)
void setStartGenerator(GaussianShapeAlignmentStartGenerator &gen)
ConstResultIterator getResultsEnd() const
std::size_t getMaxNumOptimizationIterations() const
GaussianShapeOverlapFunction::ColorFilterFunction ColorFilterFunction
Definition: GaussianShapeFunctionAlignment.hpp:68
unsigned int setupAligned(GaussianShapeFunction &func, Math::Matrix4D &xform) const
std::shared_ptr< GaussianShapeFunctionAlignment > SharedPointer
Definition: GaussianShapeFunctionAlignment.hpp:64
Definition: GaussianShapeFunction.hpp:53
Definition: GaussianShapeOverlapFunction.hpp:49
std::function< bool(std::size_t)> ColorFilterFunction
Definition: GaussianShapeOverlapFunction.hpp:54
std::function< bool(std::size_t, std::size_t)> ColorMatchFunction
Definition: GaussianShapeOverlapFunction.hpp:55
Definition: PrincipalAxesAlignmentStartGenerator.hpp:49
VectorArray< Vector3D > Vector3DArray
An array of Math::Vector3D objects.
Definition: VectorArray.hpp:84
CDPL_SHAPE_API void transform(GaussianShape &shape, const Math::Matrix4D &xform)
The namespace of the Chemical Data Processing Library.