| [4fbca9c] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * ParserTremoloUnitTest.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Mar 3, 2010 | 
|---|
|  | 12 | *      Author: metzler | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "ParserTremoloUnitTest.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
|  | 26 | #include "Parser/MpqcParser.hpp" | 
|---|
|  | 27 | #include "Parser/PdbParser.hpp" | 
|---|
|  | 28 | #include "Parser/PcpParser.hpp" | 
|---|
|  | 29 | #include "Parser/TremoloParser.hpp" | 
|---|
|  | 30 | #include "Parser/XyzParser.hpp" | 
|---|
|  | 31 | #include "World.hpp" | 
|---|
|  | 32 | #include "atom.hpp" | 
|---|
|  | 33 | #include "element.hpp" | 
|---|
|  | 34 | #include "periodentafel.hpp" | 
|---|
|  | 35 | #include "Descriptors/AtomTypeDescriptor.hpp" | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 38 | #include "UnitTestMain.hpp" | 
|---|
|  | 39 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 40 |  | 
|---|
|  | 41 | using namespace std; | 
|---|
|  | 42 |  | 
|---|
|  | 43 | // Registers the fixture into the 'registry' | 
|---|
|  | 44 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest ); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n"; | 
|---|
|  | 47 | static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; | 
|---|
|  | 48 | static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n"; | 
|---|
|  | 49 | static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n"; | 
|---|
|  | 50 | static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n"; | 
|---|
|  | 51 | static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; | 
|---|
|  | 52 | static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n"; | 
|---|
|  | 53 | static string Tremolo_full = "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t1\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n"; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | void ParserTremoloUnitTest::setUp() { | 
|---|
|  | 56 | World::getInstance(); | 
|---|
|  | 57 |  | 
|---|
|  | 58 | // we need hydrogens and oxygens in the following tests | 
|---|
|  | 59 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL); | 
|---|
|  | 60 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL); | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | void ParserTremoloUnitTest::tearDown() { | 
|---|
|  | 64 | ChangeTracker::purgeInstance(); | 
|---|
|  | 65 | World::purgeInstance(); | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
|  | 68 | /************************************ tests ***********************************/ | 
|---|
|  | 69 |  | 
|---|
|  | 70 | void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() { | 
|---|
|  | 71 | cout << "Testing the tremolo parser." << endl; | 
|---|
|  | 72 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 73 | stringstream input, output; | 
|---|
|  | 74 |  | 
|---|
|  | 75 | // Atomdata beginning with "# ATOMDATA" | 
|---|
| [73916f] | 76 | { | 
|---|
|  | 77 | input << Tremolo_Atomdata1; | 
|---|
|  | 78 | testParser->load(&input); | 
|---|
|  | 79 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 80 | testParser->save(&output, atoms); | 
|---|
|  | 81 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str()); | 
|---|
|  | 82 | input.clear(); | 
|---|
|  | 83 | output.clear(); | 
|---|
|  | 84 | } | 
|---|
| [4fbca9c] | 85 |  | 
|---|
|  | 86 | // Atomdata beginning with "#ATOMDATA" | 
|---|
| [73916f] | 87 | { | 
|---|
|  | 88 | input << Tremolo_Atomdata2; | 
|---|
|  | 89 | testParser->load(&input); | 
|---|
|  | 90 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 91 | testParser->save(&output, atoms); | 
|---|
|  | 92 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos); | 
|---|
|  | 93 | input.clear(); | 
|---|
|  | 94 | output.clear(); | 
|---|
|  | 95 | } | 
|---|
| [4fbca9c] | 96 |  | 
|---|
|  | 97 | // Invalid key in Atomdata line | 
|---|
|  | 98 | input << Tremolo_invalidkey; | 
|---|
|  | 99 | testParser->load(&input); | 
|---|
| [73916f] | 100 | //TODO: prove invalidity | 
|---|
| [4fbca9c] | 101 | input.clear(); | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() { | 
|---|
|  | 105 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 106 | stringstream input; | 
|---|
|  | 107 |  | 
|---|
|  | 108 | // One simple data line | 
|---|
|  | 109 | input << Tremolo_Atomdata2; | 
|---|
|  | 110 | testParser->load(&input); | 
|---|
|  | 111 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0); | 
|---|
|  | 112 | input.clear(); | 
|---|
|  | 113 | } | 
|---|
|  | 114 |  | 
|---|
|  | 115 | void ParserTremoloUnitTest::readTremoloVelocityTest() { | 
|---|
|  | 116 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 117 | stringstream input; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | // One simple data line | 
|---|
|  | 120 | input << Tremolo_velocity; | 
|---|
|  | 121 | testParser->load(&input); | 
|---|
|  | 122 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0); | 
|---|
|  | 123 | input.clear(); | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
|  | 126 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() { | 
|---|
|  | 127 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 128 | stringstream input; | 
|---|
|  | 129 |  | 
|---|
|  | 130 | // Neighbor data | 
|---|
|  | 131 | input << Tremolo_neighbours; | 
|---|
|  | 132 | testParser->load(&input); | 
|---|
|  | 133 |  | 
|---|
|  | 134 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
|  | 135 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))-> | 
|---|
|  | 136 | IsBondedTo(World::getInstance().getAtom(AtomByType(1)))); | 
|---|
|  | 137 | input.clear(); | 
|---|
|  | 138 | } | 
|---|
|  | 139 |  | 
|---|
|  | 140 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() { | 
|---|
|  | 141 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 142 | stringstream input, output; | 
|---|
|  | 143 |  | 
|---|
|  | 144 | // Neighbor data | 
|---|
| [73916f] | 145 | { | 
|---|
|  | 146 | input << Tremolo_improper; | 
|---|
|  | 147 | testParser->load(&input); | 
|---|
|  | 148 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 149 | testParser->save(&output, atoms); | 
|---|
|  | 150 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
|  | 151 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); | 
|---|
|  | 152 | input.clear(); | 
|---|
|  | 153 | output.clear(); | 
|---|
|  | 154 | } | 
|---|
| [4fbca9c] | 155 | } | 
|---|
|  | 156 |  | 
|---|
|  | 157 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() { | 
|---|
|  | 158 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 159 | stringstream input, output; | 
|---|
|  | 160 |  | 
|---|
|  | 161 | // Neighbor data | 
|---|
| [73916f] | 162 | { | 
|---|
|  | 163 | input << Tremolo_torsion; | 
|---|
|  | 164 | testParser->load(&input); | 
|---|
|  | 165 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 166 | testParser->save(&output, atoms); | 
|---|
|  | 167 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
|  | 168 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); | 
|---|
|  | 169 | input.clear(); | 
|---|
|  | 170 | output.clear(); | 
|---|
|  | 171 | } | 
|---|
| [4fbca9c] | 172 | } | 
|---|
|  | 173 |  | 
|---|
|  | 174 | void ParserTremoloUnitTest::writeTremoloTest() { | 
|---|
|  | 175 | TremoloParser* testParser = new TremoloParser(); | 
|---|
|  | 176 | stringstream output; | 
|---|
|  | 177 |  | 
|---|
|  | 178 | // with the maximum number of fields and minimal information, default values are printed | 
|---|
| [73916f] | 179 | { | 
|---|
|  | 180 | atom* newAtom = World::getInstance().createAtom(); | 
|---|
|  | 181 | newAtom->setType(1); | 
|---|
|  | 182 | testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion"); | 
|---|
|  | 183 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 184 | testParser->save(&output, atoms); | 
|---|
|  | 185 | CPPUNIT_ASSERT(output.str() == Tremolo_full); | 
|---|
|  | 186 | } | 
|---|
| [4fbca9c] | 187 |  | 
|---|
|  | 188 | cout << "testing the tremolo parser is done" << endl; | 
|---|
|  | 189 | } | 
|---|