RDKit
Open-source cheminformatics and machine learning.
BoundsMatrix.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #include <RDGeneral/export.h>
11 #ifndef __RD_BOUNDS_MATRIX_H__
12 #define __RD_BOUNDS_MATRIX_H__
13 
14 #include <RDGeneral/Invariant.h>
15 #include <boost/smart_ptr.hpp>
16 #include <iostream>
17 #include <iomanip>
18 #include <Numerics/SquareMatrix.h>
19 
20 namespace DistGeom {
21 //! Class to store the distance bound
22 /*!
23  Basically a N by N matrix
24  with lower distance bounds on the lower traingle and upper bounds in the upper
25  triangle
26 */
28  public:
29  typedef boost::shared_array<double> DATA_SPTR;
30 
31  explicit BoundsMatrix(unsigned int N)
32  : RDNumeric::SquareMatrix<double>(N, 0.0){};
33  BoundsMatrix(unsigned int N, DATA_SPTR data)
34  : RDNumeric::SquareMatrix<double>(N, data){};
35 
36  //! Get the upper bound between points i and j
37  inline double getUpperBound(unsigned int i, unsigned int j) const {
38  URANGE_CHECK(i, d_nRows);
39  URANGE_CHECK(j, d_nCols);
40 
41  if (i < j) {
42  return getVal(i, j);
43  } else {
44  return getVal(j, i);
45  }
46  }
47 
48  //! Set the lower bound between points i and j
49  inline void setUpperBound(unsigned int i, unsigned int j, double val) {
50  URANGE_CHECK(i, d_nRows);
51  URANGE_CHECK(j, d_nCols);
52  CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
53  if (i < j) {
54  setVal(i, j, val);
55  } else {
56  setVal(j, i, val);
57  }
58  }
59 
60  //! Set the upper bound between points i and j only if it is better than
61  //! previously existing value (i.e. the new value is smaller)
62  inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
63  double val) {
64  if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
65  setUpperBound(i, j, val);
66  }
67  }
68 
69  //! Set the lower bound between points i and j
70  inline void setLowerBound(unsigned int i, unsigned int j, double val) {
71  URANGE_CHECK(i, d_nRows);
72  URANGE_CHECK(j, d_nCols);
73  CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
74  if (i < j) {
75  setVal(j, i, val);
76  } else {
77  setVal(i, j, val);
78  }
79  }
80 
81  //! Set the lower bound between points i and j only if it is better than
82  //! previously existing value (i.e. the new value is larger)
83  inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
84  double val) {
85  if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
86  setLowerBound(i, j, val);
87  }
88  }
89 
90  //! Get the lower bound between points i and j
91  inline double getLowerBound(unsigned int i, unsigned int j) const {
92  URANGE_CHECK(i, d_nRows);
93  URANGE_CHECK(j, d_nCols);
94 
95  if (i < j) {
96  return getVal(j, i);
97  } else {
98  return getVal(i, j);
99  }
100  }
101 
102  //! Do a simple check of the current bounds - i.e. all lower bounds are
103  //! smaller than the existing upper bounds
104  inline bool checkValid() const {
105  unsigned int i, j;
106  for (i = 1; i < d_nRows; i++) {
107  for (j = 0; j < i; j++) {
108  if (getUpperBound(i, j) < getLowerBound(i, j)) {
109  return false;
110  }
111  }
112  }
113  return true;
114  }
115 };
116 
117 typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
118 }
119 
120 #endif
void setLowerBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition: BoundsMatrix.h:83
#define RDKIT_DISTGEOMETRY_EXPORT
Definition: export.h:164
#define CHECK_INVARIANT(expr, mess)
Definition: Invariant.h:100
boost::shared_ptr< BoundsMatrix > BoundsMatPtr
Definition: BoundsMatrix.h:117
void setUpperBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
Definition: BoundsMatrix.h:49
void setUpperBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition: BoundsMatrix.h:62
BoundsMatrix(unsigned int N)
Definition: BoundsMatrix.h:31
double getUpperBound(unsigned int i, unsigned int j) const
Get the upper bound between points i and j.
Definition: BoundsMatrix.h:37
bool checkValid() const
Definition: BoundsMatrix.h:104
#define URANGE_CHECK(x, hi)
Definition: Invariant.h:141
void setLowerBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
Definition: BoundsMatrix.h:70
Class to store the distance bound.
Definition: BoundsMatrix.h:27
boost::shared_array< double > DATA_SPTR
Definition: BoundsMatrix.h:29
double getLowerBound(unsigned int i, unsigned int j) const
Get the lower bound between points i and j.
Definition: BoundsMatrix.h:91
BoundsMatrix(unsigned int N, DATA_SPTR data)
Definition: BoundsMatrix.h:33