source: src/Fragmentation/Exporters/SphericalPointDistribution.hpp@ fe90ab

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since fe90ab was fe90ab, checked in by Frederik Heber <heber@…>, 9 years ago

recurseMatching() now takes connections into account.

  • matchSphericalPointDistribution() replaced by getRemainingPoints() as that describes what it does. match...() sounds symmetrical which the function is no longer as connection is associated with former _newpolygon.
  • SphericalPointDistribution now has internal points and adjacency, initialized by initSelf().
  • findBestMatching() and getRemainingPoints() are no longer static functions.
  • all unit tests are working again, including the .._multiple() that tests for joint points due to bond degree greater than 1.
  • the huge case switch in SaturatedFragment::saturateAtom() now resides in initSelf().
  • Property mode set to 100644
File size: 8.7 KB
Line 
1/*
2 * SphericalPointDistribution.hpp
3 *
4 * Created on: May 29, 2014
5 * Author: heber
6 */
7
8
9#ifndef SPHERICALPOINTDISTRIBUTION_HPP_
10#define SPHERICALPOINTDISTRIBUTION_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "CodePatterns/Assert.hpp"
18
19#include <cmath>
20#include <list>
21#include <map>
22#include <set>
23#include <vector>
24
25#include "LinearAlgebra/Vector.hpp"
26
27class SphericalPointDistributionTest;
28
29/** contains getters for the VSEPR model for specific number of electrons.
30 *
31 * This struct contains specialized functions returning a list of Vectors
32 * (points in space) to match the VSEPR model for the given number of electrons.
33 *
34 * This is implemented via template specialization of the function get().
35 *
36 * These specializations are taken from the python script \b CreateVspeShapes.py
37 * by Christian Neuen, 07th May 2009.
38 */
39struct SphericalPointDistribution
40{
41 /** Cstor for SphericalPointDistribution, allows setting radius of sphere
42 *
43 * \param _BondLength desired radius of sphere
44 */
45 SphericalPointDistribution(const double _Bondlength = 1.) :
46 Bondlength(_Bondlength)
47 {}
48
49 //!> typedef for the list of points
50 typedef std::list<Vector> Polygon_t;
51 //!> typedef for the list of points with integral weights
52 typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
53 //!> typedef for a sorted list of indices
54 typedef std::set<unsigned int> IndexSet_t;
55 //!> typedef for the adjacency list of a polygon
56 typedef std::map<unsigned int, IndexSet_t > adjacency_t;
57
58 /** General getter function for the distribution of points on the surface.
59 *
60 * \warn this function needs to be specialized!
61 *
62 * \return Polygon_t with points on the surface centered at (0,0,0)
63 */
64 template <int N> Polygon_t get() const
65 {
66 ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
67 return Polygon_t();
68 }
69
70 template <int N> adjacency_t getConnections()
71 {
72 ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+".");
73 return Polygon_t();
74 }
75
76 /** Returns vacant spots to fill to get a complete spherical point distribution from
77 * given points \a _polygon, containing then \a _N in total.
78 *
79 * This is a helper to determine points where to best insert saturation
80 * hydrogens.
81 *
82 * \param _polygon already filled places to match
83 * \param _N desired total number fo points
84 */
85 Polygon_t getRemainingPoints(const WeightedPolygon_t &_polygon, const int _N);
86
87 //!> default radius of the spherical distribution
88 const double Bondlength;
89 //!> precalculated value for root of 3
90 static const double SQRT_3;
91 //!> threshold for L1 error below which matching is immediately acceptable
92 static const double L1THRESHOLD;
93 //!> threshold for L2 error below which matching is acceptable
94 static const double L2THRESHOLD;
95
96 //!> typedef for a full rotation specification consisting of axis and angle.
97 typedef std::pair<Vector, double> Rotation_t;
98
99 //!> typedef for a list of indices (of points in a polygon)
100 typedef std::list<unsigned int> IndexList_t;
101 //!> typedef enumerating possibly multiple points accumulated as one point
102 typedef std::list< IndexList_t > IndexTupleList_t;
103 //!> typedef for a vector of indices
104 typedef std::vector<unsigned int> IndexArray_t;
105 //!> typedef for a Vector of positions
106 typedef std::vector<Vector> VectorArray_t;
107 //!> typedef for a Vector of positions with weights
108 typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
109 //!> typedef for a vector of degrees (or integral weights)
110 typedef std::vector<unsigned int> WeightsArray_t;
111
112 //!> amplitude up to which deviations in checks of rotations are tolerated
113 static const double warn_amplitude;
114
115 struct PolygonWithIndices
116 {
117 //!> array with points
118 VectorArray_t polygon;
119 //!> list with indices for the above points, defining subset
120 IndexList_t indices;
121 };
122
123 static Vector calculateCenterOfMinimumDistance(
124 const SphericalPointDistribution::VectorArray_t &_positions,
125 const SphericalPointDistribution::IndexList_t &_indices);
126
127private:
128 //!> points for the ideal distribution
129 Polygon_t points;
130 //!> connection information between these ideal points
131 adjacency_t adjacency;
132
133 /** Initialize inner status (points and adjacency) to desired number of
134 * points.
135 *
136 * \param _N number of points
137 */
138 void initSelf(const int _N);
139
140private:
141 //!> grant unit tests access to private parts
142 friend class SphericalPointDistributionTest;
143
144 static std::pair<double, double> calculateErrorOfMatching(
145 const VectorArray_t &_old,
146 const VectorArray_t &_new,
147 const IndexTupleList_t &_Matching);
148
149 static Polygon_t removeMatchingPoints(
150 const PolygonWithIndices &_points);
151
152 struct MatchingControlStructure {
153 MatchingControlStructure(
154 const adjacency_t &_adjacency,
155 const VectorArray_t &_oldpoints,
156 const VectorArray_t &_newpoints,
157 const WeightsArray_t &_weights
158 );
159 bool foundflag;
160 double bestL2;
161 const adjacency_t &adjacency;
162 const VectorArray_t oldpoints;
163 const VectorArray_t newpoints;
164 const WeightsArray_t weights;
165 IndexTupleList_t bestmatching;
166 };
167
168 static void recurseMatchings(
169 MatchingControlStructure &_MCS,
170 IndexTupleList_t &_matching,
171 IndexList_t _indices,
172 WeightsArray_t &_remainingweights,
173 WeightsArray_t::iterator _remainiter,
174 const unsigned int _matchingsize
175 );
176
177 IndexList_t findBestMatching(const WeightedPolygon_t &_polygon);
178
179 static IndexList_t joinPoints(
180 Polygon_t &_newpolygon,
181 const VectorArray_t &_newpoints,
182 const IndexTupleList_t &_bestmatching
183 );
184
185 static Rotation_t findPlaneAligningRotation(
186 const PolygonWithIndices &_referencepositions,
187 const PolygonWithIndices &_currentpositions
188 );
189
190 static Rotation_t findPointAligningRotation(
191 const PolygonWithIndices &remainingold,
192 const PolygonWithIndices &remainingnew);
193};
194
195// declare specializations
196
197template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>() const;
198template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>() const;
199template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>() const;
200template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>() const;
201template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>() const;
202template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>() const;
203template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>() const;
204template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>() const;
205template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>() const;
206template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>() const;
207template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>() const;
208template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>() const;
209template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>() const;
210template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>() const;
211
212template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<0>();
213template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<1>();
214template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<2>();
215template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<3>();
216template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<4>();
217template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<5>();
218template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<6>();
219template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<7>();
220template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<8>();
221template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<9>();
222template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<10>();
223template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<11>();
224template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<12>();
225template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<14>();
226
227#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.