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:
75  static constexpr double DEF_OPTIMIZATION_STOP_GRADIENT = 1.0;
76 
80  static constexpr std::size_t DEF_MAX_OPTIMIZATION_ITERATIONS = 20;
81 
85  typedef std::shared_ptr<GaussianShapeFunctionAlignment> SharedPointer;
86 
90  typedef ResultList::const_iterator ConstResultIterator;
91 
96 
101 
105  class Result
106  {
107 
108  public:
115  Result(const Math::Matrix4D& xform, double overlap, double col_overlap):
116  transform(xform), overlap(overlap), colOverlap(col_overlap) {}
117 
123  {
124  return transform;
125  }
126 
131  double getOverlap() const
132  {
133  return overlap;
134  }
135 
140  double getColorOverlap() const
141  {
142  return colOverlap;
143  }
144 
145  private:
147 
148  Result():
149  transform(), overlap(0.0), colOverlap(0.0) {}
150 
152  double overlap;
153  double colOverlap;
154  };
155 
160 
166  GaussianShapeFunctionAlignment(const GaussianShapeFunction& ref_func, unsigned int sym_class);
167 
169 
174 
176 
182 
188 
194 
200 
206 
212 
218 
224 
230 
236 
242 
248 
253  void performAlignment(bool perf_align);
254 
259  bool performAlignment() const;
260 
265  void optimizeOverlap(bool optimize);
266 
271  bool optimizeOverlap() const;
272 
277  void greedyOptimization(bool greedy);
278 
283  bool greedyOptimization() const;
284 
289  void setMaxNumOptimizationIterations(std::size_t max_iter);
290 
295  std::size_t getMaxNumOptimizationIterations() const;
296 
301  void setOptimizationStopGradient(double grad_norm);
302 
308 
315  unsigned int setupReference(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
316 
323  unsigned int setupAligned(GaussianShapeFunction& func, Math::Matrix4D& xform) const;
324 
330  void setReference(const GaussianShapeFunction& func, unsigned int sym_class);
331 
337 
344 
351 
356  void calcColorOverlaps(bool calc);
357 
362  bool calcColorOverlaps() const;
363 
370  bool align(const GaussianShapeFunction& func, unsigned int sym_class);
371 
376  std::size_t getNumResults() const;
377 
384  const Result& getResult(std::size_t idx) const;
385 
391 
397 
403 
409 
410  private:
411  bool checkValidity(const GaussianShapeFunction& func) const;
412 
413  double calcAlignmentFunctionValue(const QuaternionTransformation& xform_quat);
414  double calcAlignmentFunctionGradient(const QuaternionTransformation& xform_quat, QuaternionTransformation& xform_grad);
415 
417 
418  FastGaussianShapeOverlapFunction defOverlapFunc;
420  GaussianShapeOverlapFunction* overlapFunc;
422  const GaussianShapeFunction* refShapeFunc;
423  unsigned int refShapeSymClass;
424  bool perfAlignment;
425  bool calcColOverlaps;
426  bool optOverlap;
427  bool greedyOpt;
428  std::size_t maxNumOptIters;
429  double optStopGrad;
430  Math::Vector3DArray startPoseCoords;
431  Math::Vector3DArray optPoseCoords;
432  Math::Vector3DArray optPoseCoordsGrad;
433  BFGSMinimizer minimizer;
434  ResultList results;
435  };
436  } // namespace Shape
437 } // namespace CDPL
438 
439 #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:2047
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:106
double getOverlap() const
Returns the shape overlap value of the alignment.
Definition: GaussianShapeFunctionAlignment.hpp:131
const Math::Matrix4D & getTransform() const
Returns the rigid-body transformation that maps the aligned shape onto the reference shape.
Definition: GaussianShapeFunctionAlignment.hpp:122
Result(const Math::Matrix4D &xform, double overlap, double col_overlap)
Constructs a Result with the given values.
Definition: GaussianShapeFunctionAlignment.hpp:115
double getColorOverlap() const
Returns the color overlap value of the alignment.
Definition: GaussianShapeFunctionAlignment.hpp:140
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:90
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:100
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:95
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:85
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:67
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:72
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:87
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.