source: src/unittests/CountBondsUnitTest.cpp@ 26cf17

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 26cf17 was bf3817, checked in by Frederik Heber <heber@…>, 15 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
RevLine 
[dfe8ef]1/*
2 * CountBondsUnitTest.cpp
3 *
4 * Created on: Mar 30, 2010
5 * Author: heber
6 */
7
[bf3817]8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
[dfe8ef]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
[4eb4fe]23#include "Helpers/Assert.hpp"
24
[388049]25#include "analysis_bonds.hpp"
[dfe8ef]26#include "atom.hpp"
27#include "bond.hpp"
28#include "bondgraph.hpp"
29#include "element.hpp"
30#include "molecule.hpp"
31#include "periodentafel.hpp"
[5f612ee]32#include "World.hpp"
[dfe8ef]33#include "CountBondsUnitTest.hpp"
34
[5f612ee]35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
[dfe8ef]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
[4eb4fe]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");
[dfe8ef]54
55 // construct molecule (water molecule)
[5f612ee]56 TestMolecule1 = World::getInstance().createMolecule();
[4eb4fe]57 CPPUNIT_ASSERT(TestMolecule1 != NULL && "could not create first molecule");
[5f612ee]58 Walker = World::getInstance().createAtom();
[4eb4fe]59 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]60 Walker->setType(hydrogen);
61 Walker->setPosition(Vector(-0.2418, 0.9350, 0. ));
[dfe8ef]62 TestMolecule1->AddAtom(Walker);
[5f612ee]63 Walker = World::getInstance().createAtom();
[4eb4fe]64 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]65 Walker->setType(hydrogen);
66 Walker->setPosition(Vector(0.9658, 0., 0. ));
[dfe8ef]67 TestMolecule1->AddAtom(Walker);
[5f612ee]68 Walker = World::getInstance().createAtom();
[4eb4fe]69 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]70 Walker->setType(oxygen);
71 Walker->setPosition(Vector(0., 0., 0. ));
[dfe8ef]72 TestMolecule1->AddAtom(Walker);
73
[5f612ee]74 TestMolecule2 = World::getInstance().createMolecule();
[4eb4fe]75 CPPUNIT_ASSERT(TestMolecule2 != NULL && "could not create second molecule");
[5f612ee]76 Walker = World::getInstance().createAtom();
[4eb4fe]77 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]78 Walker->setType(hydrogen);
79 Walker->setPosition(Vector(-0.2418, 0.9350, 0. ));
[dfe8ef]80 TestMolecule2->AddAtom(Walker);
[5f612ee]81 Walker = World::getInstance().createAtom();
[4eb4fe]82 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]83 Walker->setType(hydrogen);
84 Walker->setPosition(Vector(0.9658, 0., 0. ));
[dfe8ef]85 TestMolecule2->AddAtom(Walker);
[5f612ee]86 Walker = World::getInstance().createAtom();
[4eb4fe]87 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]88 Walker->setType(oxygen);
89 Walker->setPosition(Vector(0., 0., 0. ));
[dfe8ef]90 TestMolecule2->AddAtom(Walker);
[5f612ee]91
92 molecules = World::getInstance().getMolecules();
[4eb4fe]93 CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules");
[5f612ee]94 molecules->insert(TestMolecule1);
[dfe8ef]95 molecules->insert(TestMolecule2);
96
97 // check that TestMolecule was correctly constructed
[a7b761b]98 CPPUNIT_ASSERT_EQUAL( TestMolecule1->getAtomCount(), 3 );
99 CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
[dfe8ef]100
101 // create a small file with table
102 BG = new BondGraph(true);
[4eb4fe]103 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
[dfe8ef]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
[5f612ee]118 World::purgeInstance();
[dfe8ef]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
[62c9c0]138void OutputTestMolecule(molecule *mol, const char *name)
139{
140 ofstream output(name);
141 mol->OutputXYZ(&output);
142 output.close();
143}
144
[dfe8ef]145/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
146 */
147void CountBondsTest::HydrogenBridgeBondsTest()
148{
149 double *mirror = new double[3];
[4eb4fe]150 CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
[dfe8ef]151 for (int i=0;i<3;i++)
152 mirror[i] = -1.;
153 Vector Translator;
[62c9c0]154
155 //OutputTestMolecule(TestMolecule1, "testmolecule1.xyz");
156
[fe238c]157 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
[8cbb97]158 Translator = Vector(3,0,0);
[dfe8ef]159 TestMolecule2->Translate(&Translator);
[bfd839]160 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
161 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen, NULL) );
[62c9c0]162 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
[8cbb97]163 Translator = Vector(-3,0,0);
[dfe8ef]164 TestMolecule2->Translate(&Translator);
165
[fe238c]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;
[8cbb97]167 Translator = Vector(0,3,0);
[dfe8ef]168 TestMolecule2->Translate(&Translator);
[bfd839]169 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[62c9c0]170 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
[8cbb97]171 Translator = Vector(0,-3,0);
[dfe8ef]172 TestMolecule2->Translate(&Translator);
173
[fe238c]174 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
[8cbb97]175 Translator = Vector(0,-3,0);
[dfe8ef]176 TestMolecule2->Scale((const double ** const)&mirror);
177 TestMolecule2->Translate(&Translator);
[bfd839]178 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[62c9c0]179 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
[8cbb97]180 Translator = Vector(0,3,0);
[dfe8ef]181 TestMolecule2->Translate(&Translator);
182 TestMolecule2->Scale((const double ** const)&mirror);
183
[fe238c]184 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
[8cbb97]185 Translator = Vector(2,1,0);
[dfe8ef]186 TestMolecule2->Translate(&Translator);
[bfd839]187 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[62c9c0]188 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
[8cbb97]189 Translator = Vector(-2,-1,0);
[dfe8ef]190 TestMolecule2->Translate(&Translator);
191
[fe238c]192 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
[8cbb97]193 Translator = Vector(0,0,3);
[dfe8ef]194 TestMolecule2->Translate(&Translator);
[bfd839]195 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[62c9c0]196 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
[8cbb97]197 Translator = Vector(0,0,-3);
[dfe8ef]198 TestMolecule2->Translate(&Translator);
199
[fe238c]200 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
[8cbb97]201 Translator = Vector(-3,0,0);
[dfe8ef]202 TestMolecule2->Scale((const double ** const)&mirror);
203 TestMolecule2->Translate(&Translator);
[bfd839]204 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[62c9c0]205 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
[8cbb97]206 Translator = Vector(3,0,0);
[dfe8ef]207 TestMolecule2->Translate(&Translator);
208 TestMolecule2->Scale((const double ** const)&mirror);
[fe238c]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;
[8cbb97]211 Translator = Vector(3,0,0);
[fe238c]212 TestMolecule2->Scale((const double ** const)&mirror);
213 TestMolecule2->Translate(&Translator);
[bfd839]214 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[fe238c]215 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
[8cbb97]216 Translator = Vector(-3,0,0);
[fe238c]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;
[8cbb97]221 Translator = Vector(0,3,0);
[fe238c]222 TestMolecule2->Scale((const double ** const)&mirror);
223 TestMolecule2->Translate(&Translator);
224 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
[bfd839]225 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
[8cbb97]226 Translator = Vector(0,-3,0);
[fe238c]227 TestMolecule2->Translate(&Translator);
228 TestMolecule2->Scale((const double ** const)&mirror);
229
[5f612ee]230 delete[](mirror);
[dfe8ef]231};
Note: See TracBrowser for help on using the repository browser.