source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp@ b3c052

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 b3c052 was b3c052, checked in by Frederik Heber <heber@…>, 9 years ago

Dropped quaternion rotation for simple arbitrary rotation axis and angle.

  • with newCenter, oldCenter and the cross product we have all we need: a rotation axis and an angle. We don't need to burden ourselves with those stupid, absolutely not working quaternions.
  • removeMatchingPoints() now works on an array.
  • Orientation rotation was wrong way round, added check.
  • TESTFIX: removed QuaternionTest from SphericalPointDistributionTest, marked FragmentMolecule-cycle and StoreSaturatedFragment regression tests as XFAIL.
  • Property mode set to 100644
File size: 13.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2014 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * SphericalPointDistributionUnitTest.cpp
25 *
26 * Created on: May 29, 2014
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41// include headers that implement a archive in simple text format
42#include <boost/archive/text_oarchive.hpp>
43#include <boost/archive/text_iarchive.hpp>
44
45#include "SphericalPointDistributionUnitTest.hpp"
46
47#include <boost/assign.hpp>
48#include <boost/math/quaternion.hpp>
49
50#include "CodePatterns/Assert.hpp"
51#include "CodePatterns/Log.hpp"
52
53#include "LinearAlgebra/Line.hpp"
54
55#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
56
57#include "LinearAlgebra/Line.hpp"
58
59#ifdef HAVE_TESTRUNNER
60#include "UnitTestMain.hpp"
61#endif /*HAVE_TESTRUNNER*/
62
63using namespace boost::assign;
64
65/********************************************** Test classes **************************************/
66
67// Registers the fixture into the 'registry'
68CPPUNIT_TEST_SUITE_REGISTRATION( SphericalPointDistributionTest );
69
70
71void SphericalPointDistributionTest::setUp()
72{
73 // failing asserts should be thrown
74 ASSERT_DO(Assert::Throw);
75
76 setVerbosity(5);
77}
78
79
80void SphericalPointDistributionTest::tearDown()
81{
82}
83
84
85/** UnitTest for matchSphericalPointDistributions() with two points
86 */
87void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
88{
89 SphericalPointDistribution SPD(1.);
90 // test with one point, matching trivially
91 {
92 SphericalPointDistribution::Polygon_t polygon;
93 polygon += Vector(1.,0.,0.);
94 SphericalPointDistribution::Polygon_t newpolygon =
95 SPD.get<2>();
96 SphericalPointDistribution::Polygon_t expected;
97 expected += Vector(-1.,0.,0.);
98 SphericalPointDistribution::Polygon_t remaining =
99 SphericalPointDistribution::matchSphericalPointDistributions(
100 polygon,
101 newpolygon);
102 CPPUNIT_ASSERT_EQUAL( expected, remaining );
103 }
104
105 // test with one point, just a flip of axis
106 {
107 SphericalPointDistribution::Polygon_t polygon;
108 polygon += Vector(0.,1.,0.);
109 SphericalPointDistribution::Polygon_t newpolygon =
110 SPD.get<2>();
111 SphericalPointDistribution::Polygon_t expected;
112 expected += Vector(0.,-1.,0.);
113 SphericalPointDistribution::Polygon_t remaining =
114 SphericalPointDistribution::matchSphericalPointDistributions(
115 polygon,
116 newpolygon);
117 CPPUNIT_ASSERT_EQUAL( expected, remaining );
118 }
119
120 // test with one point, just a flip to another axis
121 {
122 SphericalPointDistribution::Polygon_t polygon;
123 polygon += Vector(0.,0.,-1.);
124 SphericalPointDistribution::Polygon_t newpolygon =
125 SPD.get<2>();
126 SphericalPointDistribution::Polygon_t expected;
127 expected += Vector(0.,0.,1.);
128 SphericalPointDistribution::Polygon_t remaining =
129 SphericalPointDistribution::matchSphericalPointDistributions(
130 polygon,
131 newpolygon);
132 CPPUNIT_ASSERT_EQUAL( expected, remaining );
133 }
134
135 // test with one point, full rotation
136 {
137 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
138 SphericalPointDistribution::Polygon_t polygon;
139 polygon += RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI);
140 SphericalPointDistribution::Polygon_t newpolygon =
141 SPD.get<2>();
142 SphericalPointDistribution::Polygon_t expected;
143 expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
144 SphericalPointDistribution::Polygon_t remaining =
145 SphericalPointDistribution::matchSphericalPointDistributions(
146 polygon,
147 newpolygon);
148 CPPUNIT_ASSERT_EQUAL( expected, remaining );
149 }
150}
151
152/** UnitTest for matchSphericalPointDistributions() with three points
153 */
154void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_3()
155{
156 SphericalPointDistribution SPD(1.);
157
158 // test with one point, matching trivially
159 {
160 SphericalPointDistribution::Polygon_t polygon;
161 polygon += Vector(1.,0.,0.);
162 SphericalPointDistribution::Polygon_t newpolygon =
163 SPD.get<3>();
164 SphericalPointDistribution::Polygon_t expected = newpolygon;
165 expected.pop_front(); // remove first point
166 SphericalPointDistribution::Polygon_t remaining =
167 SphericalPointDistribution::matchSphericalPointDistributions(
168 polygon,
169 newpolygon);
170 CPPUNIT_ASSERT_EQUAL( expected, remaining );
171 }
172
173 // test with one point, just a flip of x and y axis
174 {
175 SphericalPointDistribution::Polygon_t polygon;
176 polygon += Vector(0.,1.,0.);
177 SphericalPointDistribution::Polygon_t newpolygon =
178 SPD.get<3>();
179 SphericalPointDistribution::Polygon_t expected = newpolygon;
180 expected.pop_front(); // remove first point
181 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
182 iter != expected.end(); ++iter) {
183 std::swap((*iter)[0], (*iter)[1]);
184 (*iter)[0] *= -1.;
185 }
186 SphericalPointDistribution::Polygon_t remaining =
187 SphericalPointDistribution::matchSphericalPointDistributions(
188 polygon,
189 newpolygon);
190 CPPUNIT_ASSERT_EQUAL( expected, remaining );
191 }
192}
193
194/** UnitTest for matchSphericalPointDistributions() with four points
195 */
196void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_4()
197{
198 SphericalPointDistribution SPD(1.);
199
200 // test with one point, matching trivially
201 {
202 SphericalPointDistribution::Polygon_t polygon;
203 polygon += Vector(1.,0.,0.);
204 SphericalPointDistribution::Polygon_t newpolygon =
205 SPD.get<4>();
206 SphericalPointDistribution::Polygon_t expected = newpolygon;
207 expected.pop_front(); // remove first point
208 SphericalPointDistribution::Polygon_t remaining =
209 SphericalPointDistribution::matchSphericalPointDistributions(
210 polygon,
211 newpolygon);
212 CPPUNIT_ASSERT_EQUAL( expected, remaining );
213 }
214
215 // test with one point, just a flip of axis
216 {
217 SphericalPointDistribution::Polygon_t polygon;
218 polygon += Vector(0.,1.,0.);
219 SphericalPointDistribution::Polygon_t newpolygon =
220 SPD.get<4>();
221 SphericalPointDistribution::Polygon_t expected = newpolygon;
222 expected.pop_front(); // remove first point
223 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
224 iter != expected.end(); ++iter) {
225 std::swap((*iter)[0], (*iter)[1]);
226 (*iter)[0] *= -1.;
227 }
228 SphericalPointDistribution::Polygon_t remaining =
229 SphericalPointDistribution::matchSphericalPointDistributions(
230 polygon,
231 newpolygon);
232 CPPUNIT_ASSERT_EQUAL( expected, remaining );
233 }
234}
235
236/** UnitTest for matchSphericalPointDistributions() with five points
237 */
238void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_5()
239{
240 SphericalPointDistribution SPD(1.);
241
242 // test with one point, matching trivially
243 {
244 SphericalPointDistribution::Polygon_t polygon;
245 polygon += Vector(1.,0.,0.);
246 SphericalPointDistribution::Polygon_t newpolygon =
247 SPD.get<5>();
248 SphericalPointDistribution::Polygon_t expected = newpolygon;
249 expected.pop_front(); // remove first point
250 SphericalPointDistribution::Polygon_t remaining =
251 SphericalPointDistribution::matchSphericalPointDistributions(
252 polygon,
253 newpolygon);
254 CPPUNIT_ASSERT_EQUAL( expected, remaining );
255 }
256
257 // test with one point, just a flip of axis
258 {
259 SphericalPointDistribution::Polygon_t polygon;
260 polygon += Vector(0.,1.,0.);
261 SphericalPointDistribution::Polygon_t newpolygon =
262 SPD.get<5>();
263 SphericalPointDistribution::Polygon_t expected = newpolygon;
264 expected.pop_front(); // remove first point
265 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
266 iter != expected.end(); ++iter) {
267 std::swap((*iter)[0], (*iter)[1]);
268 (*iter)[0] *= -1.;
269 }
270 SphericalPointDistribution::Polygon_t remaining =
271 SphericalPointDistribution::matchSphericalPointDistributions(
272 polygon,
273 newpolygon);
274 CPPUNIT_ASSERT_EQUAL( expected, remaining );
275 }
276}
277
278/** UnitTest for matchSphericalPointDistributions() with six points
279 */
280void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_6()
281{
282 SphericalPointDistribution SPD(1.);
283
284 // test with one point, matching trivially
285 {
286 SphericalPointDistribution::Polygon_t polygon;
287 polygon += Vector(1.,0.,0.);
288 SphericalPointDistribution::Polygon_t newpolygon =
289 SPD.get<6>();
290 SphericalPointDistribution::Polygon_t expected = newpolygon;
291 expected.pop_front(); // remove first point
292 SphericalPointDistribution::Polygon_t remaining =
293 SphericalPointDistribution::matchSphericalPointDistributions(
294 polygon,
295 newpolygon);
296 CPPUNIT_ASSERT_EQUAL( expected, remaining );
297 }
298
299 // test with one point, just a flip of axis
300 {
301 SphericalPointDistribution::Polygon_t polygon;
302 polygon += Vector(0.,1.,0.);
303 SphericalPointDistribution::Polygon_t newpolygon =
304 SPD.get<6>();
305 SphericalPointDistribution::Polygon_t expected = newpolygon;
306 expected.pop_front(); // remove first point
307 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
308 iter != expected.end(); ++iter) {
309 std::swap((*iter)[0], (*iter)[1]);
310 (*iter)[0] *= -1.;
311 }
312 SphericalPointDistribution::Polygon_t remaining =
313 SphericalPointDistribution::matchSphericalPointDistributions(
314 polygon,
315 newpolygon);
316 CPPUNIT_ASSERT_EQUAL( expected, remaining );
317 }
318}
319
320/** UnitTest for matchSphericalPointDistributions() with seven points
321 */
322void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_7()
323{
324 SphericalPointDistribution SPD(1.);
325
326 // test with one point, matching trivially
327 {
328 SphericalPointDistribution::Polygon_t polygon;
329 polygon += Vector(1.,0.,0.);
330 SphericalPointDistribution::Polygon_t newpolygon =
331 SPD.get<7>();
332 SphericalPointDistribution::Polygon_t expected = newpolygon;
333 expected.pop_front(); // remove first point
334 SphericalPointDistribution::Polygon_t remaining =
335 SphericalPointDistribution::matchSphericalPointDistributions(
336 polygon,
337 newpolygon);
338 CPPUNIT_ASSERT_EQUAL( expected, remaining );
339 }
340
341 // test with one point, just a flip of axis
342 {
343 SphericalPointDistribution::Polygon_t polygon;
344 polygon += Vector(0.,1.,0.);
345 SphericalPointDistribution::Polygon_t newpolygon =
346 SPD.get<7>();
347 SphericalPointDistribution::Polygon_t expected = newpolygon;
348 expected.pop_front(); // remove first point
349 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
350 iter != expected.end(); ++iter) {
351 std::swap((*iter)[0], (*iter)[1]);
352 (*iter)[0] *= -1.;
353 }
354 SphericalPointDistribution::Polygon_t remaining =
355 SphericalPointDistribution::matchSphericalPointDistributions(
356 polygon,
357 newpolygon);
358 CPPUNIT_ASSERT_EQUAL( expected, remaining );
359 }
360}
361
362/** UnitTest for matchSphericalPointDistributions() with eight points
363 */
364void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_8()
365{
366 SphericalPointDistribution SPD(1.);
367
368 // test with one point, matching trivially
369 {
370 SphericalPointDistribution::Polygon_t polygon;
371 polygon += Vector(1.,0.,0.);
372 SphericalPointDistribution::Polygon_t newpolygon =
373 SPD.get<8>();
374 SphericalPointDistribution::Polygon_t expected = newpolygon;
375 expected.pop_front(); // remove first point
376 SphericalPointDistribution::Polygon_t remaining =
377 SphericalPointDistribution::matchSphericalPointDistributions(
378 polygon,
379 newpolygon);
380 CPPUNIT_ASSERT_EQUAL( expected, remaining );
381 }
382
383 // test with one point, just a flip of axis
384 {
385 SphericalPointDistribution::Polygon_t polygon;
386 polygon += Vector(0.,1.,0.);
387 SphericalPointDistribution::Polygon_t newpolygon =
388 SPD.get<8>();
389 SphericalPointDistribution::Polygon_t expected = newpolygon;
390 expected.pop_front(); // remove first point
391 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
392 iter != expected.end(); ++iter) {
393 std::swap((*iter)[0], (*iter)[1]);
394 (*iter)[0] *= -1.;
395 }
396 SphericalPointDistribution::Polygon_t remaining =
397 SphericalPointDistribution::matchSphericalPointDistributions(
398 polygon,
399 newpolygon);
400 CPPUNIT_ASSERT_EQUAL( expected, remaining );
401 }
402}
Note: See TracBrowser for help on using the repository browser.