source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ f761c4

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

Fixed all correlations for new selected sets of molecules.

  • MapOfActions: added missing action names point-correlation and surface-correlation.
  • BUGFIX: AnalysisPairCorrelationAction::createDialog() - needs to query for multiple element_s_.
  • BUGFIX: MapOfActions::queryCurrentValue() - added values twice, due to ..ID or Z was not set to -1 after push_back.
  • TESTFIX: Analysis/* all needed --select-all-molecules in front.
  • TESTFIX: Analysis/4 need additional --unselect-molecule-by-id 207 to avoid correlating againts itself.
  • TESTFIX: changed all correlation unit tests, i.e. replaced TestList by allMolecules from getSelectedMolecules().
  • analysis_correlation.[ch]pp:
    • Replaced MoleculeListClass by const std::vector<molecule *>
    • ActiveFlag check is removed, we hand over getSelectedMolecules() from World (or any other vector of molecules) instead.
  • Property mode set to 100644
File size: 7.5 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 atom *Walker = NULL;
47
48 // init private all pointers to zero
49 TestSurfaceMolecule = NULL;
50 surfacemap = NULL;
51 binmap = NULL;
52 Surface = NULL;
53 LC = NULL;
54
55 // prepare element list
56 hydrogen = World::getInstance().getPeriode()->FindElement(1);
57 CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
58 elements.clear();
59
60 // construct molecule (tetraeder of hydrogens) base
61 TestSurfaceMolecule = World::getInstance().createMolecule();
62
63 Walker = World::getInstance().createAtom();
64 Walker->type = hydrogen;
65 *Walker->node = Vector(1., 0., 1. );
66 TestSurfaceMolecule->AddAtom(Walker);
67
68 Walker = World::getInstance().createAtom();
69 Walker->type = hydrogen;
70 *Walker->node = Vector(0., 1., 1. );
71 TestSurfaceMolecule->AddAtom(Walker);
72
73 Walker = World::getInstance().createAtom();
74 Walker->type = hydrogen;
75 *Walker->node = Vector(1., 1., 0. );
76 TestSurfaceMolecule->AddAtom(Walker);
77
78 Walker = World::getInstance().createAtom();
79 Walker->type = hydrogen;
80 *Walker->node = Vector(0., 0., 0. );
81 TestSurfaceMolecule->AddAtom(Walker);
82
83 // check that TestMolecule was correctly constructed
84 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
85
86 TestSurfaceMolecule->ActiveFlag = true;
87
88 // init tesselation and linked cell
89 Surface = new Tesselation;
90 LC = new LinkedCell(TestSurfaceMolecule, 5.);
91 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
92
93 // add outer atoms
94 carbon = World::getInstance().getPeriode()->FindElement(6);
95 TestSurfaceMolecule = World::getInstance().createMolecule();
96 Walker = World::getInstance().createAtom();
97 Walker->type = carbon;
98 *Walker->node = Vector(4., 0., 4. );
99 TestSurfaceMolecule->AddAtom(Walker);
100
101 Walker = World::getInstance().createAtom();
102 Walker->type = carbon;
103 *Walker->node = Vector(0., 4., 4. );
104 TestSurfaceMolecule->AddAtom(Walker);
105
106 Walker = World::getInstance().createAtom();
107 Walker->type = carbon;
108 *Walker->node = Vector(4., 4., 0. );
109 TestSurfaceMolecule->AddAtom(Walker);
110
111 // add inner atoms
112 Walker = World::getInstance().createAtom();
113 Walker->type = carbon;
114 *Walker->node = Vector(0.5, 0.5, 0.5 );
115 TestSurfaceMolecule->AddAtom(Walker);
116
117 World::getInstance().selectAllMolecules(AllMolecules());
118 allMolecules = World::getInstance().getSelectedMolecules();
119 CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
120
121 // init maps
122 surfacemap = NULL;
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
135 delete(Surface);
136 // note that all the atoms are cleaned by TestMolecule
137 delete(LC);
138 World::purgeInstance();
139 logger::purgeInstance();
140};
141
142
143/** Checks whether setup() does the right thing.
144 */
145void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
146{
147 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
148 CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.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
154void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
155{
156 // do the pair correlation
157 elements.push_back(hydrogen);
158 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
159// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
160 CPPUNIT_ASSERT( surfacemap != NULL );
161 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
162};
163
164void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
165{
166 BinPairMap::iterator tester;
167 elements.push_back(hydrogen);
168 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
169 // put pair correlation into bins and check with no range
170// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
171 binmap = BinData( surfacemap, 0.5, 0., 0. );
172 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
173 OutputCorrelation ( (ofstream *)&cout, binmap );
174 tester = binmap->begin();
175 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
176 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
177
178};
179
180void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
181{
182 BinPairMap::iterator tester;
183 elements.push_back(hydrogen);
184 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
185// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
186 // ... and check with [0., 2.] range
187 binmap = BinData( surfacemap, 0.5, 0., 2. );
188 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
189// OutputCorrelation ( (ofstream *)&cout, binmap );
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
199void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
200{
201 BinPairMap::iterator tester;
202 elements.push_back(carbon);
203 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
204// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
205 // put pair correlation into bins and check with no range
206 binmap = BinData( surfacemap, 0.5, 0., 0. );
207 //OutputCorrelation ( (ofstream *)&cout, binmap );
208 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
209 // inside point is first and must have negative value
210 tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
211 CPPUNIT_ASSERT( tester != binmap->end() );
212 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
213 // inner point
214 tester = binmap->lower_bound(0.);
215 CPPUNIT_ASSERT( tester != binmap->end() );
216 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
217};
218
219void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
220{
221 BinPairMap::iterator tester;
222 elements.push_back(carbon);
223 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
224// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
225 // ... and check with [0., 2.] range
226 binmap = BinData( surfacemap, 0.5, -2., 4. );
227 //OutputCorrelation ( (ofstream *)&cout, binmap );
228 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
229 // three outside points
230 tester = binmap->lower_bound(4.25-0.5);
231 CPPUNIT_ASSERT( tester != binmap->end() );
232 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
233 // inner point
234 tester = binmap->lower_bound(0.);
235 CPPUNIT_ASSERT( tester != binmap->end() );
236 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
237};
Note: See TracBrowser for help on using the repository browser.