source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 92e5cb

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

Refactored Output..Correlation...() code into a single templated one.

  • template function OutputCorrelationMap() that accepts two function pointers for header and value to print the map's specifics.
  • all other function have been refactored into these two output functions per CorrelationMap type.

TESTFIXES:

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