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