File: BoundsMatrix.h

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (111 lines) | stat: -rw-r--r-- 3,225 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
//  Copyright (C) 2004-2006 Greg Landrum and other RDKit contributors
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RD_BOUNDS_MATRIX_H
#define RD_BOUNDS_MATRIX_H

#include <RDGeneral/Invariant.h>
#include <boost/smart_ptr.hpp>
#include <iostream>
#include <iomanip>
#include <Numerics/SquareMatrix.h>

namespace DistGeom {
//! Class to store the distance bound
/*!
  Basically a N by N matrix
  with lower distance bounds on the lower traingle and upper bounds in the upper
  triangle
*/
class RDKIT_DISTGEOMETRY_EXPORT BoundsMatrix
    : public RDNumeric::SquareMatrix<double> {
 public:
  typedef boost::shared_array<double> DATA_SPTR;

  explicit BoundsMatrix(unsigned int N)
      : RDNumeric::SquareMatrix<double>(N, 0.0) {}
  BoundsMatrix(unsigned int N, DATA_SPTR data)
      : RDNumeric::SquareMatrix<double>(N, data) {}

  //! Get the upper bound between points i and j
  inline double getUpperBound(unsigned int i, unsigned int j) const {
    if (i < j) {
      return getVal(i, j);
    } else {
      return getVal(j, i);
    }
  }

  //! Set the lower bound between points i and j
  inline void setUpperBound(unsigned int i, unsigned int j, double val) {
    CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
    if (i < j) {
      setVal(i, j, val);
    } else {
      setVal(j, i, val);
    }
  }

  //! Set the upper bound between points i and j only if it is better than
  //! previously existing value (i.e. the new value is smaller)
  inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
                                    double val) {
    if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
      setUpperBound(i, j, val);
    }
  }

  //! Set the lower bound between points i and j
  inline void setLowerBound(unsigned int i, unsigned int j, double val) {
    CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
    if (i < j) {
      setVal(j, i, val);
    } else {
      setVal(i, j, val);
    }
  }

  //! Set the lower bound between points i and j only if it is better than
  //! previously existing value (i.e. the new value is larger)
  inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
                                    double val) {
    if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
      setLowerBound(i, j, val);
    }
  }

  //! Get the lower bound between points i and j
  inline double getLowerBound(unsigned int i, unsigned int j) const {
    if (i < j) {
      return getVal(j, i);
    } else {
      return getVal(i, j);
    }
  }

  //! Do a simple check of the current bounds - i.e. all lower bounds are
  //! smaller than the existing upper bounds
  inline bool checkValid() const {
    unsigned int i, j;
    for (i = 1; i < d_nRows; i++) {
      for (j = 0; j < i; j++) {
        if (getUpperBound(i, j) < getLowerBound(i, j)) {
          return false;
        }
      }
    }
    return true;
  }
};

typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
}  // namespace DistGeom

#endif