source: src/LinkedCell/unittests/linkedcellUnitTest.cpp@ c80643

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 c80643 was 6bd7e0, checked in by Frederik Heber <heber@…>, 13 years ago

Renamed old LinkedCell class to LinkedCell_deprecated.

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