Molassembler  3.0.1
Molecule graph and conformer library
DirectedConformerGenerator.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_DIRECTED_CONFORMER_GENERATOR_H
9 #define INCLUDE_MOLASSEMBLER_DIRECTED_CONFORMER_GENERATOR_H
10 
13 #include "Molassembler/Options.h"
14 
15 #include "boost/variant/variant_fwd.hpp"
16 
17 #include <unordered_map>
18 
19 namespace Scine {
20 namespace Utils {
21 class AtomCollection;
22 } // namespace Utils
23 
24 namespace Molassembler {
25 
26 class Molecule;
27 
88 class MASM_EXPORT DirectedConformerGenerator {
89 public:
93  using BondList = std::vector<BondIndex>;
100  using DecisionList = std::vector<std::uint8_t>;
101 
103  constexpr static std::uint8_t unknownDecision = std::numeric_limits<std::uint8_t>::max();
104 
105  //* @brief Reason why a bond is ignored
106  enum class IgnoreReason {
108  AtomStereopermutatorPreconditionsUnmet,
110  HasAssignedBondStereopermutator,
112  HasTerminalConstitutingAtom,
150  InCycle,
154  IsEtaBond,
158  RotationIsIsotropic
159  };
160 
161  struct Relabeler;
163 
166 
184  static boost::variant<IgnoreReason, BondStereopermutator> considerBond(
185  const BondIndex& bondIndex,
186  const Molecule& molecule,
188  );
189 
219  static unsigned distance(
220  const DecisionList& a,
221  const DecisionList& b,
222  const DecisionList& bounds
223  );
225 
228 
246  Molecule molecule,
248  const BondList& bondsToConsider = {}
249  );
251 
255  DirectedConformerGenerator& operator = (DirectedConformerGenerator&& other) noexcept;
257  DirectedConformerGenerator& operator = (const DirectedConformerGenerator& other) = delete;
260 
263 
282 
293  bool insert(const DecisionList& decisionList);
294 
303  bool contains(const DecisionList& decisionList) const;
305 
310 
318  const BondList& bondList() const;
319 
330  unsigned decisionListSetSize() const;
331 
339  unsigned idealEnsembleSize() const;
340 
353  Result<Utils::PositionCollection> generateRandomConformation(
354  const DecisionList& decisionList,
357  ) const;
358 
369  Result<Utils::PositionCollection> generateConformation(
370  const DecisionList& decisionList,
371  unsigned seed,
374  ) const;
375 
380  Molecule conformationMolecule(const DecisionList& decisionList) const;
381 
403  const Utils::AtomCollection& atomCollection,
405  ) const;
406 
424  const Utils::PositionCollection& positions,
426  ) const;
427 
430  EnumerationSettings() : configuration() {}
431 
433  unsigned dihedralRetries = 3;
438  };
439 
458  void enumerate(
459  std::function<void(const DecisionList&, Utils::PositionCollection)> callback,
460  unsigned seed,
461  const EnumerationSettings& settings = {}
462  );
463 
486  std::function<void(const DecisionList&, Utils::PositionCollection)> callback,
487  const EnumerationSettings& settings = {}
488  );
489 
492 
497  [[deprecated]]
498  std::vector<int> binMidpointIntegers(const DecisionList& decision) const;
499 
501  std::vector<std::pair<int, int>> binBounds(const DecisionList& decision) const;
503 
504 private:
505  class Impl;
506  std::unique_ptr<Impl> pImpl_;
507 };
508 
522  struct DihedralInfo {
523  std::vector<AtomIndex> is;
524  AtomIndex j;
525  AtomIndex k;
526  std::vector<AtomIndex> ls;
527  unsigned symmetryOrder;
528  };
529  using Interval = std::pair<double, double>;
530  using Intervals = std::vector<Interval>;
532 
538  static Intervals densityBins(
539  const std::vector<double>& dihedrals,
540  double delta,
541  unsigned symmetryOrder = 1
542  );
543 
544  static std::pair<double, double> makeBounds(double phi, double tolerance);
545  static std::pair<int, int> integerBounds(const std::pair<double, double>& bounds);
546 
558 
560  std::vector<double> add(const Utils::PositionCollection& positions);
561 
567  std::vector<Intervals> bins(double delta=M_PI / 6) const;
568 
578  std::vector<std::vector<unsigned>> binIndices(
579  const std::vector<Intervals>& allBins
580  ) const;
581 
583  std::vector<std::vector<int>> binMidpointIntegers(
584  const std::vector<std::vector<unsigned>>& binIndices,
585  const std::vector<Intervals>& allBins
586  ) const;
587 
589  std::vector<
590  std::vector<std::pair<int, int>>
592  const std::vector<std::vector<unsigned>>& binIndices,
593  const std::vector<Intervals>& allBins
594  ) const;
595 
598  std::vector<DihedralInfo> sequences;
599  std::vector<std::vector<double>> observedDihedrals;
601 };
602 
603 } // namespace Molassembler
604 } // namespace Scine
605 
606 #endif
Handle rotational arrangements of adjacent atom-centered shapes.
Interface for the generation of new conformations of Molecules.
Centralizes the main customization points of the library's behavior.
FittingMode
Differentiates how viable assignments are chosen during fitting.
Definition: BondStereopermutator.h:67
@ Nearest
Choose whichever assignment best represents the geometry directly.
@ Thresholded
Positions must be close to the idealized assignment geometry.
Alignment
How dihedrals are aligned in the generation of stereopermutations.
Definition: BondStereopermutator.h:53
@ Staggered
At least one pair of substituents are staggered along the axis.
Definition: DirectedConformerGeneratorImpl.h:19
Helper type for directed conformer generation.
Definition: DirectedConformerGenerator.h:88
void enumerateRandom(std::function< void(const DecisionList &, Utils::PositionCollection)> callback, const EnumerationSettings &settings={})
Enumerate all conformers of the captured molecule.
DecisionList getDecisionList(const Utils::PositionCollection &positions, BondStereopermutator::FittingMode mode=BondStereopermutator::FittingMode::Thresholded) const
Infer a decision list for relevant bonds from positional information only.
bool contains(const DecisionList &decisionList) const
Checks whether a DecisionList is part of the underlying set.
Result< Utils::PositionCollection > generateRandomConformation(const DecisionList &decisionList, const DistanceGeometry::Configuration &configuration=DistanceGeometry::Configuration {}, BondStereopermutator::FittingMode fitting=BondStereopermutator::FittingMode::Nearest) const
Try to generate a conformer for a particular decision list.
Molecule conformationMolecule(const DecisionList &decisionList) const
Yields a molecule reference for a particular decision list.
DirectedConformerGenerator(Molecule molecule, BondStereopermutator::Alignment alignment=BondStereopermutator::Alignment::Staggered, const BondList &bondsToConsider={})
Constructor.
std::vector< std::pair< int, int > > binBounds(const DecisionList &decision) const
Relabels a DecisionList into the bounds of its bin.
BondStereopermutator::Alignment alignment() const
Get alignment with which this generator was instantiated with.
std::vector< std::uint8_t > DecisionList
Type used to represent assignments at bonds.
Definition: DirectedConformerGenerator.h:100
bool insert(const DecisionList &decisionList)
Adds a decision list to the underlying set-like data structure.
static unsigned distance(const DecisionList &a, const DecisionList &b, const DecisionList &bounds)
Calculates a distance metric between two decision lists for dihedral permutations.
std::vector< BondIndex > BondList
Type used to represent the list of bonds relevant to directed conformer generation.
Definition: DirectedConformerGenerator.h:93
IgnoreReason
Type used to represent the list of bonds relevant to directed conformer generation.
Definition: DirectedConformerGenerator.h:106
Result< Utils::PositionCollection > generateConformation(const DecisionList &decisionList, unsigned seed, const DistanceGeometry::Configuration &configuration=DistanceGeometry::Configuration {}, BondStereopermutator::FittingMode fitting=BondStereopermutator::FittingMode::Nearest) const
Try to generate a conformer for a particular decision list.
void enumerate(std::function< void(const DecisionList &, Utils::PositionCollection)> callback, unsigned seed, const EnumerationSettings &settings={})
Enumerate all conformers of the captured molecule.
static boost::variant< IgnoreReason, BondStereopermutator > considerBond(const BondIndex &bondIndex, const Molecule &molecule, BondStereopermutator::Alignment alignment=BondStereopermutator::Alignment::Staggered)
Decide whether to consider a bond's dihedral values for directed conformer generation or not.
std::vector< int > binMidpointIntegers(const DecisionList &decision) const
unsigned idealEnsembleSize() const
Number of conformers needed for full ensemble.
const BondList & bondList() const
Accessor for list of relevant bonds.
unsigned decisionListSetSize() const
Number of conformer decision lists stored in the underlying set-like data structure.
DecisionList getDecisionList(const Utils::AtomCollection &atomCollection, BondStereopermutator::FittingMode mode=BondStereopermutator::FittingMode::Nearest) const
Infer a decision list for relevant bonds from an atom collection.
Relabeler relabeler() const
Generates a relabeler for the molecule and considered bonds.
DecisionList generateNewDecisionList(Random::Engine &engine=randomnessEngine())
Generate a new list of discrete dihedral arrangement choices.
Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators.
Definition: Molecule.h:77
Drives a PRNG.
Definition: Prng.h:24
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
Random::Engine & randomnessEngine()
Randomness source for the entire library.
Type used to refer to particular bonds. Orders first < second.
Definition: Types.h:54
Settings for enumeration.
Definition: DirectedConformerGenerator.h:429
DistanceGeometry::Configuration configuration
Conformer generation settings.
Definition: DirectedConformerGenerator.h:437
Relabeler for decision lists with minimized structures.
Definition: DirectedConformerGenerator.h:519
std::vector< std::vector< std::pair< int, int > > > binBounds(const std::vector< std::vector< unsigned >> &binIndices, const std::vector< Intervals > &allBins) const
Relabel bin indices for all structures with bin bounds.
std::vector< Intervals > bins(double delta=M_PI/6) const
static Intervals densityBins(const std::vector< double > &dihedrals, double delta, unsigned symmetryOrder=1)
Simplest density-based binning function.
std::vector< std::vector< unsigned > > binIndices(const std::vector< Intervals > &allBins) const
Determine relabeling for all added position sets in order.
std::vector< std::vector< int > > binMidpointIntegers(const std::vector< std::vector< unsigned >> &binIndices, const std::vector< Intervals > &allBins) const
Relabel bin indices for all structures with bin midpoint integers.
Relabeler(const DirectedConformerGenerator::BondList &bonds, const Molecule &mol)
Construct a relabeler with a custom list of bonds.
std::vector< double > add(const Utils::PositionCollection &positions)
Add a structure to the set to relabel. Yields the considered dihedrals.
A configuration object for distance geometry runs with sane defaults.
Definition: Conformers.h:73