source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ ad011c

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

CodePatterns places all includes now in subfolder CodePatterns/.

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