source: src/unittests/CountBondsUnitTest.cpp@ 1024cb

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 1024cb was 1024cb, checked in by Frederik Heber <heber@…>, 15 years ago

Merge commit 'jupiter/MoleculeStartEndSwitch' into CommandLineActionMapping

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
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/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

Integration of MoleculeStartEndSwitch had the following consequences:

  • no more AtomCount -> getAtomCount()
  • no more start/end -> begin(), end() and iterator
  • no more decent ordering in atomic ids (hence, Simple_configuration/8 and Domain/5, Domain/6 now check by comparing sorted xyz, not confs)

There is still a huge problem with bonds. One test runs into an endless loop.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 8.2 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->getAtomCount(), 3 );
95 CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
96
97 // create a small file with table
98 BG = new BondGraph(true);
99 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
100
101 // construct bond graphs
102 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule1) );
103 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule2) );
104// TestMolecule1->Output((ofstream *)&cout);
105// TestMolecule1->OutputBondsList();
106};
107
108
109void CountBondsTest::tearDown()
110{
111 // remove the file
112 delete(BG);
113
114 World::purgeInstance();
115};
116
117/** UnitTest for CountBondsTest::BondsOfTwoTest().
118 */
119void CountBondsTest::BondsOfTwoTest()
120{
121 CPPUNIT_ASSERT_EQUAL( 4 , CountBondsOfTwo(molecules, hydrogen, oxygen) );
122 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, hydrogen, hydrogen) );
123 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, oxygen, oxygen) );
124};
125
126/** UnitTest for CountBondsTest::BondsOfThreeTest().
127 */
128void CountBondsTest::BondsOfThreeTest()
129{
130 CPPUNIT_ASSERT_EQUAL( 2 , CountBondsOfThree(molecules, hydrogen, oxygen, hydrogen) );
131 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfThree(molecules, oxygen, hydrogen, oxygen) );
132};
133
134void OutputTestMolecule(molecule *mol, const char *name)
135{
136 ofstream output(name);
137 mol->OutputXYZ(&output);
138 output.close();
139}
140
141/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
142 */
143void CountBondsTest::HydrogenBridgeBondsTest()
144{
145 double *mirror = new double[3];
146 CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
147 for (int i=0;i<3;i++)
148 mirror[i] = -1.;
149 Vector Translator;
150
151 //OutputTestMolecule(TestMolecule1, "testmolecule1.xyz");
152
153 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
154 Translator = Vector(3,0,0);
155 TestMolecule2->Translate(&Translator);
156 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
157 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
158 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
159 Translator = Vector(-3,0,0);
160 TestMolecule2->Translate(&Translator);
161
162 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;
163 Translator = Vector(0,3,0);
164 TestMolecule2->Translate(&Translator);
165 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
166 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
167 Translator = Vector(0,-3,0);
168 TestMolecule2->Translate(&Translator);
169
170 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
171 Translator = Vector(0,-3,0);
172 TestMolecule2->Scale((const double ** const)&mirror);
173 TestMolecule2->Translate(&Translator);
174 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
175 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
176 Translator = Vector(0,3,0);
177 TestMolecule2->Translate(&Translator);
178 TestMolecule2->Scale((const double ** const)&mirror);
179
180 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
181 Translator = Vector(2,1,0);
182 TestMolecule2->Translate(&Translator);
183 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
184 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
185 Translator = Vector(-2,-1,0);
186 TestMolecule2->Translate(&Translator);
187
188 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
189 Translator = Vector(0,0,3);
190 TestMolecule2->Translate(&Translator);
191 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
192 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
193 Translator = Vector(0,0,-3);
194 TestMolecule2->Translate(&Translator);
195
196 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
197 Translator = Vector(-3,0,0);
198 TestMolecule2->Scale((const double ** const)&mirror);
199 TestMolecule2->Translate(&Translator);
200 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
201 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
202 Translator = Vector(3,0,0);
203 TestMolecule2->Translate(&Translator);
204 TestMolecule2->Scale((const double ** const)&mirror);
205
206 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
207 Translator = Vector(3,0,0);
208 TestMolecule2->Scale((const double ** const)&mirror);
209 TestMolecule2->Translate(&Translator);
210 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
211 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
212 Translator = Vector(-3,0,0);
213 TestMolecule2->Translate(&Translator);
214 TestMolecule2->Scale((const double ** const)&mirror);
215
216 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
217 Translator = Vector(0,3,0);
218 TestMolecule2->Scale((const double ** const)&mirror);
219 TestMolecule2->Translate(&Translator);
220 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
221 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
222 Translator = Vector(0,-3,0);
223 TestMolecule2->Translate(&Translator);
224 TestMolecule2->Scale((const double ** const)&mirror);
225
226 delete[](mirror);
227};
Note: See TracBrowser for help on using the repository browser.