RDKit: BoundsMatrix.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
BoundsMatrix.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2006 Greg Landrum and other RDKit contributors
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 <iomanip>
17#include <Numerics/SquareMatrix.h>
18
19 namespace DistGeom {
20//! Class to store the distance bound
21/*!
22 Basically a N by N matrix
23 with lower distance bounds on the lower traingle and upper bounds in the upper
24 triangle
25*/
26 class RDKIT_DISTGEOMETRY_EXPORT BoundsMatrix
27 : public RDNumeric::SquareMatrix<double> {
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 if (i < j) {
39 return getVal(i, j);
40 } else {
41 return getVal(j, i);
42 }
43 }
44
45 //! Set the lower bound between points i and j
46 inline void setUpperBound(unsigned int i, unsigned int j, double val) {
47 CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
48 if (i < j) {
49 setVal(i, j, val);
50 } else {
51 setVal(j, i, val);
52 }
53 }
54
55 //! Set the upper bound between points i and j only if it is better than
56 //! previously existing value (i.e. the new value is smaller)
57 inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
58 double val) {
59 if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
60 setUpperBound(i, j, val);
61 }
62 }
63
64 //! Set the lower bound between points i and j
65 inline void setLowerBound(unsigned int i, unsigned int j, double val) {
66 CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
67 if (i < j) {
68 setVal(j, i, val);
69 } else {
70 setVal(i, j, val);
71 }
72 }
73
74 //! Set the lower bound between points i and j only if it is better than
75 //! previously existing value (i.e. the new value is larger)
76 inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
77 double val) {
78 if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
79 setLowerBound(i, j, val);
80 }
81 }
82
83 //! Get the lower bound between points i and j
84 inline double getLowerBound(unsigned int i, unsigned int j) const {
85 if (i < j) {
86 return getVal(j, i);
87 } else {
88 return getVal(i, j);
89 }
90 }
91
92 //! Do a simple check of the current bounds - i.e. all lower bounds are
93 //! smaller than the existing upper bounds
94 inline bool checkValid() const {
95 unsigned int i, j;
96 for (i = 1; i < d_nRows; i++) {
97 for (j = 0; j < i; j++) {
98 if (getUpperBound(i, j) < getLowerBound(i, j)) {
99 return false;
100 }
101 }
102 }
103 return true;
104 }
105};
106
107 typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
108} // namespace DistGeom
109
110#endif
Invariant.h
CHECK_INVARIANT
#define CHECK_INVARIANT(expr, mess)
Definition Invariant.h:100
SquareMatrix.h
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:46
DistGeom::BoundsMatrix::getUpperBound
double getUpperBound(unsigned int i, unsigned int j) const
Get the upper bound between points i and j.
Definition BoundsMatrix.h:37
DistGeom::BoundsMatrix::getLowerBound
double getLowerBound(unsigned int i, unsigned int j) const
Get the lower bound between points i and j.
Definition BoundsMatrix.h:84
DistGeom::BoundsMatrix::BoundsMatrix
BoundsMatrix(unsigned int N)
Definition BoundsMatrix.h:31
DistGeom::BoundsMatrix::BoundsMatrix
BoundsMatrix(unsigned int N, DATA_SPTR data)
Definition BoundsMatrix.h:33
DistGeom::BoundsMatrix::setLowerBoundIfBetter
void setLowerBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition BoundsMatrix.h:76
DistGeom::BoundsMatrix::setUpperBoundIfBetter
void setUpperBoundIfBetter(unsigned int i, unsigned int j, double val)
Definition BoundsMatrix.h:57
DistGeom::BoundsMatrix::DATA_SPTR
boost::shared_array< double > DATA_SPTR
Definition BoundsMatrix.h:29
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:65
DistGeom::BoundsMatrix::checkValid
bool checkValid() const
Definition BoundsMatrix.h:94
RDNumeric::Matrix< double >::getVal
virtual double getVal(unsigned int i, unsigned int j) const
Definition Matrix.h:86
RDNumeric::Matrix< double >::d_nRows
unsigned int d_nRows
Definition Matrix.h:245
RDNumeric::Matrix< double >::setVal
virtual void setVal(unsigned int i, unsigned int j, double val)
Definition Matrix.h:94
RDNumeric::SquareMatrix
Definition SquareMatrix.h:18
RDNumeric::SquareMatrix< double >::SquareMatrix
SquareMatrix()
Definition SquareMatrix.h:21
export.h
RDKIT_DISTGEOMETRY_EXPORT
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:137
DistGeom
Definition BoundsMatrix.h:19
DistGeom::BoundsMatPtr
boost::shared_ptr< BoundsMatrix > BoundsMatPtr
Definition BoundsMatrix.h:107
RDNumeric
Definition AlignPoints.h:18