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