| 1 | /* | 
|---|
| 2 | * SaturatedFragment.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Mar 3, 2013 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef SATURATEDFRAGMENT_HPP_ | 
|---|
| 9 | #define SATURATEDFRAGMENT_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <iosfwd> | 
|---|
| 17 | #include <set> | 
|---|
| 18 | #include <string> | 
|---|
| 19 |  | 
|---|
| 20 | #include "Bond/bond.hpp" | 
|---|
| 21 | #include "Fragmentation/KeySet.hpp" | 
|---|
| 22 | #include "Fragmentation/HydrogenSaturation_enum.hpp" | 
|---|
| 23 | #include "Parser/FormatParserStorage.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | class atom; | 
|---|
| 26 | class HydrogenPool; | 
|---|
| 27 |  | 
|---|
| 28 | /** The SaturatedFragment class acts as a wrapper to a KeySet by adding a list | 
|---|
| 29 | * of saturation hydrogens. | 
|---|
| 30 | * | 
|---|
| 31 | * This SaturatedFragment along with a currently leased set of hydrogens from the | 
|---|
| 32 | * HydrogenPool is all that is required to create a fully storable molecular | 
|---|
| 33 | * fragment from a given Keyset. | 
|---|
| 34 | * | 
|---|
| 35 | * The instance notes down its existence in an external container. | 
|---|
| 36 | * | 
|---|
| 37 | */ | 
|---|
| 38 | class SaturatedFragment | 
|---|
| 39 | { | 
|---|
| 40 | public: | 
|---|
| 41 | //!> typedef to a container to mark keysets that are in use | 
|---|
| 42 | typedef std::set<KeySet> KeySetsInUse_t; | 
|---|
| 43 |  | 
|---|
| 44 | /** Constructor of SaturatedFragment requires \a set which we are tightly | 
|---|
| 45 | * associated. | 
|---|
| 46 | * | 
|---|
| 47 | * \param _set KeySet which this instance is associated with | 
|---|
| 48 | * \param _container container to add KeySet as in-use | 
|---|
| 49 | * \param _hydrogens pool with hydrogens for saturation | 
|---|
| 50 | */ | 
|---|
| 51 | SaturatedFragment( | 
|---|
| 52 | const KeySet &_set, | 
|---|
| 53 | KeySetsInUse_t &_container, | 
|---|
| 54 | HydrogenPool &_hydrogens, | 
|---|
| 55 | const enum HydrogenTreatment _treatment, | 
|---|
| 56 | const enum HydrogenSaturation saturation); | 
|---|
| 57 |  | 
|---|
| 58 | /** Destructor of class SaturatedFragment. | 
|---|
| 59 | * | 
|---|
| 60 | */ | 
|---|
| 61 | ~SaturatedFragment(); | 
|---|
| 62 |  | 
|---|
| 63 | /** Getter for the KeySet this instance is associated with. | 
|---|
| 64 | * | 
|---|
| 65 | * \return const ref to KeySet | 
|---|
| 66 | */ | 
|---|
| 67 | const KeySet & getKeySet() const | 
|---|
| 68 | { | 
|---|
| 69 | return set; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | /** Getter for the FullMolecule this instance is associated with. | 
|---|
| 73 | * | 
|---|
| 74 | * \return const ref to FullMolecule | 
|---|
| 75 | */ | 
|---|
| 76 | const KeySet & getFullMolecule() const | 
|---|
| 77 | { | 
|---|
| 78 | return FullMolecule; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | /** Getter for the SaturationHydrogens this instance is associated with. | 
|---|
| 82 | * | 
|---|
| 83 | * \return const ref to SaturationHydrogens | 
|---|
| 84 | */ | 
|---|
| 85 | const KeySet & getSaturationHydrogens() const | 
|---|
| 86 | { | 
|---|
| 87 | return SaturationHydrogens; | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | /** Prints the config of the fragment of \a _type to \a out. | 
|---|
| 91 | * | 
|---|
| 92 | * \param out output stream to write to | 
|---|
| 93 | * \param _type parser type to write config | 
|---|
| 94 | */ | 
|---|
| 95 | bool OutputConfig( | 
|---|
| 96 | std::ostream &out, | 
|---|
| 97 | const ParserTypes _type) const; | 
|---|
| 98 |  | 
|---|
| 99 | private: | 
|---|
| 100 | /** Helper function to lease and bring in place saturation hydrogens. | 
|---|
| 101 | * | 
|---|
| 102 | */ | 
|---|
| 103 | void saturate(); | 
|---|
| 104 |  | 
|---|
| 105 | /** Helper function to get a hydrogen replacement for a given \a replacement. | 
|---|
| 106 | * | 
|---|
| 107 | * \param replacement atom to "replace" with hydrogen in a fragment. | 
|---|
| 108 | * \return ref to leased hydrogen atom | 
|---|
| 109 | */ | 
|---|
| 110 | atom * const getHydrogenReplacement(atom * const replacement); | 
|---|
| 111 |  | 
|---|
| 112 | /** Leases and adds a Hydrogen atom in replacement for the given atom \a *partner in bond with a *origin. | 
|---|
| 113 | * Here, we have to distinguish between single, double or triple bonds as stated by \a BondDegree, that each demand | 
|---|
| 114 | * a different scheme when adding \a *replacement atom for the given one. | 
|---|
| 115 | * -# Single Bond: Simply add new atom with bond distance rescaled to typical hydrogen one | 
|---|
| 116 | * -# Double Bond: Here, we need the **BondList of the \a *origin atom, by scanning for the other bonds instead of | 
|---|
| 117 | *    *Bond, we use the through these connected atoms to determine the plane they lie in, vector::MakeNormalvector(). | 
|---|
| 118 | *    The orthonormal vector to this plane along with the vector in *Bond direction determines the plane the two | 
|---|
| 119 | *    replacing hydrogens shall lie in. Now, all remains to do is take the usual hydrogen double bond angle for the | 
|---|
| 120 | *    element of *origin and form the sin/cos admixture of both plane vectors for the new coordinates of the two | 
|---|
| 121 | *    hydrogens forming this angle with *origin. | 
|---|
| 122 | * -# Triple Bond: The idea is to set up a tetraoid (C1-H1-H2-H3) (however the lengths \f$b\f$ of the sides of the base | 
|---|
| 123 | *    triangle formed by the to be added hydrogens are not equal to the typical bond distance \f$l\f$ but have to be | 
|---|
| 124 | *    determined from the typical angle \f$\alpha\f$ for a hydrogen triple connected to the element of *origin): | 
|---|
| 125 | *    We have the height \f$d\f$ as the vector in *Bond direction (from triangle C1-H1-H2). | 
|---|
| 126 | *    \f[ h = l \cdot \cos{\left (\frac{\alpha}{2} \right )} \qquad b = 2l \cdot \sin{\left (\frac{\alpha}{2} \right)} \quad \rightarrow \quad d = l \cdot \sqrt{\cos^2{\left (\frac{\alpha}{2} \right)}-\frac{1}{3}\cdot\sin^2{\left (\frac{\alpha}{2}\right )}} | 
|---|
| 127 | *    \f] | 
|---|
| 128 | *    vector::GetNormalvector() creates one orthonormal vector from this *Bond vector and vector::MakeNormalvector creates | 
|---|
| 129 | *    the third one from the former two vectors. The latter ones form the plane of the base triangle mentioned above. | 
|---|
| 130 | *    The lengths for these are \f$f\f$ and \f$g\f$ (from triangle H1-H2-(center of H1-H2-H3)) with knowledge that | 
|---|
| 131 | *    the median lines in an isosceles triangle meet in the center point with a ratio 2:1. | 
|---|
| 132 | *    \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2} | 
|---|
| 133 | *    \f] | 
|---|
| 134 | *    as the coordination of all three atoms in the coordinate system of these three vectors: | 
|---|
| 135 | *    \f$\pmatrix{d & f & 0}\f$, \f$\pmatrix{d & -0.5 \cdot f & g}\f$ and \f$\pmatrix{d & -0.5 \cdot f & -g}\f$. | 
|---|
| 136 | * | 
|---|
| 137 | * \param TopBond pointer to bond between \a *origin and \a *replacement | 
|---|
| 138 | * \param Origin atom that is actually contained in the fragment | 
|---|
| 139 | * \param Replacement pointer to the atom which shall be copied as a hydrogen atom in this molecule | 
|---|
| 140 | * \param isAngstroem whether the coordination of the given atoms is in AtomicLength (false) or Angstrom(true) | 
|---|
| 141 | * \return number of atoms added, if < bond::BondDegree then something went wrong | 
|---|
| 142 | */ | 
|---|
| 143 | bool AddHydrogenReplacementAtom( | 
|---|
| 144 | bond::ptr TopBond, | 
|---|
| 145 | atom *Origin, | 
|---|
| 146 | atom *Replacement, | 
|---|
| 147 | bool IsAngstroem); | 
|---|
| 148 |  | 
|---|
| 149 | private: | 
|---|
| 150 | //!> container to mark ourselves RAII-style | 
|---|
| 151 | KeySetsInUse_t &container; | 
|---|
| 152 | //!> key set this fragment is associated with. | 
|---|
| 153 | const KeySet &set; | 
|---|
| 154 | //!> pool with saturation hydrogens | 
|---|
| 155 | HydrogenPool &hydrogens; | 
|---|
| 156 | //!> key set containing all atoms used for e.g. storing this to file | 
|---|
| 157 | KeySet FullMolecule; | 
|---|
| 158 | //!> key set containing the ids of all hydrogens added for saturation | 
|---|
| 159 | KeySet SaturationHydrogens; | 
|---|
| 160 | //!> whether hydrogens are generally contained in set or not | 
|---|
| 161 | const enum HydrogenTreatment treatment; | 
|---|
| 162 | //!> whether to actually saturate or not | 
|---|
| 163 | const enum HydrogenSaturation saturation; | 
|---|
| 164 | }; | 
|---|
| 165 |  | 
|---|
| 166 | #endif /* SATURATEDFRAGMENT_HPP_ */ | 
|---|