source: src/unittests/LinkedCellUnitTest.cpp@ 47d041

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing 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_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 47d041 was 3bdb6d, checked in by Frederik Heber <heber@…>, 13 years ago

Moved all stuff related to elements into own subfolder and has its own convenience library.

  • this induced massive changes in includes in other files.
  • we adapted PeriodentafelUnitTest to not get instance from world, but we create it ourselves.
  • also moved all .db files related to elements into subfolder Element/.
  • Property mode set to 100644
File size: 12.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * LinkedCellUnitTest.cpp
10 *
11 * Created on: Apr 9, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <iostream>
27#include <stdio.h>
28#include <cstring>
29
30#include "atom.hpp"
31#include "Descriptors/MoleculeDescriptor.hpp"
32#include "Element/element.hpp"
33#include "linkedcell.hpp"
34#include "molecule.hpp"
35#include "Element/periodentafel.hpp"
36#include "PointCloudAdaptor.hpp"
37#include "World.hpp"
38
39#include "LinkedCellUnitTest.hpp"
40
41#ifdef HAVE_TESTRUNNER
42#include "UnitTestMain.hpp"
43#endif /*HAVE_TESTRUNNER*/
44
45/********************************************** Test classes **************************************/
46
47// Registers the fixture into the 'registry'
48CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCellTest );
49
50
51void LinkedCellTest::setUp()
52{
53 atom *Walker = NULL;
54
55 // construct element
56 hydrogen = World::getInstance().getPeriode()->FindElement(1);
57 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
58
59 // construct molecule (water molecule)
60 TestMolecule = World::getInstance().createMolecule();
61 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
62 for (double x=0.5;x<3;x+=1.)
63 for (double y=0.5;y<3;y+=1.)
64 for (double z=0.5;z<3;z+=1.) {
65 Walker = World::getInstance().createAtom();
66 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
67 Walker->setType(hydrogen);
68 Walker->setPosition(Vector(x, y, z ));
69 TestMolecule->AddAtom(Walker);
70 }
71
72 // construct linked cell
73 PointCloudAdaptor<molecule> cloud(TestMolecule, TestMolecule->name);
74 LC = new LinkedCell (cloud, 1.);
75 CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell");
76
77 // check that TestMolecule was correctly constructed
78 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 3*3*3 );
79};
80
81
82void LinkedCellTest::tearDown()
83{
84 delete(LC);
85 World::purgeInstance();
86};
87
88
89/** UnitTest for LinkedCell::CheckBounds().
90 */
91void LinkedCellTest::CheckBoundsTest()
92{
93 // check for within bounds
94 LC->n[0] = LC->n[1] = LC->n[2] = 0;
95 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
96 LC->n[0] = LC->n[1] = LC->n[2] = 1;
97 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
98 LC->n[0] = LC->n[1] = LC->n[2] = 2;
99 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
100
101 // check for out of bounds
102 cout << "The following test is supposed to fail and produce an ERROR." << endl;
103 LC->n[0] = 404040;
104 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
105 cout << "The following test is supposed to fail and produce an ERROR." << endl;
106 LC->n[0] = 0;
107 LC->n[1] = 5000;
108 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
109 cout << "The following test is supposed to fail and produce an ERROR." << endl;
110 LC->n[1] = 0;
111 LC->n[2] = -70;
112 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
113 cout << "The following test is supposed to fail and produce an ERROR." << endl;
114 LC->n[0] = LC->n[1] = LC->n[2] = 3;
115 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
116};
117
118
119/** UnitTest for LinkedCell::GetCurrentCell().
120 * Note that CheckBounds() is used and has to be tested already.
121 */
122void LinkedCellTest::GetCurrentCellTest()
123{
124 // within bounds
125 LC->n[0] = LC->n[1] = LC->n[2] = 0;
126 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[0 * 3*3 + 0 * 3 + 0], LC->GetCurrentCell() );
127 LC->n[0] = LC->n[1] = LC->n[2] = 1;
128 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[1 * 3*3 + 1 * 3 + 1], LC->GetCurrentCell() );
129 LC->n[0] = LC->n[1] = LC->n[2] = 2;
130 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetCurrentCell() );
131
132 // out of bounds
133 LC->n[0] = LC->n[1] = LC->n[2] = 3;
134 cout << "The following test is supposed to fail and produce an ERROR." << endl;
135 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetCurrentCell() );
136 LC->n[0] = LC->n[1] = LC->n[2] = -1;
137 cout << "The following test is supposed to fail and produce an ERROR." << endl;
138 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetCurrentCell() );
139};
140
141/** UnitTest for LinkedCell::GetRelativeToCurrentCell().
142 */
143void LinkedCellTest::GetRelativeToCurrentCellTest()
144{
145 int offset[3];
146
147 // offset to (0,0,0) always
148 offset[0] = offset[1] = offset[2] = 0;
149 LC->n[0] = LC->n[1] = LC->n[2] = 0;
150 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
151 offset[0] = offset[1] = offset[2] = -1;
152 LC->n[0] = LC->n[1] = LC->n[2] = 1;
153 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
154 offset[0] = offset[1] = offset[2] = -2;
155 LC->n[0] = LC->n[1] = LC->n[2] = 2;
156 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
157
158 // offset to (0,0,0) - 1.*(x/y/z) out of bounds
159 offset[0] = offset[1] = offset[2] = 0;
160 offset[0] = -1;
161 LC->n[0] = LC->n[1] = LC->n[2] = 0;
162 cout << "The following test is supposed to fail and produce an ERROR." << endl;
163 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
164 offset[0] = offset[1] = offset[2] = 0;
165 offset[1] = -1;
166 LC->n[0] = LC->n[1] = LC->n[2] = 0;
167 cout << "The following test is supposed to fail and produce an ERROR." << endl;
168 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
169 offset[0] = offset[1] = offset[2] = 0;
170 offset[2] = -1;
171 LC->n[0] = LC->n[1] = LC->n[2] = 0;
172 cout << "The following test is supposed to fail and produce an ERROR." << endl;
173 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
174
175 // out of bounds
176 offset[0] = offset[1] = offset[2] = -5054932;
177 LC->n[0] = LC->n[1] = LC->n[2] = 1;
178 cout << "The following test is supposed to fail and produce an ERROR." << endl;
179 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
180 offset[0] = offset[1] = offset[2] = 192345;
181 LC->n[0] = LC->n[1] = LC->n[2] = 1;
182 cout << "The following test is supposed to fail and produce an ERROR." << endl;
183 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
184
185 // index is out of bounds, offset points within
186 offset[0] = offset[1] = offset[2] = -2;
187 LC->n[0] = LC->n[1] = LC->n[2] = 4;
188 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetRelativeToCurrentCell(offset) );
189
190 // index is within bounds, offset points out
191 offset[0] = offset[1] = offset[2] = 2;
192 LC->n[0] = LC->n[1] = LC->n[2] = 2;
193 cout << "The following test is supposed to fail and produce an ERROR." << endl;
194 CPPUNIT_ASSERT_EQUAL( (const TesselPointSTLList*)NULL, LC->GetRelativeToCurrentCell(offset) );
195};
196
197
198/** UnitTest for LinkedCell::SetIndexToNode().
199 */
200void LinkedCellTest::SetIndexToNodeTest()
201{
202 // check all atoms
203 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){
204 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) );
205 }
206
207 // check internal vectors, returns false, because this atom is not in LC-list!
208 atom *newAtom = World::getInstance().createAtom();
209 newAtom->setName("test");
210 newAtom->setPosition(Vector(1,1,1));
211 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
212 World::getInstance().destroyAtom(newAtom);
213
214 // check out of bounds vectors
215 newAtom = World::getInstance().createAtom();
216 newAtom->setName("test");
217 newAtom->setPosition(Vector(0,-1,0));
218 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
219 World::getInstance().destroyAtom(newAtom);
220};
221
222
223/** UnitTest for LinkedCell::SetIndexToVector().
224 */
225void LinkedCellTest::SetIndexToVectorTest()
226{
227 Vector tester;
228
229 // check center of each cell
230 for (double x=0.5;x<3;x+=1.)
231 for (double y=0.5;y<3;y+=1.)
232 for (double z=0.5;z<3;z+=1.) {
233 tester = Vector(x,y,z);
234 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(tester) );
235 }
236 // check corners of each cell
237 for (double x=1.;x<4;x+=1.)
238 for (double y=1.;y<4;y+=1.)
239 for (double z=1.;z<4;z+=1.) {
240 tester= Vector(x,y,z);
241 cout << "Tester is at " << tester << "." << endl;
242 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(tester) );
243 }
244 // check out of bounds
245 for (double x=0.5-1e-10;x<5;x+=3.1)
246 for (double y=0.5-1e-10;y<5;y+=3.1)
247 for (double z=0.5-1e-10;z<5;z+=3.1) {
248 tester = Vector(x,y,z);
249 cout << "The following test is supposed to fail and produce an ERROR." << endl;
250 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(tester) );
251 }
252 // check nonsense vectors
253 tester= Vector(-423598,3245978,29349);
254 cout << "The following test is supposed to fail and produce an ERROR." << endl;
255 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(tester) );
256};
257
258
259/** UnitTest for LinkedCell::GetNeighbourBounds().
260 */
261void LinkedCellTest::GetNeighbourBoundsTest()
262{
263 Vector tester;
264 int lower[NDIM], upper[NDIM];
265
266 tester= Vector(0.5,0.5,0.5);
267 LC->SetIndexToVector(tester);
268 LC->GetNeighbourBounds(lower, upper);
269 for (int i=0;i<NDIM;i++)
270 CPPUNIT_ASSERT_EQUAL( 0, lower[i]);
271 for (int i=0;i<NDIM;i++)
272 CPPUNIT_ASSERT_EQUAL( 1, upper[i]);
273};
274
275
276/** UnitTest for LinkedCell::GetallNeighbours().
277 */
278void LinkedCellTest::GetallNeighboursTest()
279{
280 Vector tester;
281 TesselPointSTLList *ListOfPoints = NULL;
282 size_t size = 0;
283
284 // get all atoms
285 tester= Vector(1.5,1.5,1.5);
286 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
287 ListOfPoints = LC->GetallNeighbours();
288 size = ListOfPoints->size();
289 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
290
291 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
292 ListOfPoints->remove((*iter));
293 size--;
294 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
295 }
296 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
297 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
298 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
299 delete(ListOfPoints);
300
301 // get all atoms in one corner
302 tester= Vector(0.5, 0.5, 0.5);
303 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
304 ListOfPoints = LC->GetallNeighbours();
305 size=ListOfPoints->size();
306 CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
307 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
308 if (((*iter)->at(0) <2) && ((*iter)->at(1) <2) && ((*iter)->at(2) <2)) {
309 ListOfPoints->remove(*iter);
310 size--;
311 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
312 }
313 }
314 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
315 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
316 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
317 delete(ListOfPoints);
318
319 // get all atoms from one corner
320 tester = Vector(0.5, 0.5, 0.5);
321 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
322 ListOfPoints = LC->GetallNeighbours(3);
323 size=ListOfPoints->size();
324 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
325 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
326 ListOfPoints->remove(*iter);
327 size--;
328 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
329 }
330 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
331 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
332 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
333 delete(ListOfPoints);
334};
335
336
337/** UnitTest for LinkedCell::GetPointsInsideSphere().
338 */
339void LinkedCellTest::GetPointsInsideSphereTest()
340{
341 Vector tester;
342 TesselPointSTLList *ListOfPoints = NULL;
343 size_t size = 0;
344
345 // get all points around central arom with radius 1.
346 tester= Vector(1.5,1.5,1.5);
347 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
348 ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
349 size = ListOfPoints->size();
350 CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
351 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
352 if (((*iter)->DistanceSquared(tester) - 1.) < MYEPSILON ) {
353 ListOfPoints->remove(*iter);
354 size--;
355 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
356 }
357 }
358 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
359 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
360 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
361 delete(ListOfPoints);
362};
Note: See TracBrowser for help on using the repository browser.