source: src/unittests/CountBondsUnitTest.cpp@ 673c7f

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 673c7f was 4eb4fe, checked in by Frederik Heber <heber@…>, 15 years ago

"-e <db path>" not necessary anymore.

Removed necessity of specifying path to databases (this was one check of molecuilder/test/testsuite.at which cannot be fulfilled anymore with boost::program_options)
For this to work a great number of small changes have been necessary:

class periodentafel:

  • all .db files merged into const char * arrays in elements_db.cpp
  • periodentafel rewritten:
  • FindElement(), AskElement() and EnterElement return element * const instead of const element * (i.e. the contents of the pointer is const (the element) not the pointer itself which is very vexatious (i.e. FindElement() yields const element * which can subsequently not be used for RemoveElement(), ...)
  • parsedElems is not needed anymore. Instead we operate on map elements directly
  • new unittest periodentafelTest which is made friend of periodentafel to be able to access private loading functions directly

A number of unit tests had to be changed (all that create elements during setUp() which is now unnecessary)

Some of the analysis_bonds function's signatures were changed in the process:

Finally, the respective tests are removed from molecuilder/tests/testsuite.at.

  • 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
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 "Helpers/Assert.hpp"
20
21#include "analysis_bonds.hpp"
22#include "atom.hpp"
23#include "bond.hpp"
24#include "bondgraph.hpp"
25#include "element.hpp"
26#include "molecule.hpp"
27#include "periodentafel.hpp"
28#include "World.hpp"
29#include "CountBondsUnitTest.hpp"
30
31#ifdef HAVE_TESTRUNNER
32#include "UnitTestMain.hpp"
33#endif /*HAVE_TESTRUNNER*/
34
35/********************************************** Test classes **************************************/
36
37// Registers the fixture into the 'registry'
38CPPUNIT_TEST_SUITE_REGISTRATION( CountBondsTest );
39
40
41void CountBondsTest::setUp()
42{
43 atom *Walker = NULL;
44
45 // construct element
46 hydrogen = World::getInstance().getPeriode()->FindElement(1);
47 oxygen = World::getInstance().getPeriode()->FindElement(8);
48 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
49 CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
50
51 // construct molecule (water molecule)
52 TestMolecule1 = World::getInstance().createMolecule();
53 CPPUNIT_ASSERT(TestMolecule1 != NULL && "could not create first molecule");
54 Walker = World::getInstance().createAtom();
55 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
56 Walker->type = hydrogen;
57 *Walker->node = Vector(-0.2418, 0.9350, 0. );
58 TestMolecule1->AddAtom(Walker);
59 Walker = World::getInstance().createAtom();
60 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
61 Walker->type = hydrogen;
62 *Walker->node = Vector(0.9658, 0., 0. );
63 TestMolecule1->AddAtom(Walker);
64 Walker = World::getInstance().createAtom();
65 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
66 Walker->type = oxygen;
67 *Walker->node = Vector(0., 0., 0. );
68 TestMolecule1->AddAtom(Walker);
69
70 TestMolecule2 = World::getInstance().createMolecule();
71 CPPUNIT_ASSERT(TestMolecule2 != NULL && "could not create second molecule");
72 Walker = World::getInstance().createAtom();
73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
74 Walker->type = hydrogen;
75 *Walker->node = Vector(-0.2418, 0.9350, 0. );
76 TestMolecule2->AddAtom(Walker);
77 Walker = World::getInstance().createAtom();
78 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
79 Walker->type = hydrogen;
80 *Walker->node = Vector(0.9658, 0., 0. );
81 TestMolecule2->AddAtom(Walker);
82 Walker = World::getInstance().createAtom();
83 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
84 Walker->type = oxygen;
85 *Walker->node = Vector(0., 0., 0. );
86 TestMolecule2->AddAtom(Walker);
87
88 molecules = World::getInstance().getMolecules();
89 CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules");
90 molecules->insert(TestMolecule1);
91 molecules->insert(TestMolecule2);
92
93 // check that TestMolecule was correctly constructed
94 CPPUNIT_ASSERT_EQUAL( TestMolecule1->AtomCount, 3 );
95 Walker = TestMolecule1->start->next;
96 CPPUNIT_ASSERT( TestMolecule1->end != Walker );
97 CPPUNIT_ASSERT_EQUAL( TestMolecule2->AtomCount, 3 );
98 Walker = TestMolecule2->start->next;
99 CPPUNIT_ASSERT( TestMolecule2->end != Walker );
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 MemoryUsageObserver::purgeInstance();
120};
121
122/** UnitTest for CountBondsTest::BondsOfTwoTest().
123 */
124void CountBondsTest::BondsOfTwoTest()
125{
126 CPPUNIT_ASSERT_EQUAL( 4 , CountBondsOfTwo(molecules, hydrogen, oxygen) );
127 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, hydrogen, hydrogen) );
128 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, oxygen, oxygen) );
129};
130
131/** UnitTest for CountBondsTest::BondsOfThreeTest().
132 */
133void CountBondsTest::BondsOfThreeTest()
134{
135 CPPUNIT_ASSERT_EQUAL( 2 , CountBondsOfThree(molecules, hydrogen, oxygen, hydrogen) );
136 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfThree(molecules, oxygen, hydrogen, oxygen) );
137};
138
139void OutputTestMolecule(molecule *mol, const char *name)
140{
141 ofstream output(name);
142 mol->OutputXYZ(&output);
143 output.close();
144}
145
146/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
147 */
148void CountBondsTest::HydrogenBridgeBondsTest()
149{
150 double *mirror = new double[3];
151 CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
152 for (int i=0;i<3;i++)
153 mirror[i] = -1.;
154 Vector Translator;
155
156 //OutputTestMolecule(TestMolecule1, "testmolecule1.xyz");
157
158 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
159 Translator = Vector(3,0,0);
160 TestMolecule2->Translate(&Translator);
161 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
162 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
163 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
164 Translator = Vector(-3,0,0);
165 TestMolecule2->Translate(&Translator);
166
167 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;
168 Translator = Vector(0,3,0);
169 TestMolecule2->Translate(&Translator);
170 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
171 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
172 Translator = Vector(0,-3,0);
173 TestMolecule2->Translate(&Translator);
174
175 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
176 Translator = Vector(0,-3,0);
177 TestMolecule2->Scale((const double ** const)&mirror);
178 TestMolecule2->Translate(&Translator);
179 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
180 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
181 Translator = Vector(0,3,0);
182 TestMolecule2->Translate(&Translator);
183 TestMolecule2->Scale((const double ** const)&mirror);
184
185 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
186 Translator = Vector(2,1,0);
187 TestMolecule2->Translate(&Translator);
188 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
189 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
190 Translator = Vector(-2,-1,0);
191 TestMolecule2->Translate(&Translator);
192
193 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
194 Translator = Vector(0,0,3);
195 TestMolecule2->Translate(&Translator);
196 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
197 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
198 Translator = Vector(0,0,-3);
199 TestMolecule2->Translate(&Translator);
200
201 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
202 Translator = Vector(-3,0,0);
203 TestMolecule2->Scale((const double ** const)&mirror);
204 TestMolecule2->Translate(&Translator);
205 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
206 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
207 Translator = Vector(3,0,0);
208 TestMolecule2->Translate(&Translator);
209 TestMolecule2->Scale((const double ** const)&mirror);
210
211 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
212 Translator = Vector(3,0,0);
213 TestMolecule2->Scale((const double ** const)&mirror);
214 TestMolecule2->Translate(&Translator);
215 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
216 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
217 Translator = Vector(-3,0,0);
218 TestMolecule2->Translate(&Translator);
219 TestMolecule2->Scale((const double ** const)&mirror);
220
221 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
222 Translator = Vector(0,3,0);
223 TestMolecule2->Scale((const double ** const)&mirror);
224 TestMolecule2->Translate(&Translator);
225 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
226 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
227 Translator = Vector(0,-3,0);
228 TestMolecule2->Translate(&Translator);
229 TestMolecule2->Scale((const double ** const)&mirror);
230
231 delete[](mirror);
232};
Note: See TracBrowser for help on using the repository browser.