File: BoundsMatrix.h

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (120 lines) | stat: -rw-r--r-- 3,429 bytes parent folder | download
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
112
113
114
115
116
117
118
119
120
//
//  Copyright (C) 2004-2006 Rational Discovery LLC
//
//   @@ 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 {
    URANGE_CHECK(i, d_nRows);
    URANGE_CHECK(j, d_nCols);

    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) {
    URANGE_CHECK(i, d_nRows);
    URANGE_CHECK(j, d_nCols);
    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) {
    URANGE_CHECK(i, d_nRows);
    URANGE_CHECK(j, d_nCols);
    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 {
    URANGE_CHECK(i, d_nRows);
    URANGE_CHECK(j, d_nCols);

    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;
}

#endif