source: src/Fragmentation/Exporters/SaturatedFragment.hpp@ f5fa48

Last change on this file since f5fa48 was f5fa48, checked in by Frederik Heber <heber@…>, 11 years ago

SaturatedFragment can deal with a global saturation position map.

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