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