source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 8e17d6

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 8e17d6 was c78d44, checked in by Frederik Heber <heber@…>, 15 years ago

Change to PairCorrelation...() functions, accept now vector<element *> instead of ptrs to element *.

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