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 RDNumeric::SquareMatrix<double> {
29  public:
30  typedef boost::shared_array<double> DATA_SPTR;
31 
32  explicit BoundsMatrix(unsigned int N)
33  : RDNumeric::SquareMatrix<double>(N, 0.0){};
34  BoundsMatrix(unsigned int N, DATA_SPTR data)
35  : RDNumeric::SquareMatrix<double>(N, data){};
36 
37  //! Get the upper bound between points i and j
38  inline double getUpperBound(unsigned int i, unsigned int j) const {
39  URANGE_CHECK(i, d_nRows);
40  URANGE_CHECK(j, d_nCols);
41 
42  if (i < j) {
43  return getVal(i, j);
44  } else {
45  return getVal(j, i);
46  }
47  }
48 
49  //! Set the lower bound between points i and j
50  inline void setUpperBound(unsigned int i, unsigned int j, double val) {
51  URANGE_CHECK(i, d_nRows);
52  URANGE_CHECK(j, d_nCols);
53  CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
54  if (i < j) {
55  setVal(i, j, val);
56  } else {
57  setVal(j, i, val);
58  }
59  }
60 
61  //! Set the upper bound between points i and j only if it is better than
62  //! previously existing value (i.e. the new value is smaller)
63  inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
64  double val) {
65  if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
66  setUpperBound(i, j, val);
67  }
68  }
69 
70  //! Set the lower bound between points i and j
71  inline void setLowerBound(unsigned int i, unsigned int j, double val) {
72  URANGE_CHECK(i, d_nRows);
73  URANGE_CHECK(j, d_nCols);
74  CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
75  if (i < j) {
76  setVal(j, i, val);
77  } else {
78  setVal(i, j, val);
79  }
80  }
81 
82  //! Set the lower bound between points i and j only if it is better than
83  //! previously existing value (i.e. the new value is larger)
84  inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
85  double val) {
86  if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
87  setLowerBound(i, j, val);
88  }
89  }
90 
91  //! Get the lower bound between points i and j
92  inline double getLowerBound(unsigned int i, unsigned int j) const {
93  URANGE_CHECK(i, d_nRows);
94  URANGE_CHECK(j, d_nCols);
95 
96  if (i < j) {
97  return getVal(j, i);
98  } else {
99  return getVal(i, j);
100  }
101  }
102 
103  //! Do a simple check of the current bounds - i.e. all lower bounds are
104  //! smaller than the existing upper bounds
105  inline bool checkValid() const {
106  unsigned int i, j;
107  for (i = 1; i < d_nRows; i++) {
108  for (j = 0; j < i; j++) {
109  if (getUpperBound(i, j) < getLowerBound(i, j)) {
110  return false;
111  }
112  }
113  }
114  return true;
115  }
116 };
117 
118 typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
119 } // namespace DistGeom
120 
121 #endif
RDNumeric::SquareMatrix
Definition: SquareMatrix.h:18
DistGeom::BoundsMatrix::getLowerBound
double getLowerBound(unsigned int i, unsigned int j) const
Get the lower bound between points i and j.
Definition: BoundsMatrix.h:92
RDKIT_DISTGEOMETRY_EXPORT
#define RDKIT_DISTGEOMETRY_EXPORT
Definition: export.h:164
CHECK_INVARIANT
#define CHECK_INVARIANT(expr, mess)
Definition: Invariant.h:101
DistGeom::BoundsMatrix::DATA_SPTR
boost::shared_array< double > DATA_SPTR
Definition: BoundsMatrix.h:30
DistGeom::BoundsMatrix::setLowerBound
void setLowerBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
Definition: BoundsMatrix.h:71
DistGeom::BoundsMatrix::setUpperBound
void setUpperBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
Definition: BoundsMatrix.h:50
DistGeom::BoundsMatrix::BoundsMatrix
BoundsMatrix(unsigned int N)
Definition: BoundsMatrix.h:32
DistGeom::BoundsMatrix::BoundsMatrix
BoundsMatrix(unsigned int N, DATA_SPTR data)
Definition: BoundsMatrix.h:34
DistGeom::BoundsMatrix::getUpperBound
double getUpperBound(unsigned int i, unsigned int j) const
Get the upper bound between points i and j.
Definition: BoundsMatrix.h:38
DistGeom::BoundsMatrix::setUpperBoundIfBetter
void setUpperBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition: BoundsMatrix.h:63
DistGeom::BoundsMatrix::checkValid
bool checkValid() const
Definition: BoundsMatrix.h:105
Invariant.h
DistGeom::BoundsMatPtr
boost::shared_ptr< BoundsMatrix > BoundsMatPtr
Definition: BoundsMatrix.h:118
DistGeom
Definition: BoundsMatrix.h:20
DistGeom::BoundsMatrix::setLowerBoundIfBetter
void setLowerBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition: BoundsMatrix.h:84
URANGE_CHECK
#define URANGE_CHECK(x, hi)
Definition: Invariant.h:142
RDNumeric
Definition: AlignPoints.h:18
SquareMatrix.h
DistGeom::BoundsMatrix
Class to store the distance bound.
Definition: BoundsMatrix.h:27
export.h