Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SpatialModel.h
Go to the documentation of this file.
1 
18 #ifndef INCLUDE_MOLASSEMBLER_DISTANCE_GEOMETRY_SPATIAL_MODEL_H
19 #define INCLUDE_MOLASSEMBLER_DISTANCE_GEOMETRY_SPATIAL_MODEL_H
20 
22 #include "Molassembler/Molecule.h"
23 #include "Molassembler/Graph.h"
26 
27 #include <unordered_map>
28 
29 namespace Scine {
30 namespace Molassembler {
31 namespace DistanceGeometry {
32 
39 class SpatialModel {
40 public:
44  struct ModelGraphWriter;
45 
47  template<unsigned size>
48  using BoundsMapType = std::unordered_map<
49  std::array<AtomIndex, size>,
52  std::array<AtomIndex, size>
53  >
54  >;
55 
57  using FixedPositionsMapType = std::unordered_map<AtomIndex, Utils::Position>;
58 
66  using BoundsMatrix = Eigen::MatrixXd;
67 
69  inline explicit BoundsMatrixHelper(AtomIndex size) : matrix(size, size) { matrix.setZero(); }
70 
71  void add(AtomIndex i, AtomIndex j, const ValueBounds& bounds);
72  void addMap(const BoundsMapType<2>& boundsMap);
73 
74  ValueBounds get(AtomIndex i, AtomIndex j) const;
75 
76  Eigen::MatrixXd matrix;
77  };
79 
82 
86  static constexpr double bondRelativeVariance = 0.01;
91  static constexpr double angleRelativeVariance = 0.02;
93  static constexpr double dihedralAbsoluteVariance = M_PI / 90; // ~ 2°
94 
96  static constexpr ValueBounds angleClampBounds {0.0, M_PI};
99 
100 /* Static functions */
106  static double modelDistance(AtomIndex i, AtomIndex j, const PrivateGraph& graph);
108  static double modelDistance(const BondIndex& bond, const PrivateGraph& graph);
109 
121  static std::vector<BondIndex> cycleConsistingOfExactly(
122  const std::vector<AtomIndex>& atoms,
123  const PrivateGraph& graph
124  );
125 
138  static boost::optional<ValueBounds> coneAngle(
139  const std::vector<AtomIndex>& baseConstituents,
140  const ValueBounds& coneHeightBounds,
141  const Graph& graph
142  );
143 
153  static double spiroCrossAngle(double alpha, double beta);
154 
168  const std::vector<AtomIndex>& siteAtomList,
169  AtomIndex placement,
170  const Graph& graph
171  );
172 
183  double centralValue,
184  double absoluteVariance
185  );
186 
195  static double smallestCycleDistortionMultiplier(
196  const AtomIndex i,
197  const Cycles& cycles
198  );
199 
200  /*
201  * @brief Generates a matrix of atom-pairwise distance bounds
202  *
203  * @complexity{@math{O(P_2 + P_3 + P_4)} where @math{P_i} is the number of
204  * distinct paths of length @math{i} in the graph. That should scale at least
205  * linearly in the number of vertices.}
206  *
207  * @param N size of the system
208  * @param fixedPositionbounds Distances to enforce due to fixed positions
209  * @param bondBounds Distances to enforce for bonds
210  * @param angleBounds Angle bounds to enforce on atom index triples
211  * @param dihedralBounds Dihedral bounds to enforce on atom index quadruplet
212  *
213  * @return A matrix of atom-pairwise distance bounds. Lower bounds are in the
214  * strict lower triangle of the matrix, upper bounds in the strict upper
215  * triangle.
216  */
218  unsigned N,
219  const BoundsMapType<2>& fixedPositionBounds,
220  const BoundsMapType<2>& bondBounds,
221  const BoundsMapType<3>& angleBounds,
222  const BoundsMapType<4>& dihedralBounds
223  );
224 
239  static double siteCentralAngle(
240  AtomIndex placement,
241  const Shapes::Shape& shape,
242  const RankingInformation& ranking,
243  const AtomStereopermutator::ShapeMap& shapeVertexMap,
244  const std::pair<SiteIndex, SiteIndex>& sites,
245  const PrivateGraph& inner
246  );
247 
249  static double siteCentralAngle(
250  const AtomStereopermutator& permutator,
251  const std::pair<SiteIndex, SiteIndex>& sites,
252  const PrivateGraph& inner
253  );
254 
267  const AtomStereopermutator& permutator,
268  const std::pair<SiteIndex, SiteIndex>& sites,
269  const double looseningMultiplier,
270  const PrivateGraph& inner
271  );
272 
287  const AtomStereopermutator::MinimalChiralConstraint& minimalConstraint,
288  const AtomStereopermutator& permutator,
289  const double looseningMultiplier
290  );
291 
302  static ValueBounds clamp(
303  ValueBounds bounds,
304  const ValueBounds& clampBounds
305  );
306 
317  const Molecule& molecule,
318  const Configuration& configuration
319  );
321 
324 
342  SpatialModel(
343  const Molecule& molecule,
344  const Configuration& configuration
345  );
347 
350 
359  std::array<AtomIndex, 2> bondIndices,
360  ValueBounds bounds
361  );
362 
374  std::array<AtomIndex, 3> angleIndices,
375  ValueBounds bounds
376  );
377 
388  std::array<AtomIndex, 4> dihedralIndices,
389  ValueBounds bounds
390  );
391 
408  const AtomStereopermutator& permutator,
409  const PrivateGraph& graph,
410  double looseningMultiplier,
411  const std::unordered_map<AtomIndex, Utils::Position>& fixedAngstromPositions,
412  bool forceChiralConstraintEmission
413  );
414 
429  const BondStereopermutator& permutator,
430  const AtomStereopermutator& stereopermutatorA,
431  const AtomStereopermutator& stereopermutatorB,
432  double looseningMultiplier,
433  const std::unordered_map<AtomIndex, Utils::Position>& fixedAngstromPositions
434  );
435 
437  const BondStereopermutator& permutator,
438  const std::pair<const AtomStereopermutator&, const AtomStereopermutator&>& atomStereopermutators,
439  const std::unordered_map<AtomIndex, Utils::Position>& fixedAngstromPositions
440  );
442 
445 
449  std::vector<ChiralConstraint> getChiralConstraints() const;
450 
455  std::vector<DihedralConstraint> getDihedralConstraints() const;
456 
472 
483  std::string dumpGraphviz() const;
484 
494  void writeGraphviz(const std::string& filename) const;
496 
497 private:
498  // Molecule closure
499  const Molecule& molecule_;
500 
509 
511  std::vector<ChiralConstraint> chiralConstraints_;
512  std::vector<DihedralConstraint> dihedralConstraints_;
513 
517  void addDefaultAngles_();
518 
525  void addDefaultDihedrals_();
526 
533 
535  void modelBondDistances_(
536  const FixedPositionsMapType& fixedAngstromPositions,
537  double looseningFactor
538  );
539 
541  void modelFlatCycles_(
542  const FixedPositionsMapType& fixedAngstromPositions,
543  double looseningFactor
544  );
545 
587  void modelSpirocenters_(
588  const FixedPositionsMapType& fixedAngstromPositions
589  );
591 };
592 
593 } // namespace DistanceGeometry
594 } // namespace Molassembler
595 } // namespace Scine
596 
597 #endif
std::array< boost::optional< SiteIndex >, 4 > MinimalChiralConstraint
Site index sequence defining a chiral constraint. If a site index is None, then it denotes the positi...
Definition: AtomStereopermutator.h:95
Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators.
Definition: Molecule.h:73
SpatialModel(const Molecule &molecule, const Configuration &configuration)
Model a molecule into internal coordinate bounds stored internally.
Ranking data of substituents around a central vertex.
Definition: RankingInformation.h:23
static std::vector< BondIndex > cycleConsistingOfExactly(const std::vector< AtomIndex > &atoms, const PrivateGraph &graph)
Tries to find a cycle that consists of a particular set of atoms.
static constexpr double angleRelativeVariance
Relative angle variance.
Definition: SpatialModel.h:91
static double siteCentralAngle(AtomIndex placement, const Shapes::Shape &shape, const RankingInformation &ranking, const AtomStereopermutator::ShapeMap &shapeVertexMap, const std::pair< SiteIndex, SiteIndex > &sites, const PrivateGraph &inner)
Determines the central value of the angle between AtomStereopermutator sites.
Drives a PRNG.
Definition: Prng.h:24
A configuration object for distance geometry runs with sane defaults.
Definition: Conformers.h:75
BoundsMapType< 4 > dihedralBounds_
Dihedral value bounds on index quadruplets.
Definition: SpatialModel.h:508
static ValueBounds siteDistanceFromCenter(const std::vector< AtomIndex > &siteAtomList, AtomIndex placement, const Graph &graph)
Calculates bounds on the distance of a (possibly haptic) ligand site to a central index...
ShapeResult shape(const PositionCollection &normalizedPositions, Shape shape)
Forwarding function to calculate the continuous shape measure.
void addAtomStereopermutatorInformation(const AtomStereopermutator &permutator, const PrivateGraph &graph, double looseningMultiplier, const std::unordered_map< AtomIndex, Utils::Position > &fixedAngstromPositions, bool forceChiralConstraintEmission)
Adds angle information to the internal coordinate bounds and collects chiral constraints.
Represents the connectivity of atoms of a molecule.
Definition: Graph.h:57
static constexpr ValueBounds angleClampBounds
Defines clamping bounds on angles.
Definition: SpatialModel.h:96
Class performing spatial modeling of molecules.
Definition: SpatialModel.h:39
BoundsMapType< 2 > constraints_
Constraints by fixed positions.
Definition: SpatialModel.h:502
Wrapper class to make working with RDL in C++ more pleasant.
Definition: Cycles.h:44
Handles the steric permutation of substituents of a non-terminal central atom.
Definition: AtomStereopermutator.h:79
std::unordered_map< AtomIndex, Utils::Position > FixedPositionsMapType
Type used to store fixed positions in angstrom.
Definition: SpatialModel.h:57
static const ValueBounds defaultDihedralBounds
Defines the range (-π,π] using std::nextafter (not constexpr)
Definition: SpatialModel.h:98
static void checkFixedPositionsPreconditions(const Molecule &molecule, const Configuration &configuration)
Ensures that the preconditions for fixed positions in Distance Geometry detailed in the Configuration...
Handle arrangements of substituents at corners of an atom-centered shape.
std::string dumpGraphviz() const
Generates a string graphviz representation of the modeled molecule.
void setDihedralBoundsIfEmpty(std::array< AtomIndex, 4 > dihedralIndices, ValueBounds bounds)
Adds the dihedral bounds to the model if unset.
Molecule class interface.
static constexpr double dihedralAbsoluteVariance
Absolute dihedral angle variance in radians.
Definition: SpatialModel.h:93
Handles specific relative arrangements of two atom stereopermutators joined by a bond.
Definition: BondStereopermutator.h:46
void modelSpirocenters_(const FixedPositionsMapType &fixedAngstromPositions)
Adds spirocenter modelling to the data set.
static double modelDistance(AtomIndex i, AtomIndex j, const PrivateGraph &graph)
Models the equilibrium distance between two bonded atoms.
std::vector< DihedralConstraint > getDihedralConstraints() const
Yields all collected dihedral constraints.
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
std::vector< std::vector< AtomIndex >> sites(const PrivateGraph &graph, AtomIndex placement, const std::vector< AtomIndex > &excludeAdjacents={})
Differentiate adjacent vertices of a central index into sites.
std::vector< ChiralConstraint > chiralConstraints_
Chiral constraints.
Definition: SpatialModel.h:511
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
static ValueBounds modelSiteAngleBounds(const AtomStereopermutator &permutator, const std::pair< SiteIndex, SiteIndex > &sites, const double looseningMultiplier, const PrivateGraph &inner)
Models bounds on the angle between AtomStereopermutator sites.
static double smallestCycleDistortionMultiplier(const AtomIndex i, const Cycles &cycles)
Idealization strictness loosening multiplier due to small cycles.
BoundsMapType< 3 > angleBounds_
Angle value bounds on index triples.
Definition: SpatialModel.h:506
std::unordered_map< std::array< AtomIndex, size >, ValueBounds, boost::hash< std::array< AtomIndex, size > > > BoundsMapType
ValueBounds container for various internal coordinates.
Definition: SpatialModel.h:54
static ValueBounds makeBoundsFromCentralValue(double centralValue, double absoluteVariance)
Yields central value plus/minus some absolute variance bounds.
static ValueBounds clamp(ValueBounds bounds, const ValueBounds &clampBounds)
Analogous to C++17&#39;s clamp, reduces ValueBounds to the maximal extent specified by some clamping boun...
BoundsMatrix makePairwiseBounds() const
Generate unsmoothed atom-pairwise distance bounds matrix.
void addDefaultDihedrals_()
Adds [0, π] default dihedrals to the model (of connected sequences)
std::vector< ChiralConstraint > getChiralConstraints() const
Yields all collected chiral constraints.
Type used to refer to particular bonds. Orders first &lt; second.
Definition: Types.h:54
unsigned size(const Shape shape)
Fetch the number of vertices of a shape.
Interface class for the molecular graph.
void setAngleBoundsIfEmpty(std::array< AtomIndex, 3 > angleIndices, ValueBounds bounds)
Adds angle bounds to the model if unset.
BoundsMapType< 2 > bondBounds_
Bond distance value bounds on index pairs.
Definition: SpatialModel.h:504
Data class for bounded values.
Definition: ValueBounds.h:23
WideHashType hash(AtomEnvironmentComponents bitmask, Utils::ElementType elementType, const std::vector< BondInformation > &sortedBonds, const boost::optional< Shapes::Shape > &shapeOptional, const boost::optional< unsigned > &assignedOptional)
Convolutes the atom&#39;s element type and bonds into an unsigned integer.
Shape
Enumeration of all contained symmetry names.
Definition: Shapes.h:28
void modelBondDistances_(const FixedPositionsMapType &fixedAngstromPositions, double looseningFactor)
Add bond distances to the underlying model.
void modelFlatCycles_(const FixedPositionsMapType &fixedAngstromPositions, double looseningFactor)
Add precise information to the model for cycles that are flat.
void instantiateMissingAtomStereopermutators_(Random::Engine &engine)
static ChiralConstraint makeChiralConstraint(const AtomStereopermutator::MinimalChiralConstraint &minimalConstraint, const AtomStereopermutator &permutator, const double looseningMultiplier)
Creates a volume-specific chiral constraint from a list of.
static double spiroCrossAngle(double alpha, double beta)
Calculates the cross angle between opposite cycle atoms in a spirocenter.
Data struct representing a chiral constraint.
Definition: DistanceGeometry.h:32
void addDefaultAngles_()
Adds [0, π] default angle bounds for all bonded atom triples.
Owning class storing all stereopermutators in a molecule.
static constexpr double bondRelativeVariance
Relative bond distance variance 0.0x mean x% variance. Must fulfill 0 &lt; x &lt;&lt; 1.
Definition: SpatialModel.h:86
Class storing atom-pairwise distance bounds.
void writeGraphviz(const std::string &filename) const
Writes a graphviz representation of a modeled molecule to a file.
bool modelPartiallyFixedBond(const BondStereopermutator &permutator, const std::pair< const AtomStereopermutator &, const AtomStereopermutator & > &atomStereopermutators, const std::unordered_map< AtomIndex, Utils::Position > &fixedAngstromPositions)
Sets bond bounds to exact value bounds if unset.
void addBondStereopermutatorInformation(const BondStereopermutator &permutator, const AtomStereopermutator &stereopermutatorA, const AtomStereopermutator &stereopermutatorB, double looseningMultiplier, const std::unordered_map< AtomIndex, Utils::Position > &fixedAngstromPositions)
Adds dihedral information to the internal coordinate bounds and collects dihedral constraints...
void setBondBoundsIfEmpty(std::array< AtomIndex, 2 > bondIndices, ValueBounds bounds)
Sets bond bounds to exact value bounds if unset.
Eigen::MatrixXd BoundsMatrix
Type used to represent atom-pairwise distance bounds constructed from bounds on internal coordinates...
Definition: SpatialModel.h:66
static boost::optional< ValueBounds > coneAngle(const std::vector< AtomIndex > &baseConstituents, const ValueBounds &coneHeightBounds, const Graph &graph)
Tries to calculate the cone angle for a possibly haptic ligand site.