source: src/unittests/CountBondsUnitTest.cpp@ 906822

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