source: src/unittests/CountBondsUnitTest.cpp@ a7b761b

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 Candidate_v1.7.0 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 a7b761b was a7b761b, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge branch 'MoleculeStartEndSwitch' into StructureRefactoring

Conflicts:

molecuilder/src/Helpers/Assert.cpp
molecuilder/src/Helpers/Assert.hpp
molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/Patterns/Cacheable.hpp
molecuilder/src/Patterns/Observer.cpp
molecuilder/src/Patterns/Observer.hpp
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule.hpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/ObserverTest.cpp
molecuilder/src/unittests/ObserverTest.hpp

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*
2 * CountBondsUnitTest.cpp
3 *
4 * Created on: Mar 30, 2010
5 * Author: heber
6 */
7
8
9using namespace std;
10
11#include <cppunit/CompilerOutputter.h>
12#include <cppunit/extensions/TestFactoryRegistry.h>
13#include <cppunit/ui/text/TestRunner.h>
14
15#include <iostream>
16#include <stdio.h>
17#include <cstring>
18
19#include "analysis_bonds.hpp"
20#include "atom.hpp"
21#include "bond.hpp"
22#include "bondgraph.hpp"
23#include "element.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
26#include "World.hpp"
27#include "CountBondsUnitTest.hpp"
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( CountBondsTest );
37
38
39void CountBondsTest::setUp()
40{
41 atom *Walker = NULL;
42 BG = NULL;
43 filename = NULL;
44
45 // init private all pointers to zero
46 molecules = NULL;
47 TestMolecule1 = NULL;
48 TestMolecule2 = NULL;
49 hydrogen = NULL;
50 oxygen = NULL;
51 tafel = NULL;
52
53 // construct element
54 hydrogen = new element;
55 hydrogen->Z = 1;
56 hydrogen->CovalentRadius = 0.23;
57 strcpy(hydrogen->name, "hydrogen");
58 strcpy(hydrogen->symbol, "H");
59 oxygen = new element;
60 oxygen->Z = 8;
61 oxygen->CovalentRadius = 0.68;
62 strcpy(oxygen->name, "oxygen");
63 strcpy(oxygen->symbol, "O");
64
65 // construct periodentafel
66 tafel = World::getInstance().getPeriode();
67 tafel->AddElement(hydrogen);
68 tafel->AddElement(oxygen);
69
70 // construct molecule (water molecule)
71 TestMolecule1 = World::getInstance().createMolecule();
72 Walker = World::getInstance().createAtom();
73 Walker->type = hydrogen;
74 *Walker->node = Vector(-0.2418, 0.9350, 0. );
75 TestMolecule1->AddAtom(Walker);
76 Walker = World::getInstance().createAtom();
77 Walker->type = hydrogen;
78 *Walker->node = Vector(0.9658, 0., 0. );
79 TestMolecule1->AddAtom(Walker);
80 Walker = World::getInstance().createAtom();
81 Walker->type = oxygen;
82 *Walker->node = Vector(0., 0., 0. );
83 TestMolecule1->AddAtom(Walker);
84
85 TestMolecule2 = World::getInstance().createMolecule();
86 Walker = World::getInstance().createAtom();
87 Walker->type = hydrogen;
88 *Walker->node = Vector(-0.2418, 0.9350, 0. );
89 TestMolecule2->AddAtom(Walker);
90 Walker = World::getInstance().createAtom();
91 Walker->type = hydrogen;
92 *Walker->node = Vector(0.9658, 0., 0. );
93 TestMolecule2->AddAtom(Walker);
94 Walker = World::getInstance().createAtom();
95 Walker->type = oxygen;
96 *Walker->node = Vector(0., 0., 0. );
97 TestMolecule2->AddAtom(Walker);
98
99 molecules = World::getInstance().getMolecules();
100 molecules->insert(TestMolecule1);
101 molecules->insert(TestMolecule2);
102
103 // check that TestMolecule was correctly constructed
104 CPPUNIT_ASSERT_EQUAL( TestMolecule1->getAtomCount(), 3 );
105 CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
106
107 // create a small file with table
108 BG = new BondGraph(true);
109
110 // construct bond graphs
111 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule1) );
112 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule2) );
113// TestMolecule1->Output((ofstream *)&cout);
114// TestMolecule1->OutputBondsList();
115};
116
117
118void CountBondsTest::tearDown()
119{
120 // remove the file
121 delete(BG);
122
123 World::purgeInstance();
124 MemoryUsageObserver::purgeInstance();
125};
126
127/** UnitTest for CountBondsTest::BondsOfTwoTest().
128 */
129void CountBondsTest::BondsOfTwoTest()
130{
131 CPPUNIT_ASSERT_EQUAL( 4 , CountBondsOfTwo(molecules, hydrogen, oxygen) );
132 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, hydrogen, hydrogen) );
133 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, oxygen, oxygen) );
134};
135
136/** UnitTest for CountBondsTest::BondsOfThreeTest().
137 */
138void CountBondsTest::BondsOfThreeTest()
139{
140 CPPUNIT_ASSERT_EQUAL( 2 , CountBondsOfThree(molecules, hydrogen, oxygen, hydrogen) );
141 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfThree(molecules, oxygen, hydrogen, oxygen) );
142};
143
144void OutputTestMolecule(molecule *mol, const char *name)
145{
146 ofstream output(name);
147 mol->OutputXYZ(&output);
148 output.close();
149}
150
151/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
152 */
153void CountBondsTest::HydrogenBridgeBondsTest()
154{
155 double *mirror = new double[3];
156 for (int i=0;i<3;i++)
157 mirror[i] = -1.;
158 Vector Translator;
159
160 //OutputTestMolecule(TestMolecule1, "testmolecule1.xyz");
161
162 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
163 Translator = Vector(3,0,0);
164 TestMolecule2->Translate(&Translator);
165 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
166 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
167 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
168 Translator = Vector(-3,0,0);
169 TestMolecule2->Translate(&Translator);
170
171 cout << "Case 2: offset of (0,3,0), hence angle are (14.5, 165.5, 90) < 30 (only three, because other 90 is missing due to first H01 only fulfilling H-bond criteria)." << endl;
172 Translator = Vector(0,3,0);
173 TestMolecule2->Translate(&Translator);
174 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
175 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
176 Translator = Vector(0,-3,0);
177 TestMolecule2->Translate(&Translator);
178
179 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
180 Translator = Vector(0,-3,0);
181 TestMolecule2->Scale((const double ** const)&mirror);
182 TestMolecule2->Translate(&Translator);
183 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
184 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
185 Translator = Vector(0,3,0);
186 TestMolecule2->Translate(&Translator);
187 TestMolecule2->Scale((const double ** const)&mirror);
188
189 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
190 Translator = Vector(2,1,0);
191 TestMolecule2->Translate(&Translator);
192 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
193 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
194 Translator = Vector(-2,-1,0);
195 TestMolecule2->Translate(&Translator);
196
197 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
198 Translator = Vector(0,0,3);
199 TestMolecule2->Translate(&Translator);
200 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
201 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
202 Translator = Vector(0,0,-3);
203 TestMolecule2->Translate(&Translator);
204
205 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
206 Translator = Vector(-3,0,0);
207 TestMolecule2->Scale((const double ** const)&mirror);
208 TestMolecule2->Translate(&Translator);
209 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
210 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
211 Translator = Vector(3,0,0);
212 TestMolecule2->Translate(&Translator);
213 TestMolecule2->Scale((const double ** const)&mirror);
214
215 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
216 Translator = Vector(3,0,0);
217 TestMolecule2->Scale((const double ** const)&mirror);
218 TestMolecule2->Translate(&Translator);
219 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
220 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
221 Translator = Vector(-3,0,0);
222 TestMolecule2->Translate(&Translator);
223 TestMolecule2->Scale((const double ** const)&mirror);
224
225 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
226 Translator = Vector(0,3,0);
227 TestMolecule2->Scale((const double ** const)&mirror);
228 TestMolecule2->Translate(&Translator);
229 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
230 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
231 Translator = Vector(0,-3,0);
232 TestMolecule2->Translate(&Translator);
233 TestMolecule2->Scale((const double ** const)&mirror);
234
235 delete[](mirror);
236};
Note: See TracBrowser for help on using the repository browser.