source: src/Analysis/unittests/CountBondsUnitTest.cpp@ 826e8c

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 826e8c was 826e8c, checked in by Frederik Heber <heber@…>, 13 years ago

Introduced new LinkedCell into BondGraph.

  • new convenience functions BondGraph::getDomain(), ::getLinkedCell(), ::getTime() to have World dependency not in header file (circular include).
  • new function BondGraph::getMaxPossibleBondDistance() where one element is given.
  • dropped BondGraph::CreateAdjacency(LC_deprecated) as functionality is better placed directly into templated version directly.
  • rewrote templated BondGraph::CreateAdjacency that now makes use of LinkedCell_View::getAllNeighbours().
  • FIX: BondGraph::CreateAdjacency() created bonds for atom's fathers, not for atoms.
  • TESTFIX: New LinkedCell construct in BondGraph::CreateAdjacency changes order of ids in adjacency file:
    • ids are now in order (unlike to before), hence we simply use the new file in the regression test.
    • this is actually a fault of the test, not of the code as order of ids is not guaranteed in the file anyway.
  • TESTFIX: Removed XFAILs from regression test Graph/SubgraphDissection- BoundaryCondition.
  • TESTFIX: CountBondsUnitTest use two molecules that are on top of each other: This causes mess with changed LinkedCell BondGraph recognition, and we even actually need just one molecule for the testing.
  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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/analysis_bonds.hpp"
