source: src/unittests/LinkedCellUnitTest.cpp@ e08c46

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 e08c46 was 1024cb, checked in by Frederik Heber <heber@…>, 15 years ago

Merge commit 'jupiter/MoleculeStartEndSwitch' into CommandLineActionMapping

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

Integration of MoleculeStartEndSwitch had the following consequences:

  • no more AtomCount -> getAtomCount()
  • no more start/end -> begin(), end() and iterator
  • no more decent ordering in atomic ids (hence, Simple_configuration/8 and Domain/5, Domain/6 now check by comparing sorted xyz, not confs)

There is still a huge problem with bonds. One test runs into an endless loop.

Signed-off-by: Frederik Heber <heber@…>

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