| [4fbca9c] | 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| [0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| [4fbca9c] | 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 |
|
|---|
| [5a667d] | 26 | #include "CodePatterns/Log.hpp"
|
|---|
| 27 |
|
|---|
| [6f0841] | 28 | #include "Atom/atom.hpp"
|
|---|
| [006e1e] | 29 | #include "Atom/AtomObserver.hpp"
|
|---|
| [073a9e4] | 30 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
|---|
| [3bdb6d] | 31 | #include "Element/element.hpp"
|
|---|
| 32 | #include "Element/periodentafel.hpp"
|
|---|
| [4fbca9c] | 33 | #include "Parser/TremoloParser.hpp"
|
|---|
| [765f16] | 34 | #include "Parser/ChangeTracker.hpp"
|
|---|
| [073a9e4] | 35 | #include "World.hpp"
|
|---|
| 36 | #include "WorldTime.hpp"
|
|---|
| [4fbca9c] | 37 |
|
|---|
| 38 | #ifdef HAVE_TESTRUNNER
|
|---|
| 39 | #include "UnitTestMain.hpp"
|
|---|
| 40 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 41 |
|
|---|
| 42 | using namespace std;
|
|---|
| 43 |
|
|---|
| 44 | // Registers the fixture into the 'registry'
|
|---|
| 45 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest );
|
|---|
| 46 |
|
|---|
| [4d4d33] | 47 | static string Tremolo_Atomdata1 = "\
|
|---|
| [ccb487] | 48 | # ATOMDATA\tId\tname\ttype\tx=3\n\
|
|---|
| 49 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
|
|---|
| [4d4d33] | 50 | static string Tremolo_Atomdata2 = "\
|
|---|
| 51 | #\n\
|
|---|
| [305e7e] | 52 | #ATOMDATA Id name type x=3\n\
|
|---|
| [ccb487] | 53 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 54 | 1 hydrogen H 3.0 4.5 0.1\n\
|
|---|
| 55 | \n";
|
|---|
| 56 | static string Tremolo_invalidkey = "\
|
|---|
| 57 | #\n\
|
|---|
| [305e7e] | 58 | #ATOMDATA Id name foo type x=3\n\
|
|---|
| [ccb487] | 59 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 60 | \n\n";
|
|---|
| 61 | static string Tremolo_velocity = "\
|
|---|
| 62 | #\n\
|
|---|
| [305e7e] | 63 | #ATOMDATA Id name type u=3\n\
|
|---|
| [ccb487] | 64 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 65 | 1 hydrogen H 3.0 4.5 0.1\n\
|
|---|
| 66 | \n";
|
|---|
| 67 | static string Tremolo_neighbours = "#\n\
|
|---|
| [305e7e] | 68 | #ATOMDATA Id type neighbors=2\n\
|
|---|
| [ccb487] | 69 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 70 | 1 H 3 0\n\
|
|---|
| 71 | 2 H 3 0\n\
|
|---|
| 72 | 3 O 1 2\n";
|
|---|
| 73 | static string Tremolo_improper = "\
|
|---|
| 74 | #\n\
|
|---|
| [305e7e] | 75 | #ATOMDATA Id type imprData\n\
|
|---|
| [ccb487] | 76 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 77 | 8 H 9-10\n\
|
|---|
| 78 | 9 H 10-8,8-10\n\
|
|---|
| 79 | 10 O -\n";
|
|---|
| 80 | static string Tremolo_torsion = "\
|
|---|
| 81 | #\n\
|
|---|
| [305e7e] | 82 | #ATOMDATA Id type torsion\n\
|
|---|
| [ccb487] | 83 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 84 | 8 H 9-10\n\
|
|---|
| 85 | 9 H 10-8,8-10\n\
|
|---|
| 86 | 10 O -\n";
|
|---|
| 87 | static string Tremolo_full = "\
|
|---|
| [305e7e] | 88 | # 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\n\
|
|---|
| [ccb487] | 89 | # Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
|
|---|
| [4d4d33] | 90 | 0\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";
|
|---|
| [4fbca9c] | 91 |
|
|---|
| 92 | void ParserTremoloUnitTest::setUp() {
|
|---|
| 93 | World::getInstance();
|
|---|
| 94 |
|
|---|
| [5a667d] | 95 | setVerbosity(5);
|
|---|
| 96 |
|
|---|
| [765f16] | 97 | parser = new FormatParser<tremolo>();
|
|---|
| 98 |
|
|---|
| [4fbca9c] | 99 | // we need hydrogens and oxygens in the following tests
|
|---|
| 100 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
|---|
| 101 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| [765f16] | 104 | void ParserTremoloUnitTest::tearDown()
|
|---|
| 105 | {
|
|---|
| 106 | delete parser;
|
|---|
| [4fbca9c] | 107 | ChangeTracker::purgeInstance();
|
|---|
| [006e1e] | 108 | AtomObserver::purgeInstance();
|
|---|
| [4fbca9c] | 109 | World::purgeInstance();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /************************************ tests ***********************************/
|
|---|
| 113 |
|
|---|
| 114 | void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
|
|---|
| 115 | cout << "Testing the tremolo parser." << endl;
|
|---|
| 116 | stringstream input, output;
|
|---|
| 117 |
|
|---|
| 118 | // Atomdata beginning with "# ATOMDATA"
|
|---|
| [73916f] | 119 | {
|
|---|
| 120 | input << Tremolo_Atomdata1;
|
|---|
| [765f16] | 121 | parser->load(&input);
|
|---|
| [73916f] | 122 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| [765f16] | 123 | parser->save(&output, atoms);
|
|---|
| [4d4d33] | 124 | // std::cout << output.str() << std::endl;
|
|---|
| 125 | // std::cout << Tremolo_Atomdata1 << std::endl;
|
|---|
| [73916f] | 126 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
|
|---|
| 127 | input.clear();
|
|---|
| 128 | output.clear();
|
|---|
| 129 | }
|
|---|
| [4fbca9c] | 130 |
|
|---|
| 131 | // Atomdata beginning with "#ATOMDATA"
|
|---|
| [73916f] | 132 | {
|
|---|
| 133 | input << Tremolo_Atomdata2;
|
|---|
| [765f16] | 134 | parser->load(&input);
|
|---|
| [73916f] | 135 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| [765f16] | 136 | parser->save(&output, atoms);
|
|---|
| [4d4d33] | 137 | std::cout << output.str() << std::endl;
|
|---|
| [73916f] | 138 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
|
|---|
| 139 | input.clear();
|
|---|
| 140 | output.clear();
|
|---|
| 141 | }
|
|---|
| [4fbca9c] | 142 |
|
|---|
| 143 | // Invalid key in Atomdata line
|
|---|
| 144 | input << Tremolo_invalidkey;
|
|---|
| [5a667d] | 145 | CPPUNIT_ASSERT_THROW( parser->load(&input), IllegalParserKeyException);
|
|---|
| [73916f] | 146 | //TODO: prove invalidity
|
|---|
| [4fbca9c] | 147 | input.clear();
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| [ca331c] | 150 | void ParserTremoloUnitTest::getsetAtomDataTest() {
|
|---|
| 151 | stringstream input;
|
|---|
| 152 | input << Tremolo_Atomdata1;
|
|---|
| 153 | parser->load(&input);
|
|---|
| 154 |
|
|---|
| 155 | CPPUNIT_ASSERT_EQUAL( std::string("Id name type x=3"), parser->getAtomData() );
|
|---|
| 156 |
|
|---|
| 157 | // overwrite keys
|
|---|
| 158 | const std::string fewkeys("Id type x=3 neighbors=2");
|
|---|
| 159 | parser->resetAtomData(fewkeys);
|
|---|
| 160 | CPPUNIT_ASSERT_EQUAL( fewkeys, parser->getAtomData() );
|
|---|
| 161 |
|
|---|
| 162 | // add some keys
|
|---|
| 163 | const std::string morekeys("charge");
|
|---|
| 164 | parser->setAtomData(morekeys);
|
|---|
| 165 | CPPUNIT_ASSERT_EQUAL( fewkeys+std::string(" ")+morekeys, parser->getAtomData() );
|
|---|
| 166 |
|
|---|
| 167 | // add similar key
|
|---|
| 168 | const std::string otherkey("neighbors=4");
|
|---|
| 169 | parser->setAtomData(otherkey);
|
|---|
| 170 | CPPUNIT_ASSERT( fewkeys+std::string(" ")+morekeys != parser->getAtomData() );
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| [4fbca9c] | 173 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
|
|---|
| 174 | stringstream input;
|
|---|
| 175 |
|
|---|
| 176 | // One simple data line
|
|---|
| 177 | input << Tremolo_Atomdata2;
|
|---|
| [765f16] | 178 | parser->load(&input);
|
|---|
| [4fbca9c] | 179 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
|
|---|
| 180 | input.clear();
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | void ParserTremoloUnitTest::readTremoloVelocityTest() {
|
|---|
| 184 | stringstream input;
|
|---|
| 185 |
|
|---|
| 186 | // One simple data line
|
|---|
| 187 | input << Tremolo_velocity;
|
|---|
| [765f16] | 188 | parser->load(&input);
|
|---|
| [bce72c] | 189 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
|
|---|
| [4fbca9c] | 190 | input.clear();
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
|
|---|
| 194 | stringstream input;
|
|---|
| 195 |
|
|---|
| 196 | // Neighbor data
|
|---|
| 197 | input << Tremolo_neighbours;
|
|---|
| [765f16] | 198 | parser->load(&input);
|
|---|
| [4fbca9c] | 199 |
|
|---|
| 200 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
|---|
| 201 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
|
|---|
| [073a9e4] | 202 | IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
|
|---|
| [4fbca9c] | 203 | input.clear();
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
|
|---|
| 207 | stringstream input, output;
|
|---|
| 208 |
|
|---|
| 209 | // Neighbor data
|
|---|
| [73916f] | 210 | {
|
|---|
| 211 | input << Tremolo_improper;
|
|---|
| [765f16] | 212 | parser->load(&input);
|
|---|
| [73916f] | 213 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| [765f16] | 214 | parser->save(&output, atoms);
|
|---|
| [73916f] | 215 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
|---|
| [4d4d33] | 216 | std::cout << output.str() << std::endl;
|
|---|
| [73916f] | 217 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
|---|
| 218 | input.clear();
|
|---|
| 219 | output.clear();
|
|---|
| 220 | }
|
|---|
| [4fbca9c] | 221 | }
|
|---|
| 222 |
|
|---|
| 223 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
|
|---|
| 224 | stringstream input, output;
|
|---|
| 225 |
|
|---|
| 226 | // Neighbor data
|
|---|
| [73916f] | 227 | {
|
|---|
| 228 | input << Tremolo_torsion;
|
|---|
| [765f16] | 229 | parser->load(&input);
|
|---|
| [73916f] | 230 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| [765f16] | 231 | parser->save(&output, atoms);
|
|---|
| [73916f] | 232 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
|---|
| [4d4d33] | 233 | std::cout << output.str() << std::endl;
|
|---|
| [73916f] | 234 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
|---|
| 235 | input.clear();
|
|---|
| 236 | output.clear();
|
|---|
| 237 | }
|
|---|
| [4fbca9c] | 238 | }
|
|---|
| 239 |
|
|---|
| 240 | void ParserTremoloUnitTest::writeTremoloTest() {
|
|---|
| 241 | stringstream output;
|
|---|
| 242 |
|
|---|
| 243 | // with the maximum number of fields and minimal information, default values are printed
|
|---|
| [73916f] | 244 | {
|
|---|
| 245 | atom* newAtom = World::getInstance().createAtom();
|
|---|
| 246 | newAtom->setType(1);
|
|---|
| [23fd43] | 247 | parser->setAtomData("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
|
|---|
| [73916f] | 248 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| [765f16] | 249 | parser->save(&output, atoms);
|
|---|
| [ccb487] | 250 | // std::cout << output.str() << std::endl;
|
|---|
| 251 | // std::cout << Tremolo_full << std::endl;
|
|---|
| [73916f] | 252 | CPPUNIT_ASSERT(output.str() == Tremolo_full);
|
|---|
| 253 | }
|
|---|
| [4fbca9c] | 254 |
|
|---|
| 255 | cout << "testing the tremolo parser is done" << endl;
|
|---|
| 256 | }
|
|---|
| [765f16] | 257 |
|
|---|