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 |
|
---|
35 | using 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'
|
---|
66 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
|
---|
67 |
|
---|
68 | void 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 = const_cast<const World &>(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 |
|
---|
157 | void 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 | */
|
---|
174 | void 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 |
|
---|
183 | void 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 |
|
---|
193 | void 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 |
|
---|
209 | void 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 |
|
---|
228 | void 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 |
|
---|
248 | void 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 | };
|
---|