Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DistanceBoundsMatrix.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_DISTANCE_GEOMETRY_DISTANCE_BOUNDS_MATRIX_H
9 #define INCLUDE_MOLASSEMBLER_DISTANCE_GEOMETRY_DISTANCE_BOUNDS_MATRIX_H
10 
11 #include <Eigen/Core>
12 
16 
17 namespace Scine {
18 namespace Molassembler {
19 
20 namespace Random {
21 class Engine;
22 } // namespace Random
23 
24 namespace DistanceGeometry {
25 
27 public:
28  static constexpr double defaultLower = 0.0;
29  static constexpr double defaultUpper = 100.0;
30 
33  static inline double& lowerBound(Eigen::Ref<Eigen::MatrixXd> matrix, const AtomIndex i, const AtomIndex j) {
34  if(i < j) {
35  return matrix(j, i);
36  }
37 
38  return matrix(i, j);
39  }
40 
41  static inline double& upperBound(Eigen::Ref<Eigen::MatrixXd> matrix, const AtomIndex i, const AtomIndex j) {
42  if(i < j) {
43  return matrix(i, j);
44  }
45 
46  return matrix(j, i);
47  }
48 
53  static void smooth(Eigen::Ref<Eigen::MatrixXd> matrix);
55 
58  using BoundsMatrix = Eigen::MatrixXd;
60 
65 
67  explicit DistanceBoundsMatrix(long unsigned N);
68 
70  explicit DistanceBoundsMatrix(Eigen::MatrixXd matrix);
71 
77  template<typename PrivateGraph>
79  const PrivateGraph& inner,
80  BoundsMatrix bounds
81  ) : matrix_(std::move(bounds)) {
82  // Populate the lower bounds if no explicit information is present
83  const AtomIndex N = inner.V();
84  for(AtomIndex i = 0; i < N - 1; ++i) {
85  for(AtomIndex j = i + 1; j < N; ++j) {
86  // i < j in all cases -> lower bound is (j, i), upper bound is (i, j)
87  if(matrix_(j, i) == 0) {
88  matrix_(j, i) = (
91  );
92  }
93 
94  // Ensure upper bound has a default value for Floyd's algorithm
95  if(matrix_(i, j) == 0.0) {
96  matrix_(i, j) = defaultUpper;
97  }
98  }
99  }
100 
101  assert(boundInconsistencies() == 0);
102  }
104 
107  bool setUpperBound(AtomIndex i, AtomIndex j, double newUpperBound);
108  bool setLowerBound(AtomIndex i, AtomIndex j, double newLowerBound);
109 
111  void smooth();
113 
116 
120  inline double upperBound(AtomIndex i, AtomIndex j) const {
121  if(i < j) {
122  return matrix_(i, j);
123  }
124 
125  return matrix_(j, i);
126  }
127 
132  inline double lowerBound(AtomIndex i, AtomIndex j) const {
133  if(i < j) {
134  return matrix_(j, i);
135  }
136 
137  return matrix_(i, j);
138  }
139 
144  unsigned boundInconsistencies() const;
145 
150  const Eigen::MatrixXd& access() const;
151 
159  Result<Eigen::MatrixXd> makeDistanceMatrix(
160  Random::Engine& engine,
161  Partiality partiality = Partiality::All
162  ) const noexcept;
163 
168  Eigen::MatrixXd makeSquaredBoundsMatrix() const;
169 
174  unsigned N() const;
176 
177 private:
178  Eigen::MatrixXd matrix_;
179 
180  inline double& lowerBound_(const AtomIndex i, const AtomIndex j) {
181  return matrix_(
182  std::max(i, j),
183  std::min(i, j)
184  );
185  }
186 
187  inline double& upperBound_(const AtomIndex i, const AtomIndex j) {
188  return matrix_(
189  std::min(i, j),
190  std::max(i, j)
191  );
192  }
193 
194 };
195 
196 } // namespace DistanceGeometry
197 } // namespace Molassembler
198 } // namespace Scine
199 
200 #endif
bool setUpperBound(AtomIndex i, AtomIndex j, double newUpperBound)
Smoothes the underlying matrix using smooth(Eigen::Ref&lt;Eigen::MatrixXd&gt;)
Vertex V() const
Number of vertices in the graph.
Drives a PRNG.
Definition: Prng.h:24
double vdwRadius(Utils::ElementType elementType)
Accessor function to fetch the vdw radius directly from elementData.
Eigen::MatrixXd makeSquaredBoundsMatrix() const
Squares all bounds and returns a new matrix.
const Eigen::MatrixXd & access() const
Nonmodifiable access to bounds matrix.
double upperBound(AtomIndex i, AtomIndex j) const
Access to upper bound of unordered indices.
Definition: DistanceBoundsMatrix.h:120
Element type information classes.
static double & lowerBound(Eigen::Ref< Eigen::MatrixXd > matrix, const AtomIndex i, const AtomIndex j)
Uses Floyd&#39;s algorithm to smooth the matrix.
Definition: DistanceBoundsMatrix.h:33
Perform smoothing after all distance choices.
void smooth()
Smoothes the underlying matrix using smooth(Eigen::Ref&lt;Eigen::MatrixXd&gt;)
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
bool setLowerBound(AtomIndex i, AtomIndex j, double newLowerBound)
Smoothes the underlying matrix using smooth(Eigen::Ref&lt;Eigen::MatrixXd&gt;)
unsigned N() const
Yields the number of particles.
static double & upperBound(Eigen::Ref< Eigen::MatrixXd > matrix, const AtomIndex i, const AtomIndex j)
Uses Floyd&#39;s algorithm to smooth the matrix.
Definition: DistanceBoundsMatrix.h:41
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:26
unsigned boundInconsistencies() const
Checks for cases in which the lower bound is greater than the upper bound.
DistanceBoundsMatrix(const PrivateGraph &inner, BoundsMatrix bounds)
Constructs a bounds matrix from a graph and a bounds matrix.
Definition: DistanceBoundsMatrix.h:78
Result< Eigen::MatrixXd > makeDistanceMatrix(Random::Engine &engine, Partiality partiality=Partiality::All) const noexcept
Generate a distance matrix.
Data struct to store chiral constraints for DG.
Utils::ElementType & elementType(Vertex a)
Fetches the element type of a vertex.
double lowerBound(AtomIndex i, AtomIndex j) const
Access to lower bound of unordered indices.
Definition: DistanceBoundsMatrix.h:132
Interface for the generation of new conformations of Molecules.
Partiality
Limit triangle inequality bounds smoothing to a subset of all atoms.
Definition: Conformers.h:42