| 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 |
|
|---|
| 20 | using 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'
|
|---|
| 52 | CPPUNIT_TEST_SUITE_REGISTRATION( CountBondsTest );
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | void 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 |
|
|---|
| 106 | void CountBondsTest::tearDown()
|
|---|
| 107 | {
|
|---|
| 108 | // remove the file
|
|---|
| 109 | delete(BG);
|
|---|
| 110 |
|
|---|
| 111 | World::purgeInstance();
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | /** UnitTest for CountBondsTest::BondsOfTwoTest().
|
|---|
| 115 | */
|
|---|
| 116 | void 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 | */
|
|---|
| 125 | void 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 |
|
|---|
| 131 | /** UnitTest for CountBondsTest::HydrogenBridgeBondsTest().
|
|---|
| 132 | */
|
|---|
| 133 | void CountBondsTest::HydrogenBridgeBondsTest()
|
|---|
| 134 | {
|
|---|
| 135 | double *mirror = new double[3];
|
|---|
| 136 | CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
|
|---|
| 137 | for (int i=0;i<3;i++)
|
|---|
| 138 | mirror[i] = -1.;
|
|---|
| 139 | Vector Translator;
|
|---|
| 140 |
|
|---|
| 141 | // create TestMolecule2 as copy
|
|---|
| 142 | TestMolecule2 = TestMolecule1->CopyMolecule();
|
|---|
| 143 | molecules->insert(TestMolecule2);
|
|---|
| 144 | CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
|
|---|
| 145 |
|
|---|
| 146 | cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
|
|---|
| 147 | Translator = Vector(3,0,0);
|
|---|
| 148 | TestMolecule1->Translate(&Translator);
|
|---|
| 149 | CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 150 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen, NULL) );
|
|---|
| 151 | Translator = Vector(-3,0,0);
|
|---|
| 152 | TestMolecule1->Translate(&Translator);
|
|---|
| 153 |
|
|---|
| 154 | 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;
|
|---|
| 155 | Translator = Vector(0,3,0);
|
|---|
| 156 | TestMolecule1->Translate(&Translator);
|
|---|
| 157 | CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 158 | Translator = Vector(0,-3,0);
|
|---|
| 159 | TestMolecule1->Translate(&Translator);
|
|---|
| 160 |
|
|---|
| 161 | cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
|
|---|
| 162 | Translator = Vector(0,-3,0);
|
|---|
| 163 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 164 | TestMolecule1->Translate(&Translator);
|
|---|
| 165 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 166 | Translator = Vector(0,3,0);
|
|---|
| 167 | TestMolecule1->Translate(&Translator);
|
|---|
| 168 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 169 |
|
|---|
| 170 | cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
|
|---|
| 171 | Translator = Vector(2,1,0);
|
|---|
| 172 | TestMolecule1->Translate(&Translator);
|
|---|
| 173 | CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 174 | Translator = Vector(-2,-1,0);
|
|---|
| 175 | TestMolecule1->Translate(&Translator);
|
|---|
| 176 |
|
|---|
| 177 | cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
|
|---|
| 178 | Translator = Vector(0,0,3);
|
|---|
| 179 | TestMolecule1->Translate(&Translator);
|
|---|
| 180 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 181 | Translator = Vector(0,0,-3);
|
|---|
| 182 | TestMolecule1->Translate(&Translator);
|
|---|
| 183 |
|
|---|
| 184 | cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
|
|---|
| 185 | Translator = Vector(-3,0,0);
|
|---|
| 186 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 187 | TestMolecule1->Translate(&Translator);
|
|---|
| 188 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 189 | Translator = Vector(3,0,0);
|
|---|
| 190 | TestMolecule1->Translate(&Translator);
|
|---|
| 191 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 192 |
|
|---|
| 193 | cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
|
|---|
| 194 | Translator = Vector(3,0,0);
|
|---|
| 195 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 196 | TestMolecule1->Translate(&Translator);
|
|---|
| 197 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 198 | Translator = Vector(-3,0,0);
|
|---|
| 199 | TestMolecule1->Translate(&Translator);
|
|---|
| 200 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 201 |
|
|---|
| 202 | cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
|
|---|
| 203 | Translator = Vector(0,3,0);
|
|---|
| 204 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 205 | TestMolecule1->Translate(&Translator);
|
|---|
| 206 | CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
|
|---|
| 207 | Translator = Vector(0,-3,0);
|
|---|
| 208 | TestMolecule1->Translate(&Translator);
|
|---|
| 209 | TestMolecule1->Scale((const double ** const)&mirror);
|
|---|
| 210 |
|
|---|
| 211 | delete[](mirror);
|
|---|
| 212 | };
|
|---|