Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators. More...
#include <Molecule.h>
Data Structures | |
struct | Impl |
Public Member Functions | |
Special member functions | |
Molecule (Molecule &&other) noexcept | |
Default-constructor creates a hydrogen molecule (H2). More... | |
Molecule & | operator= (Molecule &&rhs) noexcept |
Default-constructor creates a hydrogen molecule (H2). More... | |
Molecule (const Molecule &other) | |
Default-constructor creates a hydrogen molecule (H2). More... | |
Molecule & | operator= (const Molecule &rhs) |
Default-constructor creates a hydrogen molecule (H2). More... | |
~Molecule () | |
Default-constructor creates a hydrogen molecule (H2). More... | |
Molecule () noexcept | |
Default-constructor creates a hydrogen molecule (H2). More... | |
Molecule (Utils::ElementType element) noexcept | |
Single-element molecule constructor. More... | |
Molecule (Utils::ElementType a, Utils::ElementType b, BondType bondType=BondType::Single) noexcept | |
Construct a minimal molecule from two element types and a mutual bond type. More... | |
Molecule (Graph graph) | |
Constructs from connectivity alone, inferring the stereopermutators from graph. More... | |
Molecule (Graph graph, const AngstromPositions &positions, const boost::optional< std::vector< BondIndex > > &bondStereopermutatorCandidatesOptional=boost::none) | |
Construct from connectivity and positions. More... | |
Molecule (Graph graph, StereopermutatorList stereopermutators, boost::optional< AtomEnvironmentComponents > canonicalComponentsOption=boost::none) | |
Construct a molecule from underlying data fragments. More... | |
Modifiers | |
AtomIndex | addAtom (Utils::ElementType elementType, AtomIndex adjacentTo, BondType bondType=BondType::Single) |
Adds an atom by attaching it to an existing atom. More... | |
BondIndex | addBond (AtomIndex a, AtomIndex b, BondType bondType=BondType::Single) |
Adds a bond between two existing atoms. More... | |
void | applyPermutation (const std::vector< AtomIndex > &permutation) |
Applies an index permutation to the Molecule state. More... | |
void | assignStereopermutator (AtomIndex a, const boost::optional< unsigned > &assignmentOption) |
Sets the stereopermutator assignment at a particular atom. More... | |
void | assignStereopermutator (const BondIndex &edge, const boost::optional< unsigned > &assignmentOption) |
Sets the stereopermutator assignment on a bond. More... | |
void | assignStereopermutatorRandomly (AtomIndex a, Random::Engine &engine=randomnessEngine()) |
Assigns a stereopermutator stereopermutation at random. More... | |
void | assignStereopermutatorRandomly (const BondIndex &e, Random::Engine &engine=randomnessEngine()) |
Assigns a bond stereopermutator to a random assignment. More... | |
std::vector< AtomIndex > | canonicalize (AtomEnvironmentComponents componentBitmask=AtomEnvironmentComponents::All) |
Transform the molecule to a canonical form. Invalidates all atom and bond indices. More... | |
void | removeAtom (AtomIndex a) |
Removes an atom from the graph, including bonds to it. More... | |
void | removeBond (AtomIndex a, AtomIndex b) |
Removes a bond from the graph. More... | |
void | removeBond (const BondIndex &bond) |
bool | setBondType (AtomIndex a, AtomIndex b, BondType bondType) |
Changes a bond type. Returns whether the bond already existed. More... | |
void | setElementType (AtomIndex a, Utils::ElementType elementType) |
Changes an existing atom's element type. More... | |
void | setShapeAtAtom (AtomIndex a, Shapes::Shape shape) |
Sets the local shape at an atom index. More... | |
Information | |
boost::optional < AtomEnvironmentComponents > | canonicalComponents () const |
Get which components of the graph have been used in canonicalization. More... | |
boost::optional< Shapes::Shape > | inferShape (AtomIndex index, const RankingInformation &ranking) const |
Determines what the local shape at a non-terminal atom ought to be based on the underlying graph. More... | |
std::string | dumpGraphviz () const |
Returns a graphivz string representation of the molecule. More... | |
const Graph & | graph () const |
Provides read-only access to the graph representation. More... | |
std::size_t | hash () const |
Hash function for the molecule. More... | |
const StereopermutatorList & | stereopermutators () const |
Provides read-only access to the list of stereopermutators. More... | |
StereopermutatorList | inferStereopermutatorsFromPositions (const AngstromPositions &angstromWrapper, const boost::optional< std::vector< BondIndex > > &explicitBondStereopermutatorCandidatesOption=boost::none) const |
Generates stereopermutators from connectivity and positional information. More... | |
std::string | str () const |
Returns a command-line interface information string. | |
RankingInformation | rankPriority (AtomIndex a, const std::vector< AtomIndex > &excludeAdjacent={}, const boost::optional< AngstromPositions > &positionsOption=boost::none) const |
Rank substituents of an atom. More... | |
Comparison | |
bool | canonicalCompare (const Molecule &other, AtomEnvironmentComponents componentBitmask=AtomEnvironmentComponents::All) const |
Modular comparison of this Molecule with another, assuming that both are in a canonical form. More... | |
boost::optional< std::vector < AtomIndex > > | modularIsomorphism (const Molecule &other, AtomEnvironmentComponents componentBitmask) const |
Modular comparison of this Molecule with another. More... | |
Operators | |
bool | operator== (const Molecule &other) const |
Equality operator, performs most strict equality comparison. More... | |
bool | operator!= (const Molecule &other) const |
Inverts Molecule::operator ==. | |
Static Public Member Functions | |
Static functions | |
static Utils::AtomCollection | applyCanonicalizationMap (const std::vector< AtomIndex > &canonicalizationIndexMap, const Utils::AtomCollection &atomCollection) |
Applies a canonicalization index mapping to an atom collection. More... | |
Private Attributes | |
std::unique_ptr< Impl > | pImpl_ |
Friends | |
struct | Editing |
class | DirectedConformerGenerator |
Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators.
This class models chemical molecules as a combination of a graph and a list of stereopermutators.
In the graph, vertices additionally store an element type (and thus represent atoms) and edges store a discretized bond type (and therefore represent bonds).
Stereopermutators represent the absolute configuration at an atom or bond in an abstract fashion and do not store coordinate information.
|
noexcept |
Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
Scine::Molassembler::Molecule::Molecule | ( | const Molecule & | other | ) |
Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
Scine::Molassembler::Molecule::~Molecule | ( | ) |
Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
|
noexcept |
Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
|
noexcept |
Single-element molecule constructor.
Complexity \(\Theta(1)\)
|
noexcept |
Construct a minimal molecule from two element types and a mutual bond type.
Complexity \(\Theta(1)\)
|
explicit |
Constructs from connectivity alone, inferring the stereopermutators from graph.
Constructs a molecule from connectivity alone. Local shapes and stereopermutators are inferred from the graph alone.
Complexity \(O(V + E)\) in rankings and stereopermutator instantiations
std::logic_error | If the supplied graph has multiple connected components or there are less than 2 atoms |
Scine::Molassembler::Molecule::Molecule | ( | Graph | graph, |
const AngstromPositions & | positions, | ||
const boost::optional< std::vector< BondIndex > > & | bondStereopermutatorCandidatesOptional = boost::none |
||
) |
Construct from connectivity and positions.
Construct an instance from a constituting graph and positional information. Local shapes are deduced from positional information. Stereopermutators are inferred from the graph and assigned using the supplied positional information.
Complexity \(O(V + B)\) where \(B\) is the number of candidate bonds for bond stereopermutators
graph | The graph from which to construct the molecule |
positions | Atom positions to use for the classification of shapes and interpretation of stereopermutators |
bondStereopermutatorCandidatesOptional | If boost::none, all bonds are candidates for BondStereopermutator. Otherwise, only the specified bonds are checked for BondStereopermutators. |
std::logic_error | If the supplied graph has multiple connected components or there are less than 2 atoms |
Scine::Molassembler::Molecule::Molecule | ( | Graph | graph, |
StereopermutatorList | stereopermutators, | ||
boost::optional< AtomEnvironmentComponents > | canonicalComponentsOption = boost::none |
||
) |
Construct a molecule from underlying data fragments.
Complexity \(\Theta(1)\)
std::logic_error | If the supplied graph has multiple connected components or there are less than 2 atoms |
AtomIndex Scine::Molassembler::Molecule::addAtom | ( | Utils::ElementType | elementType, |
AtomIndex | adjacentTo, | ||
BondType | bondType = BondType::Single |
||
) |
Adds an atom by attaching it to an existing atom.
Adds a new atom, attaching it to an existing atom by a specified bond type.
Complexity Factorial in size of the new shape at adjacentTo
and linear in re-rankings and propagations of non-terminal positions
elementType | The element type of the new atom |
adjacentTo | The atom to which the new atom is to be attached |
bondType | The bond type with which the new atom is to be attached |
std::out_of_range | If adjacentTo is invalid, i.e. >= N() |
BondIndex Scine::Molassembler::Molecule::addBond | ( | AtomIndex | a, |
AtomIndex | b, | ||
BondType | bondType = BondType::Single |
||
) |
Adds a bond between two existing atoms.
Adds a bond between two already-existing atoms.
Complexity Factorial in size of the larger new shape at either end of the bond and linear in re-rankings and propagations of non-terminal positions
a | The first atom index |
b | The second atom index |
bondType | The bond type with which to connect a and b. |
std::out_of_range | If either atom index is invalid, i.e. >= N() |
std::logic_error | If the atom indices match or the edge already exists. |
|
static |
Applies a canonicalization index mapping to an atom collection.
canonicalizationIndexMap | Index mapping received from a molecule canonicalization operation |
atomCollection | the atom collection to permute |
void Scine::Molassembler::Molecule::applyPermutation | ( | const std::vector< AtomIndex > & | permutation | ) |
Applies an index permutation to the Molecule state.
Complexity \(\Theta(V + A + B)\)
permutation | A vertex permutation |
void Scine::Molassembler::Molecule::assignStereopermutator | ( | AtomIndex | a, |
const boost::optional< unsigned > & | assignmentOption | ||
) |
Sets the stereopermutator assignment at a particular atom.
This sets the stereopermutator assignment at a specific atom index. For this, a stereopermutator must be instantiated and contained in the StereopermutatorList returned by stereopermutators(). The supplied assignment must be either boost::none or smaller than stereopermutatorPtr->numAssignments().
Complexity \(O(N)\) re-rankings and state propagations
a | The atom index at which a stereopermutator is to be assigned. |
assignmentOption | The new assignment. The special value boost::none makes the stereopermutator indeterminate. Any indeterminate atom stereopermutators in a molecule at conformation-generation will be assigned with a probability according to their sterepermutation's relative statistical occurence. |
std::out_of_range | If the atom index is invalid, i.e. >= N(), there is no stereopermutator at this position or the assignment index is invalid. |
void Scine::Molassembler::Molecule::assignStereopermutator | ( | const BondIndex & | edge, |
const boost::optional< unsigned > & | assignmentOption | ||
) |
Sets the stereopermutator assignment on a bond.
This sets the stereopermutator assignment at a specific bond index. For this, a stereopermutator must be instantiated and contained in the StereopermutatorList returned by stereopermutators(). The supplied assignment must be either boost::none or smaller than stereopermutatorPtr->numAssignments().
Complexity \(O(N)\) re-rankings and state propagations
edge | The edge at which a stereopermutator is to be assigned. |
assignmentOption | The new assignment. The special value boost::none makes the stereopermutator indeterminate. Any indeterminate bond stereopermutators in a molecule at conformation-generation will be assigned randomly. |
std::out_of_range | If the BondIndex is invalid (i.e. either atom index >= N()), there is no bond stereopermutator at the supplied edge or the assignment index is invalid. |
void Scine::Molassembler::Molecule::assignStereopermutatorRandomly | ( | AtomIndex | a, |
Random::Engine & | engine = randomnessEngine() |
||
) |
Assigns a stereopermutator stereopermutation at random.
This sets the stereopermutator assignment at a specific index, taking relative statistical occurence weights of each stereopermutation into account.
Complexity \(O(N)\) re-rankings and state propagations
a | The atom index at which the atom stereopermutator is to be assigned randomly |
engine | The PRNG engine to use for random assignment. Defaults to the library-global random number generator engine |
std::out_of_range | If the atom index is invalid (i.e. is >= N()) or there is no atom stereopermutator at this bond index. |
engine
is chosen. void Scine::Molassembler::Molecule::assignStereopermutatorRandomly | ( | const BondIndex & | e, |
Random::Engine & | engine = randomnessEngine() |
||
) |
Assigns a bond stereopermutator to a random assignment.
e | The bond index at which to randomly assign a bond stereopermutator |
engine | The PRNG engine to use for random assignment. Defaults to the library-global random number generator engine |
Complexity \(O(N)\) re-rankings and state propagations
std::out_of_range | If the bond index is invalid (i.e. either atom index is >= N()) or there is no bond stereopermutator at this bond index. |
engine
is chosen. bool Scine::Molassembler::Molecule::canonicalCompare | ( | const Molecule & | other, |
AtomEnvironmentComponents | componentBitmask = AtomEnvironmentComponents::All |
||
) | const |
Modular comparison of this Molecule with another, assuming that both are in a canonical form.
Complexity \(O(N)\)
other | The other canonical molecule to compare against |
componentBitmask | The components of an atom's environment to include in the comparison. You should use the same componentBitmask as when canonicalizing the molecules you are comparing here. It may be possible to use a bitmask with fewer components, but certainly not one with more. May not be None. |
std::logic_error | If componentBitmask contains more components than have been used to canonicalize this molecule instance or other . |
boost::optional<AtomEnvironmentComponents> Scine::Molassembler::Molecule::canonicalComponents | ( | ) | const |
Get which components of the graph have been used in canonicalization.
Complexity \(\Theta(1)\)
std::vector<AtomIndex> Scine::Molassembler::Molecule::canonicalize | ( | AtomEnvironmentComponents | componentBitmask = AtomEnvironmentComponents::All | ) |
Transform the molecule to a canonical form. Invalidates all atom and bond indices.
Complexity Theoretically the algorithm falls into the exponential class, but for typical molecules much faster.
componentBitmask | The components of the molecular graph to include in the canonicalization procedure. |
componentBitmask
, Molecule::operator == has a shortcut for fully canonical molecules.components
supplied here.std::string Scine::Molassembler::Molecule::dumpGraphviz | ( | ) | const |
Returns a graphivz string representation of the molecule.
Complexity \(\Theta(V + E + A + B)\)
Creates a graphviz representation of a molecule that can be written into a dotfile and processed with graphviz's dot
binary to create an image of the molecular graph.
Includes tooltip information on stereopermutators when hovering over individual nodes.
const Graph& Scine::Molassembler::Molecule::graph | ( | ) | const |
Provides read-only access to the graph representation.
Complexity \(\Theta(1)\)
std::size_t Scine::Molassembler::Molecule::hash | ( | ) | const |
Hash function for the molecule.
Convolutional hash including only the currently canonical components.
std::logic_error | If the molecule is acanonical, i.e. canonicalComponents() is None |
boost::optional<Shapes::Shape> Scine::Molassembler::Molecule::inferShape | ( | AtomIndex | index, |
const RankingInformation & | ranking | ||
) | const |
Determines what the local shape at a non-terminal atom ought to be based on the underlying graph.
Complexity \(\Theta(1)\) currently since only basic VSEPR is implemented
Returns the expected shape name at a non-terminal atom by inference from graph information only.
Can be extended to apply various levels of theory to determine the shape based on various information contained in the graph, such as ligand field theory.
index | The atom index where the local shape should be determined |
ranking | The ranking of all substituents at the supplied index. See rankPriority() |
std::out_of_range | If the supplied atomic index is >= N() |
std::logic_error | If the supplied atom is terminal or if the amount of ligand sites exceeds the size of the largest defined shape. |
StereopermutatorList Scine::Molassembler::Molecule::inferStereopermutatorsFromPositions | ( | const AngstromPositions & | angstromWrapper, |
const boost::optional< std::vector< BondIndex > > & | explicitBondStereopermutatorCandidatesOption = boost::none |
||
) | const |
Generates stereopermutators from connectivity and positional information.
Positions are an important source of information for stereopermutators as they will alleviate graph-based shape-determination errors and allow for the determination of stereopermutator assignments through spatial fitting.
Complexity \(\Theta(S!)\) where \(S\) is the largest shape size fitted
angstromWrapper | Wrapped positions in angstrom length units |
explicitBondStereopermutatorCandidatesOption | Permits the specification of a limited set of bonds on which BondStereopermutator instantiation is attempted. In Interpret.h, for instance, you can choose not to instantiate BondStereopermutators below a fractional bond order threshold to avoid spurious frozen dihedrals. By default, all bonds are candidates. |
std::out_of_range | if a BondIndex in explicitBondStereopermutatorCandidatesOption does not reference an existing bond (irrelevant if left default). |
boost::optional<std::vector<AtomIndex> > Scine::Molassembler::Molecule::modularIsomorphism | ( | const Molecule & | other, |
AtomEnvironmentComponents | componentBitmask | ||
) | const |
Modular comparison of this Molecule with another.
This permits detailed specification of which elements of the molecular information you want to use in the comparison.
At each atom position, a hash is computed that encompasses all local information that is specified to be used in componentsBitmask
. This hash is then used during graph isomorphism calculation to avoid finding an isomorphism that does not consider the specified factors.
Complexity \(O(V_1 \cdot V_2)\)
other | The other molecule to compare against |
componentBitmask | Components of an atom's environment to include in isomorphism tests. May not be None. |
this
to other
if the molecules are isomorphic.compentBitmask
matches the canonical components of both molecules involved. Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
Default-constructor creates a hydrogen molecule (H2).
Complexity \(\Theta(1)\)
bool Scine::Molassembler::Molecule::operator== | ( | const Molecule & | other | ) | const |
Equality operator, performs most strict equality comparison.
If both molecule instances are fully canonical, calls canonicalCompare(). Otherwise calls modularIsomorphism().
Implemented as
RankingInformation Scine::Molassembler::Molecule::rankPriority | ( | AtomIndex | a, |
const std::vector< AtomIndex > & | excludeAdjacent = {} , |
||
const boost::optional< AngstromPositions > & | positionsOption = boost::none |
||
) | const |
Rank substituents of an atom.
Performs a ranking algorithm that attempts to differentiate branches extending at each substituent atom (haptic ligands are not considered a single unit, rather their component atoms are all individual substituents).
Groups substituents into ligands (these are not the same since haptic ligands exist) and ranks those too.
Complexity Theoretically unclear, but for typical cases constant time.
a | The atom whose substituents are to be ranked |
excludeAdjacent | A list of substituent atom indices that should be excluded from ranking |
positionsOption | Positional information can be used to determine auxiliary stereopermutator assignments that arise in the ranking algorithm and may have different sub-rankings than at the same position in the molecule considered on its own. It is preferable to supply this if positional information is present! |
std::out_of_range | If the supplied atom index is i.e. >= N() |
void Scine::Molassembler::Molecule::removeAtom | ( | AtomIndex | a | ) |
Removes an atom from the graph, including bonds to it.
Removes an atom from the molecular graph, including bonds to the atom, after checking that removing it is safe, i.e. the removal does not disconnect the graph.
Complexity \(O(N + A + B)\) stereopermutator updates, re-rankings and propagations
std::out_of_range | If the supplied index is invalid, i.e. >= N() |
std::logic_error | If removing the atom disconnects the graph or removes the final atom. |
Removes a bond from the graph.
Removes a bond after checking if removing that bond is safe, i.e. does not disconnect the graph. An example of bonds that can always be removed are ring-closing bonds, since they never disconnect the molecular graph.
Complexity \(O(N + A + B)\) stereopermutator updates, re-rankings and propagations
std::out_of_range | If the supplied bond index is invalid, i.e. either atom index >= N() or the specified bond does not exist. |
std::logic_error | If graph().canRemove() returns false. |
void Scine::Molassembler::Molecule::removeBond | ( | const BondIndex & | bond | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Changes a bond type. Returns whether the bond already existed.
Changes the bond type between two atom indices. If the bond does not exist yet, adds the bond.
Complexity \(\Theta(N)\) re-rankings and propagations
a | The first index of the bond whose type should be changed |
b | The second index of the bond whose type should be changed |
bondType | The new bond type |
out_of_range | If a or b are invalid, i.e. >= N() |
std::logic_error | If bondType is specified as BondType::Eta. The representation of bonding to haptic ligands and its dynamism is handled internally. |
void Scine::Molassembler::Molecule::setElementType | ( | AtomIndex | a, |
Utils::ElementType | elementType | ||
) |
Changes an existing atom's element type.
Changes the element type of an existing atom.
Complexity \(\Theta(N)\) re-rankings and propagations
a | The atom index of the atom whose element type is to be changed |
elementType | The new element type |
std::out_of_range | If a is invalid >= N() |
void Scine::Molassembler::Molecule::setShapeAtAtom | ( | AtomIndex | a, |
Shapes::Shape | shape | ||
) |
Sets the local shape at an atom index.
This sets the local shape at a specific atom index. There are a number of cases that this function treats differently, besides faulty arguments: If there is already a AtomStereopermutator instantiated at this atom index, its underlying shape is altered. If there is no AtomStereopermutator at this index, one is instantiated. In all cases, new or modified stereopermutators are default-assigned if there is only one possible assignment.
Complexity \(\Theta(N)\) re-rankings and propagations
std::out_of_range | if the supplied atomic index is invalid |
std::logic_error | if the provided shape is a different size than that of the existing AtomStereopermutator |
const StereopermutatorList& Scine::Molassembler::Molecule::stereopermutators | ( | ) | const |
Provides read-only access to the list of stereopermutators.
Complexity \(\Theta(1)\)