Molassembler  1.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 outcome = OUTCOME_V2_NAMESPACE;
25 
26 namespace DistanceGeometry {
27 
29 public:
30  static constexpr double defaultLower = 0.0;
31  static constexpr double defaultUpper = 100.0;
32 
35  static inline double& lowerBound(Eigen::Ref<Eigen::MatrixXd> matrix, const AtomIndex i, const AtomIndex j) {
36  if(i < j) {
37  return matrix(j, i);
38  }
39 
40  return matrix(i, j);
41  }
42 
43  static inline double& upperBound(Eigen::Ref<Eigen::MatrixXd> matrix, const AtomIndex i, const AtomIndex j) {
44  if(i < j) {
45  return matrix(i, j);
46  }
47 
48  return matrix(j, i);
49  }
50 
55  static void smooth(Eigen::Ref<Eigen::MatrixXd> matrix);
57 
60  using BoundsMatrix = Eigen::MatrixXd;
62 
67 
69  explicit DistanceBoundsMatrix(long unsigned N);
70 
72  explicit DistanceBoundsMatrix(Eigen::MatrixXd matrix);
73 
79  template<typename PrivateGraph>
81  const PrivateGraph& inner,
82  BoundsMatrix bounds
83  ) : matrix_(std::move(bounds)) {
84  // Populate the lower bounds if no explicit information is present
85  const AtomIndex N = inner.N();
86  for(AtomIndex i = 0; i < N - 1; ++i) {
87  for(AtomIndex j = i + 1; j < N; ++j) {
88  // i < j in all cases -> lower bound is (j, i), upper bound is (i, j)
89  if(matrix_(j, i) == 0) {
90  matrix_(j, i) = (
93  );
94  }
95 
96  // Ensure upper bound has a default value for Floyd's algorithm
97  if(matrix_(i, j) == 0.0) {
98  matrix_(i, j) = defaultUpper;
99  }
100  }
101  }
102 
103  assert(boundInconsistencies() == 0);
104  }
106 
109  bool setUpperBound(AtomIndex i, AtomIndex j, double newUpperBound);
110  bool setLowerBound(AtomIndex i, AtomIndex j, double newLowerBound);
111 
113  void smooth();
115 
118 
122  inline double upperBound(AtomIndex i, AtomIndex j) const {
123  if(i < j) {
124  return matrix_(i, j);
125  }
126 
127  return matrix_(j, i);
128  }
129 
134  inline double lowerBound(AtomIndex i, AtomIndex j) const {
135  if(i < j) {
136  return matrix_(j, i);
137  }
138 
139  return matrix_(i, j);
140  }
141 
146  unsigned boundInconsistencies() const;
147 
152  const Eigen::MatrixXd& access() const;
153 
161  outcome::result<Eigen::MatrixXd> makeDistanceMatrix(
162  Random::Engine& engine,
163  Partiality partiality = Partiality::All
164  ) const noexcept;
165 
170  Eigen::MatrixXd makeSquaredBoundsMatrix() const;
171 
176  unsigned N() const;
178 
179 private:
180  Eigen::MatrixXd matrix_;
181 
182  inline double& lowerBound_(const AtomIndex i, const AtomIndex j) {
183  return matrix_(
184  std::max(i, j),
185  std::min(i, j)
186  );
187  }
188 
189  inline double& upperBound_(const AtomIndex i, const AtomIndex j) {
190  return matrix_(
191  std::min(i, j),
192  std::max(i, j)
193  );
194  }
195 
196 };
197 
198 } // namespace DistanceGeometry
199 } // namespace Molassembler
200 } // namespace Scine
201 
202 #endif
bool setUpperBound(AtomIndex i, AtomIndex j, double newUpperBound)
Smoothes the underlying matrix using smooth(Eigen::Ref&lt;Eigen::MatrixXd&gt;)
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:122
Vertex N() const
Number of vertices in the graph.
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:35
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:43
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
unsigned boundInconsistencies() const
Checks for cases in which the lower bound is greater than the upper bound.
outcome::result< Eigen::MatrixXd > makeDistanceMatrix(Random::Engine &engine, Partiality partiality=Partiality::All) const noexcept
Generate a distance matrix.
DistanceBoundsMatrix(const PrivateGraph &inner, BoundsMatrix bounds)
Constructs a bounds matrix from a graph and a bounds matrix.
Definition: DistanceBoundsMatrix.h:80
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:134
Interface for the generation of new conformations of Molecules.
Partiality
Limit triangle inequality bounds smoothing to a subset of all atoms.
Definition: Conformers.h:44