source: src/Analysis/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ e9e86f

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 e9e86f was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * AnalysisCorrelationToSurfaceUnitTest.cpp
25 *
26 * Created on: Oct 13, 2009
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include <cstring>
42
43#include "Analysis/analysis_correlation.hpp"
44#include "Atom/atom.hpp"
45#include "CodePatterns/Assert.hpp"
46#include "Descriptors/MoleculeDescriptor.hpp"
47#include "Element/element.hpp"
48#include "Element/periodentafel.hpp"
49#include "LinkedCell/linkedcell.hpp"
50#include "LinkedCell/PointCloudAdaptor.hpp"
51#include "molecule.hpp"
52#include "MoleculeListClass.hpp"
53#include "Tesselation/boundary.hpp"
54#include "Tesselation/tesselation.hpp"
55#include "World.hpp"
56
57#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
58
59#ifdef HAVE_TESTRUNNER
60#include "UnitTestMain.hpp"
61#endif /*HAVE_TESTRUNNER*/
62
63/********************************************** Test classes **************************************/
64
65// Registers the fixture into the 'registry'
66CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
67
68void AnalysisCorrelationToSurfaceUnitTest::setUp()
69{
70 ASSERT_DO(Assert::Throw);
71
72 setVerbosity(5);
73
74 atom *Walker = NULL;
75
76 // init private all pointers to zero
77 TestSurfaceMolecule = NULL;
78 surfacemap = NULL;
79 binmap = NULL;
80 Surface = NULL;
81 LC = NULL;
82
83 // prepare element list
84 hydrogen = World::getInstance().getPeriode()->FindElement(1);
85 CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
86 elements.clear();
87
88 // construct molecule (tetraeder of hydrogens) base
89 TestSurfaceMolecule = World::getInstance().createMolecule();
90
91 Walker = World::getInstance().createAtom();
92 Walker->setType(hydrogen);
93 Walker->setPosition(Vector(1., 0., 1. ));
94 TestSurfaceMolecule->AddAtom(Walker);
95
96 Walker = World::getInstance().createAtom();
97 Walker->setType(hydrogen);
98 Walker->setPosition(Vector(0., 1., 1. ));
99 TestSurfaceMolecule->AddAtom(Walker);
100
101 Walker = World::getInstance().createAtom();
102 Walker->setType(hydrogen);
103 Walker->setPosition(Vector(1., 1., 0. ));
104 TestSurfaceMolecule->AddAtom(Walker);
105
106 Walker = World::getInstance().createAtom();
107 Walker->setType(hydrogen);
108 Walker->setPosition(Vector(0., 0., 0. ));
109 TestSurfaceMolecule->AddAtom(Walker);
110
111 // check that TestMolecule was correctly constructed
112 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
113
114 TestSurfaceMolecule->ActiveFlag = true;
115
116 // init tesselation and linked cell
117 Surface = new Tesselation;
118 PointCloudAdaptor<molecule> cloud(TestSurfaceMolecule, TestSurfaceMolecule->name);
119 LC = new LinkedCell_deprecated(cloud, 5.);
120 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell_deprecated *&)LC, 2.5, NULL);
121
122 // add outer atoms
123 carbon = World::getInstance().getPeriode()->FindElement(6);
124 TestSurfaceMolecule = World::getInstance().createMolecule();
125 Walker = World::getInstance().createAtom();
126 Walker->setType(carbon);
127 Walker->setPosition(Vector(4., 0., 4. ));
128 TestSurfaceMolecule->AddAtom(Walker);
129
130 Walker = World::getInstance().createAtom();
131 Walker->setType(carbon);
132 Walker->setPosition(Vector(0., 4., 4. ));
133 TestSurfaceMolecule->AddAtom(Walker);
134
135 Walker = World::getInstance().createAtom();
136 Walker->setType(carbon);
137 Walker->setPosition(Vector(4., 4., 0. ));
138 TestSurfaceMolecule->AddAtom(Walker);
139
140 // add inner atoms
141 Walker = World::getInstance().createAtom();
142 Walker->setType(carbon);
143 Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
144 TestSurfaceMolecule->AddAtom(Walker);
145
146 World::getInstance().selectAllMolecules(AllMolecules());
147 allMolecules = World::getInstance().getSelectedMolecules();
148 CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
149
150 // init maps
151 surfacemap = NULL;
152 binmap = NULL;
153
154};
155
156
157void AnalysisCorrelationToSurfaceUnitTest::tearDown()
158{
159 if (surfacemap != NULL)
160 delete(surfacemap);
161 if (binmap != NULL)
162 delete(binmap);
163
164 delete(Surface);
165 // note that all the atoms are cleaned by TestMolecule
166 delete(LC);
167 World::purgeInstance();
168 logger::purgeInstance();
169};
170
171
172/** Checks whether setup() does the right thing.
173 */
174void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
175{
176 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
177 CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
178 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
179 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
180 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
181};
182
183void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
184{
185 // do the pair correlation
186 elements.push_back(hydrogen);
187 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
188// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
189 CPPUNIT_ASSERT( surfacemap != NULL );
190 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
191};
192
193void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
194{
195 BinPairMap::iterator tester;
196 elements.push_back(hydrogen);
197 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
198 // put pair correlation into bins and check with no range
199// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
200 binmap = BinData( surfacemap, 0.5, 0., 0. );
201 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
202 OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
203 tester = binmap->begin();
204 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
205 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
206
207};
208
209void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
210{
211 BinPairMap::iterator tester;
212 elements.push_back(hydrogen);
213 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
214// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
215 // ... and check with [0., 2.] range
216 binmap = BinData( surfacemap, 0.5, 0., 2. );
217 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
218// OutputCorrelation ( (ofstream *)&cout, binmap );
219 tester = binmap->begin();
220 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
221 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
222 tester = binmap->find(1.);
223 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
224 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
225
226};
227
228void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
229{
230 BinPairMap::iterator tester;
231 elements.push_back(carbon);
232 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
233// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
234 // put pair correlation into bins and check with no range
235 binmap = BinData( surfacemap, 0.5, 0., 0. );
236 //OutputCorrelation ( (ofstream *)&cout, binmap );
237 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
238 // inside point is first and must have negative value
239 tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
240 CPPUNIT_ASSERT( tester != binmap->end() );
241 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
242 // inner point
243 tester = binmap->lower_bound(0.);
244 CPPUNIT_ASSERT( tester != binmap->end() );
245 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
246};
247
248void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
249{
250 BinPairMap::iterator tester;
251 elements.push_back(carbon);
252 surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
253// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
254 // ... and check with [0., 2.] range
255 binmap = BinData( surfacemap, 0.5, -2., 4. );
256 //OutputCorrelation ( (ofstream *)&cout, binmap );
257 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
258 // three outside points
259 tester = binmap->lower_bound(4.25-0.5);
260 CPPUNIT_ASSERT( tester != binmap->end() );
261 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
262 // inner point
263 tester = binmap->lower_bound(0.);
264 CPPUNIT_ASSERT( tester != binmap->end() );
265 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
266};
Note: See TracBrowser for help on using the repository browser.