source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ b5c53d

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

Member variable Vector and element of class atom are now private.

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