File: DistPicker.h

package info (click to toggle)
rdkit 202209.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 203,880 kB
  • sloc: cpp: 334,239; python: 80,247; ansic: 24,579; java: 7,667; sql: 2,123; yacc: 1,884; javascript: 1,358; lex: 1,260; makefile: 576; xml: 229; fortran: 183; cs: 181; sh: 101
file content (92 lines) | stat: -rw-r--r-- 2,720 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
//  Copyright (C) 2003-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef _RD_DISTPICKER_H
#define _RD_DISTPICKER_H

#include <RDGeneral/types.h>

namespace RDPickers {

/*! \brief function to lookup distance from 1D lower triangular distance matrix
 *
 *
 *    \param distMat - a pointer to a 1D lower triangular distance matrix \n
 *    \param i - row index \n
 *    \param j - column index \n
 *
 *  RETURNS:
 *
 *    if (i == j) : 0.0
 *    if (i > j) : distMat[i*(i-1)/2 + j]
 *    if (j < i) : distMat[j*(j-1)/2 + i]
 */
RDKIT_SIMDIVPICKERS_EXPORT double getDistFromLTM(const double *distMat,
                                                 unsigned int i,
                                                 unsigned int j);

/*! \brief Abstract base class to do perform item picking (typically molecules)
 *using a
 *         distance matrix
 *
 *  This class should never be instantiated by itself. One of the child classes
 *need to be
 *  used. The picking algorithm itself is missing here and only the child
 *classes implement that
 *  This class contains a pointer to a distance matrix, but it is not
 *responsible for cleaning it up
 */
class RDKIT_SIMDIVPICKERS_EXPORT DistPicker {
 public:
  /*! \brief Default constructor
   *
   */
  DistPicker() {}
  virtual ~DistPicker() {}

  /*! \brief this is a virtual function specific to the type of algorihtm used
   *
   *  The child classes need to implement this function
   *
   *  ARGUMENTS:
   *
   *    \param distMat - distance matrix - a vector of double. It is assumed
   *that only the
   *              lower triangle elements of the matrix are supplied in a 1D
   *array
   *    \param poolSize - the size of the pool to pick the items from. It is
   *assumed that the
   *              distance matrix above contains the right number of elements;
   *i.e.
   *              poolSize*(poolSize-1)
   *    \param pickSize - the number items to pick from pool (<= poolSize)
   *
   *    \return a vector with indices of the picked items.
   */
  virtual RDKit::INT_VECT pick(const double *distMat, unsigned int poolSize,
                               unsigned int pickSize) const = 0;
};

namespace {
class distmatFunctor {
 public:
  distmatFunctor(const double *distMat) : dp_distMat(distMat) {}
  double operator()(unsigned int i, unsigned int j) {
    return getDistFromLTM(this->dp_distMat, i, j);
  }

 private:
  const double *dp_distMat;
};
}  // namespace

};  // namespace RDPickers

#endif