33#include "Atom/atom.hpp"
34#include "Bond/bond.hpp"
35#include "CodePatterns/Log.hpp"
36#include "Element/element.hpp"
37#include "Element/periodentafel.hpp"
38#include "Graph/BondGraph.hpp"
39#include "molecule.hpp"
40#include "MoleculeListClass.hpp"
41#include "World.hpp"
42
43#include "CountBondsUnitTest.hpp"
44
45#ifdef HAVE_TESTRUNNER
46#include "UnitTestMain.hpp"
47#endif /*HAVE_TESTRUNNER*/
48
49/********************************************** Test classes **************************************/
50
51// Registers the fixture into the 'registry'
52CPPUNIT_TEST_SUITE_REGISTRATION( CountBondsTest );
53
54
55void CountBondsTest::setUp()
56{
57 atom *Walker = NULL;
58
59 // construct element
60 hydrogen = World::getInstance().getPeriode()->FindElement(1);
61 oxygen = World::getInstance().getPeriode()->FindElement(8);
62 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
63 CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
64
65 //setVerbosity(3);
66
67 // construct molecule (water molecule)
68 TestMolecule1 = World::getInstance().createMolecule();
69 CPPUNIT_ASSERT(TestMolecule1 != NULL && "could not create second molecule");
70 Walker = World::getInstance().createAtom();
71 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
72 Walker->setType(hydrogen);
73 Walker->setPosition(Vector(-0.2418, 0.9350, 0. ));
74 TestMolecule1->AddAtom(Walker);
75 Walker = World::getInstance().createAtom();
76 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
77 Walker->setType(hydrogen);
78 Walker->setPosition(Vector(0.9658, 0., 0. ));
79 TestMolecule1->AddAtom(Walker);
80 Walker = World::getInstance().createAtom();
81 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
82 Walker->setType(oxygen);
83 Walker->setPosition(Vector(0., 0., 0. ));
84 TestMolecule1->AddAtom(Walker);
85
86 molecules = World::getInstance().getMolecules();
87 CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules");
88 molecules->insert(TestMolecule1);
89
90 // check that TestMolecule1 was correctly constructed
91 CPPUNIT_ASSERT_EQUAL( TestMolecule1->getAtomCount(), 3 );
92
93 // create a small file with table
94 BG = new BondGraph(true);
95 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
96
97 // construct bond graphs
98 World::AtomComposite Set1 = TestMolecule1->getAtomSet();
99 BG->CreateAdjacency(Set1);
100 CPPUNIT_ASSERT( TestMolecule1->getBondCount() != 0);
101// TestMolecule1->Output((ofstream *)&cout);
102// TestMolecule1->OutputBondsList(std::cout);
103};
104
105
106void CountBondsTest::tearDown()
107{
108 // remove the file
109 delete(BG);
110
111 World::purgeInstance();
112};
113
114/** UnitTest for CountBondsTest::BondsOfTwoTest().
115 */
116void CountBondsTest::BondsOfTwoTest()
117{
118 CPPUNIT_ASSERT_EQUAL( 2 , CountBondsOfTwo(molecules, hydrogen, oxygen) );
119 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, hydrogen, hydrogen) );
120 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfTwo(molecules, oxygen, oxygen) );
121};
122
123/** UnitTest for CountBondsTest::BondsOfThreeTest().
124 */
125void CountBondsTest::BondsOfThreeTest()
126{
127 CPPUNIT_ASSERT_EQUAL( 1 , CountBondsOfThree(molecules, hydrogen, oxygen, hydrogen) );
128 CPPUNIT_ASSERT_EQUAL( 0 , CountBondsOfThree(molecules, oxygen, hydrogen, oxygen) );
129};
130
131void OutputTestMolecule1(molecule *mol, const char *name)
132{
133 ofstream output(name);
134 mol->OutputXYZ(&output);
135 output.close();
136}
137
138/** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
139 */
140void CountBondsTest::HydrogenBridgeBondsTest()
141{
142 double *mirror = new double[3];
143 CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
144 for (int i=0;i<3;i++)
145 mirror[i] = -1.;
146 Vector Translator;
147
148 //OutputTestMolecule1(TestMolecule1, "testmolecule1.xyz");
149
150 // create TestMolecule2 as copy
151 TestMolecule2 = TestMolecule1->CopyMolecule();
152 molecules->insert(TestMolecule2);
153 CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
154
155 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
156 Translator = Vector(3,0,0);
157 TestMolecule1->Translate(&Translator);
158 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
159 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen, NULL) );
160 //OutputTestMolecule1(TestMolecule1, "testmolecule2-1.xyz");
161 Translator = Vector(-3,0,0);
162 TestMolecule1->Translate(&Translator);
163
164 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;
165 Translator = Vector(0,3,0);
166 TestMolecule1->Translate(&Translator);
167 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
168 //OutputTestMolecule1(TestMolecule1, "testmolecule2-2.xyz");
169 Translator = Vector(0,-3,0);
170 TestMolecule1->Translate(&Translator);
171
172 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
173 Translator = Vector(0,-3,0);
174 TestMolecule1->Scale((const double ** const)&mirror);
175 TestMolecule1->Translate(&Translator);
176 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
177 //OutputTestMolecule1(TestMolecule1, "testmolecule2-3.xyz");
178 Translator = Vector(0,3,0);
179 TestMolecule1->Translate(&Translator);
180 TestMolecule1->Scale((const double ** const)&mirror);
181
182 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
183 Translator = Vector(2,1,0);
184 TestMolecule1->Translate(&Translator);
185 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
186 //OutputTestMolecule1(TestMolecule1, "testmolecule2-4.xyz");
187 Translator = Vector(-2,-1,0);
188 TestMolecule1->Translate(&Translator);
189
190 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
191 Translator = Vector(0,0,3);
192 TestMolecule1->Translate(&Translator);
193 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
194 //OutputTestMolecule1(TestMolecule1, "testmolecule2-5.xyz");
195 Translator = Vector(0,0,-3);
196 TestMolecule1->Translate(&Translator);
197
198 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
199 Translator = Vector(-3,0,0);
200 TestMolecule1->Scale((const double ** const)&mirror);
201 TestMolecule1->Translate(&Translator);
202 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
203 //OutputTestMolecule1(TestMolecule1, "testmolecule2-6.xyz");
204 Translator = Vector(3,0,0);
205 TestMolecule1->Translate(&Translator);
206 TestMolecule1->Scale((const double ** const)&mirror);
207
208 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
209 Translator = Vector(3,0,0);
210 TestMolecule1->Scale((const double ** const)&mirror);
211 TestMolecule1->Translate(&Translator);
212 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
213 //OutputTestMolecule1(TestMolecule1, "testmolecule2-7.xyz");
214 Translator = Vector(-3,0,0);
215 TestMolecule1->Translate(&Translator);
216 TestMolecule1->Scale((const double ** const)&mirror);
217
218 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
219 Translator = Vector(0,3,0);
220 TestMolecule1->Scale((const double ** const)&mirror);
221 TestMolecule1->Translate(&Translator);
222 //OutputTestMolecule1(TestMolecule1, "testmolecule2-8.xyz");
223 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
224 Translator = Vector(0,-3,0);
225 TestMolecule1->Translate(&Translator);
226 TestMolecule1->Scale((const double ** const)&mirror);
227
228 delete[](mirror);
229};
Note: See TracBrowser for help on using the repository browser.