source: src/unittests/CountBondsUnitTest.cpp@ 13e3c3

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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