source: src/unittests/CountBondsUnitTest.cpp@ 1f91f4

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 1f91f4 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

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