source: src/unittests/CountBondsUnitTest.cpp@ c6efc1

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 c6efc1 was 8cbb97, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.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/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[dfe8ef]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
[388049]19#include "analysis_bonds.hpp"
[dfe8ef]20#include "atom.hpp"
21#include "bond.hpp"
22#include "bondgraph.hpp"
23#include "element.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
[5f612ee]26#include "World.hpp"
[dfe8ef]27#include "CountBondsUnitTest.hpp"
28
[5f612ee]29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
[dfe8ef]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;
[5f612ee]42 BG = NULL;
43 filename = NULL;
[dfe8ef]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
[5f612ee]66 tafel = World::getInstance().getPeriode();
[dfe8ef]67 tafel->AddElement(hydrogen);
68 tafel->AddElement(oxygen);
69
70 // construct molecule (water molecule)
[5f612ee]71 TestMolecule1 = World::getInstance().createMolecule();
72 Walker = World::getInstance().createAtom();
[dfe8ef]73 Walker->type = hydrogen;
[8cbb97]74 *Walker->node = Vector(-0.2418, 0.9350, 0. );
[dfe8ef]75 TestMolecule1->AddAtom(Walker);
[5f612ee]76 Walker = World::getInstance().createAtom();
[dfe8ef]77 Walker->type = hydrogen;
[8cbb97]78 *Walker->node = Vector(0.9658, 0., 0. );
[dfe8ef]79 TestMolecule1->AddAtom(Walker);
[5f612ee]80 Walker = World::getInstance().createAtom();
[dfe8ef]81 Walker->type = oxygen;
[8cbb97]82 *Walker->node = Vector(0., 0., 0. );
[dfe8ef]83 TestMolecule1->AddAtom(Walker);
84
[5f612ee]85 TestMolecule2 = World::getInstance().createMolecule();
86 Walker = World::getInstance().createAtom();
[dfe8ef]87 Walker->type = hydrogen;
[8cbb97]88 *Walker->node = Vector(-0.2418, 0.9350, 0. );
[dfe8ef]89 TestMolecule2->AddAtom(Walker);
[5f612ee]90 Walker = World::getInstance().createAtom();
[dfe8ef]91 Walker->type = hydrogen;
[8cbb97]92 *Walker->node = Vector(0.9658, 0., 0. );
[dfe8ef]93 TestMolecule2->AddAtom(Walker);
[5f612ee]94 Walker = World::getInstance().createAtom();
[dfe8ef]95 Walker->type = oxygen;
[8cbb97]96 *Walker->node = Vector(0., 0., 0. );
[dfe8ef]97 TestMolecule2->AddAtom(Walker);
[5f612ee]98
99 molecules = World::getInstance().getMolecules();
100 molecules->insert(TestMolecule1);
[dfe8ef]101 molecules->insert(TestMolecule2);
102
103 // check that TestMolecule was correctly constructed
104 CPPUNIT_ASSERT_EQUAL( TestMolecule1->AtomCount, 3 );
105 Walker = TestMolecule1->start->next;
106 CPPUNIT_ASSERT( TestMolecule1->end != Walker );
107 CPPUNIT_ASSERT_EQUAL( TestMolecule2->AtomCount, 3 );
108 Walker = TestMolecule2->start->next;
109 CPPUNIT_ASSERT( TestMolecule2->end != Walker );
110
111 // create a small file with table
112 BG = new BondGraph(true);
113
114 // construct bond graphs
115 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule1) );
116 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule2) );
117// TestMolecule1->Output((ofstream *)&cout);
118// TestMolecule1->OutputBondsList();
119};
120
121
122void CountBondsTest::tearDown()
123{
124 // remove the file
125 delete(BG);
126
[5f612ee]127 World::purgeInstance();
128 MemoryUsageObserver::purgeInstance();
[dfe8ef]129};
130
131/** UnitTest for CountBondsTest::BondsOfTwoTest().
132 */
133void CountBondsTest::BondsOfTwoTest()
134{
135 CPPUNIT_ASSERT_EQUAL( 4 , CountBondsOfTwo(molecules, hydrogen, oxygen) );
136 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, hydrogen, hydrogen) );
137 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, oxygen, oxygen) );
138};
139
140/** UnitTest for CountBondsTest::BondsOfThreeTest().
141 */
142void CountBondsTest::BondsOfThreeTest()
143{
144 CPPUNIT_ASSERT_EQUAL( 2 , CountBondsOfThree(molecules, hydrogen, oxygen, hydrogen) );
145 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfThree(molecules, oxygen, hydrogen, oxygen) );
146};
147
[62c9c0]148void OutputTestMolecule(molecule *mol, const char *name)
149{
150 ofstream output(name);
151 mol->OutputXYZ(&output);
152 output.close();
153}
154
[dfe8ef]155/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
156 */
157void CountBondsTest::HydrogenBridgeBondsTest()
158{
159 double *mirror = new double[3];
160 for (int i=0;i<3;i++)
161 mirror[i] = -1.;
162 Vector Translator;
[62c9c0]163
164 //OutputTestMolecule(TestMolecule1, "testmolecule1.xyz");
165
[fe238c]166 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
[8cbb97]167 Translator = Vector(3,0,0);
[dfe8ef]168 TestMolecule2->Translate(&Translator);
169 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
170 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
[62c9c0]171 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
[8cbb97]172 Translator = Vector(-3,0,0);
[dfe8ef]173 TestMolecule2->Translate(&Translator);
174
[fe238c]175 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;
[8cbb97]176 Translator = Vector(0,3,0);
[dfe8ef]177 TestMolecule2->Translate(&Translator);
178 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
[62c9c0]179 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
[8cbb97]180 Translator = Vector(0,-3,0);
[dfe8ef]181 TestMolecule2->Translate(&Translator);
182
[fe238c]183 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
[8cbb97]184 Translator = Vector(0,-3,0);
[dfe8ef]185 TestMolecule2->Scale((const double ** const)&mirror);
186 TestMolecule2->Translate(&Translator);
187 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
[62c9c0]188 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
[8cbb97]189 Translator = Vector(0,3,0);
[dfe8ef]190 TestMolecule2->Translate(&Translator);
191 TestMolecule2->Scale((const double ** const)&mirror);
192
[fe238c]193 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
[8cbb97]194 Translator = Vector(2,1,0);
[dfe8ef]195 TestMolecule2->Translate(&Translator);
196 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
[62c9c0]197 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
[8cbb97]198 Translator = Vector(-2,-1,0);
[dfe8ef]199 TestMolecule2->Translate(&Translator);
200
[fe238c]201 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
[8cbb97]202 Translator = Vector(0,0,3);
[dfe8ef]203 TestMolecule2->Translate(&Translator);
204 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
[62c9c0]205 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
[8cbb97]206 Translator = Vector(0,0,-3);
[dfe8ef]207 TestMolecule2->Translate(&Translator);
208
[fe238c]209 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
[8cbb97]210 Translator = Vector(-3,0,0);
[dfe8ef]211 TestMolecule2->Scale((const double ** const)&mirror);
212 TestMolecule2->Translate(&Translator);
213 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
[62c9c0]214 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
[8cbb97]215 Translator = Vector(3,0,0);
[dfe8ef]216 TestMolecule2->Translate(&Translator);
217 TestMolecule2->Scale((const double ** const)&mirror);
[fe238c]218
219 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
[8cbb97]220 Translator = Vector(3,0,0);
[fe238c]221 TestMolecule2->Scale((const double ** const)&mirror);
222 TestMolecule2->Translate(&Translator);
223 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
224 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
[8cbb97]225 Translator = Vector(-3,0,0);
[fe238c]226 TestMolecule2->Translate(&Translator);
227 TestMolecule2->Scale((const double ** const)&mirror);
228
229 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
[8cbb97]230 Translator = Vector(0,3,0);
[fe238c]231 TestMolecule2->Scale((const double ** const)&mirror);
232 TestMolecule2->Translate(&Translator);
233 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
234 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
[8cbb97]235 Translator = Vector(0,-3,0);
[fe238c]236 TestMolecule2->Translate(&Translator);
237 TestMolecule2->Scale((const double ** const)&mirror);
238
[5f612ee]239 delete[](mirror);
[dfe8ef]240};
Note: See TracBrowser for help on using the repository browser.