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