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