Chemical Data Processing Library C++ API - Version 1.4.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 
63  {
64 
65  public:
66  class Result;
67 
68  private:
69  typedef std::vector<Result> ResultList;
70 
71  public:
73  static constexpr double DEF_OPTIMIZATION_STOP_GRADIENT = 1.0;
74 
76  static constexpr std::size_t DEF_MAX_OPTIMIZATION_ITERATIONS = 20;
77 
79  typedef std::shared_ptr<GaussianShapeFunctionAlignment> SharedPointer;
80 
82  typedef ResultList::const_iterator ConstResultIterator;
83 
86 
89 
93  class Result
94  {
95 
96  public:
103  Result(const Math::Matrix4D& xform, double overlap, double col_overlap):
104  transform(xform), overlap(overlap), colOverlap(col_overlap) {}
105 
111  {
112  return transform;
113  }
114 
119  double getOverlap() const
120  {
121  return overlap;
122  }
123 
128  double getColorOverlap() const
129  {
130  return colOverlap;
131  }
132 
133  private:
135 
136  Result():
137  transform(), overlap(0.0), colOverlap(0.0) {}
138 
140  double overlap;
141  double colOverlap;
142  };
143 
148 
154  GaussianShapeFunctionAlignment(const GaussianShapeFunction& ref_func, unsigned int sym_class);
155 
157 
160 
162 
168 
174 
180 
186 
192 
198 
204 
210 
216 
222 
228 
234 
239  void performAlignment(bool perf_align);
240 
245  bool performAlignment() const;
246 
251  void optimizeOverlap(bool optimize);
252 
257  bool optimizeOverlap() const;
258 
263  void greedyOptimization(bool greedy);
264 
269  bool greedyOptimization() const;
270 
275  void setMaxNumOptimizationIterations(std::size_t max_iter);
276 
281  std::size_t getMaxNumOptimizationIterations() const;
282 
287  void setOptimizationStopGradient(double grad_norm);
288 
294 
301  unsigned int setupReference(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
302 
309  unsigned int setupAligned(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
310 
316  void setReference(const GaussianShapeFunction& func, unsigned int sym_class);
317 
323 
330 
337 
342  void calcColorOverlaps(bool calc);
343 
348  bool calcColorOverlaps() const;
349 
356  bool align(const GaussianShapeFunction& func, unsigned int sym_class);
357 
362  std::size_t getNumResults() const;
363 
370  const Result& getResult(std::size_t idx) const;
371 
377 
383 
389 
395 
396  private:
397  bool checkValidity(const GaussianShapeFunction& func) const;
398 
399  double calcAlignmentFunctionValue(const QuaternionTransformation& xform_quat);
400  double calcAlignmentFunctionGradient(const QuaternionTransformation& xform_quat, QuaternionTransformation& xform_grad);
401 
403 
404  FastGaussianShapeOverlapFunction defOverlapFunc;
406  GaussianShapeOverlapFunction* overlapFunc;
408  const GaussianShapeFunction* refShapeFunc;
409  unsigned int refShapeSymClass;
410  bool perfAlignment;
411  bool calcColOverlaps;
412  bool optOverlap;
413  bool greedyOpt;
414  std::size_t maxNumOptIters;
415  double optStopGrad;
416  Math::Vector3DArray startPoseCoords;
417  Math::Vector3DArray optPoseCoords;
418  Math::Vector3DArray optPoseCoordsGrad;
419  BFGSMinimizer minimizer;
420  ResultList results;
421  };
422  } // namespace Shape
423 } // namespace CDPL
424 
425 #endif // CDPL_SHAPE_GAUSSIANSHAPEFUNCTIONALIGNMENT_HPP
Implementation of the BFGS optimization algorithm.
Definition of class CDPL::Shape::FastGaussianShapeOverlapFunction.
Definition of matrix data types.
Definition of 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 class CDPL::Math::VectorArray.
Fixed-size vector of dimension N backed by a C-array (no dynamic allocation).
Definition: Vector.hpp:1876
Shape::GaussianShapeOverlapFunction implementation that uses two approximation techniques to trade so...
Definition: FastGaussianShapeOverlapFunction.hpp:58
Abstract base class for generators of starting transformations used to seed Gaussian-shape overlap op...
Definition: GaussianShapeAlignmentStartGenerator.hpp:57
A single alignment result: rigid-body transformation plus shape and color overlap values.
Definition: GaussianShapeFunctionAlignment.hpp:94
double getOverlap() const
Returns the shape overlap value of the alignment.
Definition: GaussianShapeFunctionAlignment.hpp:119
const Math::Matrix4D & getTransform() const
Returns the rigid-body transformation that maps the aligned shape onto the reference shape.
Definition: GaussianShapeFunctionAlignment.hpp:110
Result(const Math::Matrix4D &xform, double overlap, double col_overlap)
Constructs a Result with the given values.
Definition: GaussianShapeFunctionAlignment.hpp:103
double getColorOverlap() const
Returns the color overlap value of the alignment.
Definition: GaussianShapeFunctionAlignment.hpp:128
Driver for the alignment of one Shape::GaussianShapeFunction (the aligned shape) against a fixed refe...
Definition: GaussianShapeFunctionAlignment.hpp:63
std::size_t getNumResults() const
Returns the number of alignment results produced by the last align() call.
void setOptimizationStopGradient(double grad_norm)
Sets the gradient norm at which the overlap optimization is stopped.
ConstResultIterator begin() const
Returns a constant iterator pointing to the first alignment result (range-based for support).
ConstResultIterator end() const
Returns a constant iterator pointing one past the last alignment result (range-based for support).
void setColorFilterFunction(const ColorFilterFunction &func)
Specifies the function used to filter color features by type.
FastGaussianShapeOverlapFunction & getDefaultOverlapFunction()
Returns the built-in default overlap function (Shape::FastGaussianShapeOverlapFunction).
void calcColorOverlaps(bool calc)
Specifies whether color overlaps shall be evaluated in addition to shape overlaps.
GaussianShapeFunctionAlignment & operator=(const GaussianShapeFunctionAlignment &alignment)=delete
const Result & getResult(std::size_t idx) const
Returns the alignment result at index idx.
void performAlignment(bool perf_align)
Specifies whether the actual alignment shall be performed (vs. only evaluating overlaps in the initia...
void optimizeOverlap(bool optimize)
Specifies whether the overlap shall be optimized iteratively after the initial alignment.
GaussianShapeFunctionAlignment(const GaussianShapeFunctionAlignment &alignment)=delete
GaussianShapeFunctionAlignment(const GaussianShapeFunction &ref_func, unsigned int sym_class)
Constructs the GaussianShapeFunctionAlignment instance with the given reference shape function.
double calcColorSelfOverlap(const GaussianShapeFunction &func)
Calculates the color self-overlap of func using the configured overlap function.
const GaussianShapeFunction * getReference() const
Returns the current reference shape function (or nullptr if none is set).
unsigned int setupReference(GaussianShapeFunction &func, Math::Matrix4D &xform) const
Delegates the reference-shape preparation to the configured start generator.
bool greedyOptimization() const
Tells whether the overlap optimization uses a greedy strategy.
const ColorFilterFunction & getColorFilterFunction() const
Returns the currently configured color-filter function.
ResultList::const_iterator ConstResultIterator
A constant iterator over the alignment results.
Definition: GaussianShapeFunctionAlignment.hpp:82
bool align(const GaussianShapeFunction &func, unsigned int sym_class)
Aligns the shape function func against the configured reference shape.
void setColorMatchFunction(const ColorMatchFunction &func)
Specifies the function used to decide whether two color features match.
bool optimizeOverlap() const
Tells whether the overlap is optimized iteratively.
double getOptimizationStopGradient() const
Returns the currently configured overlap-optimization stop gradient.
const ColorMatchFunction & getColorMatchFunction() const
Returns the currently configured color-match function.
const PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator() const
Returns the built-in default principal-axes alignment-start generator.
double calcSelfOverlap(const GaussianShapeFunction &func)
Calculates the shape-only self-overlap of func using the configured overlap function.
void setReference(const GaussianShapeFunction &func, unsigned int sym_class)
Sets the reference shape function used by subsequent align() calls.
GaussianShapeOverlapFunction::ColorMatchFunction ColorMatchFunction
Type of the function used to decide whether two color features match.
Definition: GaussianShapeFunctionAlignment.hpp:88
const FastGaussianShapeOverlapFunction & getDefaultOverlapFunction() const
Returns the built-in default overlap function (Shape::FastGaussianShapeOverlapFunction).
PrincipalAxesAlignmentStartGenerator & getDefaultStartGenerator()
Returns the built-in default principal-axes alignment-start generator.
GaussianShapeAlignmentStartGenerator & getStartGenerator() const
Returns the currently configured alignment-start generator.
GaussianShapeOverlapFunction & getOverlapFunction() const
Returns the currently configured overlap function.
void greedyOptimization(bool greedy)
Specifies whether the overlap optimization shall use a greedy strategy that stops at the first local ...
void setOverlapFunction(GaussianShapeOverlapFunction &func)
Specifies the Gaussian-shape overlap function used during alignment.
ConstResultIterator getResultsBegin() const
Returns a constant iterator pointing to the first alignment result.
GaussianShapeFunctionAlignment()
Constructs the GaussianShapeFunctionAlignment instance without a reference shape.
bool calcColorOverlaps() const
Tells whether color overlaps are evaluated.
void setMaxNumOptimizationIterations(std::size_t max_iter)
Sets the maximum number of overlap-optimization iterations.
bool performAlignment() const
Tells whether the actual alignment is performed.
void setStartGenerator(GaussianShapeAlignmentStartGenerator &gen)
Specifies the alignment-start generator used to seed the overlap optimization.
ConstResultIterator getResultsEnd() const
Returns a constant iterator pointing one past the last alignment result.
std::size_t getMaxNumOptimizationIterations() const
Returns the currently configured maximum number of overlap-optimization iterations.
GaussianShapeOverlapFunction::ColorFilterFunction ColorFilterFunction
Type of the function used to filter color (pharmacophore) features by type.
Definition: GaussianShapeFunctionAlignment.hpp:85
unsigned int setupAligned(GaussianShapeFunction &func, Math::Matrix4D &xform) const
Delegates the aligned-shape preparation to the configured start generator.
std::shared_ptr< GaussianShapeFunctionAlignment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated GaussianShapeFunctionAlignment in...
Definition: GaussianShapeFunctionAlignment.hpp:79
Function representation of a Gaussian shape, used to evaluate the shape's density,...
Definition: GaussianShapeFunction.hpp:61
Abstract base class for functions evaluating the overlap between two Gaussian shape functions.
Definition: GaussianShapeOverlapFunction.hpp:56
std::function< bool(std::size_t)> ColorFilterFunction
Type of the function used to filter color (pharmacophore) features by type.
Definition: GaussianShapeOverlapFunction.hpp:63
std::function< bool(std::size_t, std::size_t)> ColorMatchFunction
Type of the function used to decide whether two color features match.
Definition: GaussianShapeOverlapFunction.hpp:66
Generator that produces alignment starting transformations by aligning the principal axes of the alig...
Definition: PrincipalAxesAlignmentStartGenerator.hpp:58
VectorArray< Vector3D > Vector3DArray
Array storing vectors of type Math::Vector3D.
Definition: VectorArray.hpp:85
CDPL_SHAPE_API void transform(GaussianShape &shape, const Math::Matrix4D &xform)
Applies an affine transformation to the element positions of shape.
The namespace of the Chemical Data Processing Library.