source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 13e3c3

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 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 7.6 KB
Line 
1/*
2 * AnalysisCorrelationToSurfaceUnitTest.cpp
3 *
4 * Created on: Oct 13, 2009
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13using namespace std;
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
19#include <cstring>
20
21#include "analysis_correlation.hpp"
22#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
23
24#include "Descriptors/MoleculeDescriptor.hpp"
25
26#include "atom.hpp"
27#include "boundary.hpp"
28#include "element.hpp"
29#include "molecule.hpp"
30#include "linkedcell.hpp"
31#include "periodentafel.hpp"
32#include "tesselation.hpp"
33#include "World.hpp"
34#include "Helpers/Assert.hpp"
35
36#include "Helpers/Assert.hpp"
37
38#ifdef HAVE_TESTRUNNER
39#include "UnitTestMain.hpp"
40#endif /*HAVE_TESTRUNNER*/
41
42/********************************************** Test classes **************************************/
43
44// Registers the fixture into the 'registry'
45CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
46
47void AnalysisCorrelationToSurfaceUnitTest::setUp()
48{
49 ASSERT_DO(Assert::Throw);
50
51 setVerbosity(5);
52
53 atom *Walker = NULL;
54
55 // init private all pointers to zero
56 TestSurfaceMolecule = NULL;
57 surfacemap = NULL;
58 binmap = NULL;
59 Surface = NULL;
60 LC = NULL;
61
62 // prepare element list
63 hydrogen = World::getInstance().getPeriode()->FindElement(1);
64 CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
65 elements.clear();
66
67 // construct molecule (tetraeder of hydrogens) base
68 TestSurfaceMolecule = World::getInstance().createMolecule();
69
70 Walker = World::getInstance().createAtom();
71 Walker->setType(hydrogen);
72 Walker->setPosition(Vector(1., 0., 1. ));
73 TestSurfaceMolecule->AddAtom(Walker);
74
75 Walker = World::getInstance().createAtom();
76 Walker->setType(hydrogen);
77 Walker->setPosition(Vector(0., 1., 1. ));
78 TestSurfaceMolecule->AddAtom(Walker);
79
80 Walker = World::getInstance().createAtom();
81 Walker->setType(hydrogen);
82 Walker->setPosition(Vector(1., 1., 0. ));
83 TestSurfaceMolecule->AddAtom(Walker);
84
85 Walker = World::getInstance().createAtom();
86 Walker->setType(hydrogen);
87 Walker->setPosition(Vector(0., 0., 0. ));
88 TestSurfaceMolecule->AddAtom(Walker);
89
90 // check that TestMolecule was correctly constructed
91 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
92
93 TestSurfaceMolecule->ActiveFlag = true;
94
95 // init tesselation and linked cell
96 Surface = new Tesselation;
97 LC = new LinkedCell(TestSurfaceMolecule, 5.);
98 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
99
100 // add outer atoms
101 carbon = World::getInstance().getPeriode()->FindElement(6);
102 TestSurfaceMolecule = World::getInstance().createMolecule();
103 Walker = World::getInstance().createAtom();
104 Walker->setType(carbon);
105 Walker->setPosition(Vector(4., 0., 4. ));
106 TestSurfaceMolecule->AddAtom(Walker);
107
108 Walker = World::getInstance().createAtom();
109 Walker->setType(carbon);
110 Walker->setPosition(Vector(0., 4., 4. ));
111 TestSurfaceMolecule->AddAtom(Walker);
112
113 Walker = World::getInstance().createAtom();
114 Walker->setType(carbon);
115 Walker->setPosition(Vector(4., 4., 0. ));
116 TestSurfaceMolecule->AddAtom(Walker);
117
118 // add inner atoms
119 Walker = World::getInstance().createAtom();
120 Walker->setType(carbon);
121 Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
122 TestSurfaceMolecule->AddAtom(Walker);
123
124 World::getInstance().selectAllMolecules(AllMolecules());
125 allMolecules = World::getInstance().getSelectedMolecules();
126 CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
127
128 // init maps
129 surfacemap = NULL;
130 binmap = NULL;
131
132};
133
134
135void AnalysisCorrelationToSurfaceUnitTest::tearDown()
136{
137 if (surfacemap != NULL)
138 delete(surfacemap);
139 if (binmap != NULL)
140 delete(binmap);
141
142 delete(Surface);
143 // note that all the atoms are cleaned by TestMolecule
144 delete(LC);
145 World::purgeInstance();
146 logger::purgeInstance();
147};
148
149
150/** Checks whether setup() does the right thing.
151 */
152void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
153{
154 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
155 CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
156 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
157 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
158 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
159};
160
161void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
162{
163 // do the pair correlation
164 elements.push_back(hydrogen);
165 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
166// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
167 CPPUNIT_ASSERT( surfacemap != NULL );
168 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
169};
170
171void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
172{
173 BinPairMap::iterator tester;
174 elements.push_back(hydrogen);
175 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
176 // put pair correlation into bins and check with no range
177// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
178 binmap = BinData( surfacemap, 0.5, 0., 0. );
179 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
180 OutputCorrelation ( (ofstream *)&cout, binmap );
181 tester = binmap->begin();
182 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
183 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
184
185};
186
187void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
188{
189 BinPairMap::iterator tester;
190 elements.push_back(hydrogen);
191 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
192// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
193 // ... and check with [0., 2.] range
194 binmap = BinData( surfacemap, 0.5, 0., 2. );
195 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
196// OutputCorrelation ( (ofstream *)&cout, binmap );
197 tester = binmap->begin();
198 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
199 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
200 tester = binmap->find(1.);
201 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
202 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
203
204};
205
206void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
207{
208 BinPairMap::iterator tester;
209 elements.push_back(carbon);
210 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
211// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
212 // put pair correlation into bins and check with no range
213 binmap = BinData( surfacemap, 0.5, 0., 0. );
214 //OutputCorrelation ( (ofstream *)&cout, binmap );
215 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
216 // inside point is first and must have negative value
217 tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
218 CPPUNIT_ASSERT( tester != binmap->end() );
219 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
220 // inner point
221 tester = binmap->lower_bound(0.);
222 CPPUNIT_ASSERT( tester != binmap->end() );
223 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
224};
225
226void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
227{
228 BinPairMap::iterator tester;
229 elements.push_back(carbon);
230 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
231// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
232 // ... and check with [0., 2.] range
233 binmap = BinData( surfacemap, 0.5, -2., 4. );
234 //OutputCorrelation ( (ofstream *)&cout, binmap );
235 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
236 // three outside points
237 tester = binmap->lower_bound(4.25-0.5);
238 CPPUNIT_ASSERT( tester != binmap->end() );
239 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
240 // inner point
241 tester = binmap->lower_bound(0.);
242 CPPUNIT_ASSERT( tester != binmap->end() );
243 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
244};
Note: See TracBrowser for help on using the repository browser.