source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ bcedf7

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

Added name to PointCloudAdaptor, set by constructor.

  • Property mode set to 100644
File size: 8.0 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 "atom.hpp"
30#include "boundary.hpp"
31#include "CodePatterns/Assert.hpp"
32#include "Descriptors/MoleculeDescriptor.hpp"
33#include "element.hpp"
34#include "molecule.hpp"
35#include "linkedcell.hpp"
36#include "periodentafel.hpp"
37#include "PointCloudAdaptor.hpp"
38#include "tesselation.hpp"
39#include "World.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 PointCloudAdaptor<molecule> cloud(TestSurfaceMolecule, TestSurfaceMolecule->name);
103 LC = new LinkedCell(cloud, 5.);
104 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
105
106 // add outer atoms
107 carbon = World::getInstance().getPeriode()->FindElement(6);
108 TestSurfaceMolecule = World::getInstance().createMolecule();
109 Walker = World::getInstance().createAtom();
110 Walker->setType(carbon);
111 Walker->setPosition(Vector(4., 0., 4. ));
112 TestSurfaceMolecule->AddAtom(Walker);
113
114 Walker = World::getInstance().createAtom();
115 Walker->setType(carbon);
116 Walker->setPosition(Vector(0., 4., 4. ));
117 TestSurfaceMolecule->AddAtom(Walker);
118
119 Walker = World::getInstance().createAtom();
120 Walker->setType(carbon);
121 Walker->setPosition(Vector(4., 4., 0. ));
122 TestSurfaceMolecule->AddAtom(Walker);
123
124 // add inner atoms
125 Walker = World::getInstance().createAtom();
126 Walker->setType(carbon);
127 Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
128 TestSurfaceMolecule->AddAtom(Walker);
129
130 World::getInstance().selectAllMolecules(AllMolecules());
131 allMolecules = World::getInstance().getSelectedMolecules();
132 CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
133
134 // init maps
135 surfacemap = NULL;
136 binmap = NULL;
137
138};
139
140
141void AnalysisCorrelationToSurfaceUnitTest::tearDown()
142{
143 if (surfacemap != NULL)
144 delete(surfacemap);
145 if (binmap != NULL)
146 delete(binmap);
147
148 delete(Surface);
149 // note that all the atoms are cleaned by TestMolecule
150 delete(LC);
151 World::purgeInstance();
152 logger::purgeInstance();
153};
154
155
156/** Checks whether setup() does the right thing.
157 */
158void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
159{
160 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
161 CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
162 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
163 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
164 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
165};
166
167void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
168{
169 // do the pair correlation
170 elements.push_back(hydrogen);
171 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
172// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
173 CPPUNIT_ASSERT( surfacemap != NULL );
174 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
175};
176
177void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
178{
179 BinPairMap::iterator tester;
180 elements.push_back(hydrogen);
181 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
182 // put pair correlation into bins and check with no range
183// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
184 binmap = BinData( surfacemap, 0.5, 0., 0. );
185 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
186 OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
187 tester = binmap->begin();
188 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
189 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
190
191};
192
193void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
194{
195 BinPairMap::iterator tester;
196 elements.push_back(hydrogen);
197 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
198// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
199 // ... and check with [0., 2.] range
200 binmap = BinData( surfacemap, 0.5, 0., 2. );
201 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
202// OutputCorrelation ( (ofstream *)&cout, binmap );
203 tester = binmap->begin();
204 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
205 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
206 tester = binmap->find(1.);
207 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
208 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
209
210};
211
212void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
213{
214 BinPairMap::iterator tester;
215 elements.push_back(carbon);
216 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
217// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
218 // put pair correlation into bins and check with no range
219 binmap = BinData( surfacemap, 0.5, 0., 0. );
220 //OutputCorrelation ( (ofstream *)&cout, binmap );
221 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
222 // inside point is first and must have negative value
223 tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
224 CPPUNIT_ASSERT( tester != binmap->end() );
225 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
226 // inner point
227 tester = binmap->lower_bound(0.);
228 CPPUNIT_ASSERT( tester != binmap->end() );
229 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
230};
231
232void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
233{
234 BinPairMap::iterator tester;
235 elements.push_back(carbon);
236 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
237// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
238 // ... and check with [0., 2.] range
239 binmap = BinData( surfacemap, 0.5, -2., 4. );
240 //OutputCorrelation ( (ofstream *)&cout, binmap );
241 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
242 // three outside points
243 tester = binmap->lower_bound(4.25-0.5);
244 CPPUNIT_ASSERT( tester != binmap->end() );
245 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
246 // inner point
247 tester = binmap->lower_bound(0.);
248 CPPUNIT_ASSERT( tester != binmap->end() );
249 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
250};
Note: See TracBrowser for help on using the repository browser.