29 #ifndef CDPL_SHAPE_FASTGAUSSIANSHAPEALIGNMENT_HPP
30 #define CDPL_SHAPE_FASTGAUSSIANSHAPEALIGNMENT_HPP
35 #include <unordered_map>
39 #include <boost/functional/hash.hpp>
40 #include <boost/random/mersenne_twister.hpp>
72 typedef std::vector<AlignmentResult> ResultList;
76 static constexpr
double DEF_OPTIMIZATION_STOP_GRADIENT = 1.0;
78 static constexpr std::size_t DEF_MAX_OPTIMIZATION_ITERATIONS = 20;
82 static constexpr
double DEF_SYMMETRY_THRESHOLD = 0.15;
84 static constexpr std::size_t DEF_NUM_RANDOM_STARTS = 4;
86 static constexpr
double DEF_MAX_RANDOM_TRANSLATION = 2.0;
473 typedef std::vector<Element> ElementArray;
475 ElementArray elements;
476 std::size_t colElemOffs;
477 std::size_t setIndex;
479 unsigned int symClass;
482 double colSelfOverlap;
483 bool equalNonColDelta;
486 typedef std::pair<std::size_t, std::size_t> ResultID;
488 void alignAndProcessResults(std::size_t ref_idx, std::size_t al_idx);
489 void processResult(
AlignmentResult& res, std::size_t ref_idx, std::size_t al_idx);
491 void setupShapeData(
const GaussianShape& shape, ShapeData& data,
bool ref);
494 void prepareForAlignment();
496 bool generateStartTransforms(
const ShapeData& ref_data);
498 void generateTransformsForElementCenters(
const ShapeData& data,
unsigned int axes_swap_flags,
bool ref_shape);
499 void generateTransforms(
const Math::Vector3D& ctr_trans,
unsigned int axes_swap_flags);
501 template <
typename QE>
504 void transformAlignedShape();
509 double calcOverlap(
const ShapeData& ref_data,
const ShapeData& ovl_data,
bool color)
const;
512 bool getResultIndex(
const ResultID& res_id, std::size_t& res_idx);
514 typedef std::vector<ShapeData> ShapeDataArray;
515 typedef std::unordered_map<ResultID, std::size_t, boost::hash<ResultID> > ResultIndexMap;
516 typedef std::vector<QuaternionTransformation> StartTransformList;
517 typedef boost::random::mt11213b RandomEngine;
523 std::size_t maxNumOptIters;
525 unsigned int resultSelMode;
528 ShapeDataArray refShapeData;
529 ShapeData algdShapeData;
530 ResultIndexMap resIndexMap;
532 std::size_t currSetIndex;
533 std::size_t currShapeIndex;
536 bool nonColCtrStarts;
538 bool genForAlgdShape;
540 bool genForLargerShape;
542 double maxRandomTrans;
543 std::size_t numRandomStarts;
544 std::size_t numSubTransforms;
545 RandomEngine randomEngine;
546 StartTransformList startTransforms;
552 std::size_t currRefShapeIdx;
Definition of constants in namespace CDPL::Shape::AlignmentResultSelectionMode.
Definition of class CDPL::Shape::AlignmentResult.
Implementation of the BFGS optimization algorithm.
Definition of class CDPL::Shape::GaussianShapeSet.
Definition of matrix data types.
Definition of various quaternion expression types and operations.
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
CRTP base class for all quaternion expression types.
Definition: Expression.hpp:142
Result of a Gaussian-shape alignment between a reference and an aligned shape.
Definition: AlignmentResult.hpp:52
High-level driver for the fast alignment of Gaussian shapes against a set of reference shapes.
Definition: FastGaussianShapeAlignment.hpp:70
ResultList::const_iterator ConstResultIterator
A constant iterator over the alignment results.
Definition: FastGaussianShapeAlignment.hpp:92
void setSymmetryThreshold(double thresh)
Sets the relative threshold for treating two principal moments as equal.
bool genColorCenterStarts() const
Tells whether starting transformations at color (pharmacophore) feature centers are generated.
AlignmentResult & getResult(std::size_t idx)
Returns the alignment result at index idx.
void genForAlignedShapeCenters(bool generate)
Specifies whether element-/color-center starts shall be generated for centers of the aligned shape.
std::size_t getNumRandomStarts() const
Returns the currently configured number of random starts.
void setNumRandomStarts(std::size_t num_starts)
Sets the number of random starting transformations.
const ResultCompareFunction & getResultCompareFunction() const
Returns the currently configured result-compare function.
void setMaxRandomTranslation(double max_trans)
Sets the maximum random translation magnitude applied to random starts.
std::shared_ptr< FastGaussianShapeAlignment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated FastGaussianShapeAlignment instan...
Definition: FastGaussianShapeAlignment.hpp:89
void setMaxNumOptimizationIterations(std::size_t max_iter)
Sets the maximum number of overlap-optimization iterations.
std::size_t getNumResults() const
Returns the number of stored alignment results.
void optimizeOverlap(bool optimize)
Specifies whether the overlap shall be optimized iteratively after the initial alignment.
ResultIterator getResultsBegin()
Returns a mutable iterator pointing to the first alignment result.
FastGaussianShapeAlignment(const GaussianShapeSet &ref_shapes)
Constructs the FastGaussianShapeAlignment instance with the shapes in ref_shapes as the reference set...
std::function< bool(const AlignmentResult &, const AlignmentResult &)> ResultCompareFunction
Type of the function used to compare two alignment results.
Definition: FastGaussianShapeAlignment.hpp:99
void clearReferenceShapes()
Removes all reference shapes and reference shape sets.
void genColorCenterStarts(bool generate)
Enables or disables the generation of starting transformations at color (pharmacophore) feature cente...
void setResultCompareFunction(const ResultCompareFunction &func)
Specifies the function used to compare two alignment results for sorting and filtering.
bool genForLargerShapeCenters() const
Tells whether element-/color-center starts are generated for centers of the shape with more elements ...
ResultIterator getResultsEnd()
Returns a mutable iterator pointing one past the last alignment result.
void genForReferenceShapeCenters(bool generate)
Specifies whether element-/color-center starts shall be generated for centers of the reference shape.
ResultIterator end()
Returns a mutable iterator pointing one past the last alignment result (range-based for support).
double getSymmetryThreshold()
Returns the currently configured symmetry threshold.
void setRandomSeed(unsigned int seed)
Sets the seed used by the random number generator that produces the random starts.
void setOptimizationStopGradient(double grad_norm)
Sets the gradient norm at which the overlap optimization is stopped.
unsigned int getResultSelectionMode() const
Returns the currently configured alignment-result selection mode.
ConstResultIterator begin() const
Returns a constant iterator pointing to the first alignment result (range-based for support).
ConstResultIterator getResultsBegin() const
Returns a constant iterator pointing to the first alignment result.
void setResultSelectionMode(unsigned int mode)
Sets the alignment-result selection mode (see namespace Shape::AlignmentResultSelectionMode).
bool genShapeCenterStarts() const
Tells whether a starting transformation at the shape centroid is generated.
bool greedyOptimization() const
Tells whether the overlap optimization uses a greedy strategy.
std::size_t getMaxNumOptimizationIterations() const
Returns the currently configured maximum number of overlap-optimization iterations.
void genNonColorCenterStarts(bool generate)
Enables or disables the generation of starting transformations at non-color (shape) element centers.
~FastGaussianShapeAlignment()
Destructor.
void genRandomStarts(bool generate)
Enables or disables the generation of random starting transformations.
bool genRandomStarts() const
Tells whether random starting transformations are generated.
void setScoringFunction(const ScoringFunction &func)
Specifies the function used to score an alignment result.
void greedyOptimization(bool greedy)
Specifies whether the overlap optimization shall use a greedy strategy that stops at the first local ...
const AlignmentResult & getResult(std::size_t idx) const
Returns the alignment result at index idx.
bool performAlignment() const
Tells whether the actual alignment is performed.
bool genForReferenceShapeCenters() const
Tells whether element-/color-center starts are generated for centers of the reference shape.
std::size_t getNumReferenceShapes() const
Returns the total number of reference shapes.
const ScoringFunction & getScoringFunction() const
Returns the currently configured scoring function.
bool align(const GaussianShape &shape)
Aligns shape against all reference shapes.
void performAlignment(bool perf_align)
Specifies whether the actual alignment shall be performed (vs. only evaluating overlaps in the initia...
ResultList::iterator ResultIterator
A mutable iterator over the alignment results.
Definition: FastGaussianShapeAlignment.hpp:94
double getOptimizationStopGradient() const
Returns the currently configured overlap-optimization stop gradient.
bool optimizeOverlap() const
Tells whether the overlap is optimized iteratively.
FastGaussianShapeAlignment(const GaussianShape &ref_shape)
Constructs the FastGaussianShapeAlignment instance with ref_shape as the single reference shape.
void genForLargerShapeCenters(bool generate)
Specifies whether element-/color-center starts shall be generated for centers of the shape with more ...
ConstResultIterator end() const
Returns a constant iterator pointing one past the last alignment result (range-based for support).
void genShapeCenterStarts(bool generate)
Enables or disables the generation of a starting transformation at the shape centroid.
bool genNonColorCenterStarts() const
Tells whether starting transformations at non-color (shape) element centers are generated.
std::function< double(const AlignmentResult &)> ScoringFunction
Type of the function used to score an alignment result.
Definition: FastGaussianShapeAlignment.hpp:97
FastGaussianShapeAlignment(const FastGaussianShapeAlignment &alignment)=delete
void addReferenceShapes(const GaussianShapeSet &shapes, bool new_set=true)
Adds the shapes in shapes to the reference shapes.
double getMaxRandomTranslation() const
Returns the currently configured maximum random translation.
FastGaussianShapeAlignment & operator=(const FastGaussianShapeAlignment &alignment)=delete
ResultIterator begin()
Returns a mutable iterator pointing to the first alignment result (range-based for support).
bool genForAlignedShapeCenters() const
Tells whether element-/color-center starts are generated for centers of the aligned shape.
FastGaussianShapeAlignment()
Constructs the FastGaussianShapeAlignment instance.
bool align(const GaussianShapeSet &shapes)
Aligns each shape in shapes against all reference shapes.
ConstResultIterator getResultsEnd() const
Returns a constant iterator pointing one past the last alignment result.
void addReferenceShape(const GaussianShape &shape, bool new_set=true)
Adds shape to the reference shapes.
Data structure storing a set of (shared) Gaussian shapes.
Definition: GaussianShapeSet.hpp:52
Data structure representing a single sphere of the Gaussian shape, characterized by a position,...
Definition: GaussianShape.hpp:58
Data type for the descripton of arbitrary shapes composed of spheres approximated by gaussian functio...
Definition: GaussianShape.hpp:51
VectorArray< Vector3D > Vector3DArray
Array storing vectors of type Math::Vector3D.
Definition: VectorArray.hpp:85
CVector< double, 3 > Vector3D
Bounded 3 element vector holding floating point values of type double.
Definition: Vector.hpp:2937
constexpr unsigned int BEST_PER_REFERENCE_SET
Keep only the best alignment result per reference shape set.
Definition: AlignmentResultSelectionMode.hpp:63
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.
Definition: FastGaussianShapeAlignment.hpp:463
Math::Vector3D center
Definition: FastGaussianShapeAlignment.hpp:466
double radius
Definition: FastGaussianShapeAlignment.hpp:467
std::size_t color
Definition: FastGaussianShapeAlignment.hpp:465
double volume
Definition: FastGaussianShapeAlignment.hpp:470
double weightFactor
Definition: FastGaussianShapeAlignment.hpp:469
double delta
Definition: FastGaussianShapeAlignment.hpp:468