| [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 | 
 | 
|---|
| [4d4d33] | 46 | static string Tremolo_Atomdata1 = "\
 | 
|---|
 | 47 | # ATOMDATA\tId\tname\tType\tx=3\n";
 | 
|---|
 | 48 | static string Tremolo_Atomdata2 = "\
 | 
|---|
 | 49 | #\n\
 | 
|---|
 | 50 | #ATOMDATA Id name Type x=3\n\
 | 
|---|
 | 51 | 1 hydrogen H 3.0 4.5 0.1\n\
 | 
|---|
 | 52 | \n";
 | 
|---|
 | 53 | static string Tremolo_invalidkey = "\
 | 
|---|
 | 54 | #\n\
 | 
|---|
 | 55 | #ATOMDATA Id name foo Type x=3\n\
 | 
|---|
 | 56 | \n\n";
 | 
|---|
 | 57 | static string Tremolo_velocity = "\
 | 
|---|
 | 58 | #\n\
 | 
|---|
 | 59 | #ATOMDATA Id name Type u=3\n\
 | 
|---|
 | 60 | 1 hydrogen H 3.0 4.5 0.1\n\
 | 
|---|
 | 61 | \n";
 | 
|---|
 | 62 | static string Tremolo_neighbours = "#\n\
 | 
|---|
 | 63 | #ATOMDATA Id Type neighbors=2\n\
 | 
|---|
 | 64 | 1 H 3 0\n\
 | 
|---|
 | 65 | 2 H 3 0\n\
 | 
|---|
 | 66 | 3 O 1 2\n";
 | 
|---|
 | 67 | static string Tremolo_improper = "\
 | 
|---|
 | 68 | #\n\
 | 
|---|
 | 69 | #ATOMDATA Id Type imprData\n\
 | 
|---|
 | 70 | 8 H 9-10\n\
 | 
|---|
 | 71 | 9 H 10-8,8-10\n\
 | 
|---|
 | 72 | 10 O -\n";
 | 
|---|
 | 73 | static string Tremolo_torsion = "\
 | 
|---|
 | 74 | #\n\
 | 
|---|
 | 75 | #ATOMDATA Id Type torsion\n\
 | 
|---|
 | 76 | 8 H 9-10\n\
 | 
|---|
 | 77 | 9 H 10-8,8-10\n\
 | 
|---|
 | 78 | 10 O -\n";
 | 
|---|
 | 79 | static string Tremolo_full = "\
 | 
|---|
 | 80 | # 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\
 | 
|---|
 | 81 | 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] | 82 | 
 | 
|---|
 | 83 | void ParserTremoloUnitTest::setUp() {
 | 
|---|
 | 84 |   World::getInstance();
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |   // we need hydrogens and oxygens in the following tests
 | 
|---|
 | 87 |   CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
 | 
|---|
 | 88 |   CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
 | 
|---|
 | 89 | }
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | void ParserTremoloUnitTest::tearDown() {
 | 
|---|
 | 92 |   ChangeTracker::purgeInstance();
 | 
|---|
 | 93 |   World::purgeInstance();
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | /************************************ tests ***********************************/
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
 | 
|---|
 | 99 |   cout << "Testing the tremolo parser." << endl;
 | 
|---|
 | 100 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 101 |   stringstream input, output;
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 |   // Atomdata beginning with "# ATOMDATA"
 | 
|---|
| [73916f] | 104 |   {
 | 
|---|
 | 105 |     input << Tremolo_Atomdata1;
 | 
|---|
 | 106 |     testParser->load(&input);
 | 
|---|
 | 107 |     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 108 |     testParser->save(&output, atoms);
 | 
|---|
| [4d4d33] | 109 | //    std::cout << output.str() << std::endl;
 | 
|---|
 | 110 | //    std::cout << Tremolo_Atomdata1 << std::endl;
 | 
|---|
| [73916f] | 111 |     CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
 | 
|---|
 | 112 |     input.clear();
 | 
|---|
 | 113 |     output.clear();
 | 
|---|
 | 114 |   }
 | 
|---|
| [4fbca9c] | 115 | 
 | 
|---|
 | 116 |   // Atomdata beginning with "#ATOMDATA"
 | 
|---|
| [73916f] | 117 |   {
 | 
|---|
 | 118 |     input << Tremolo_Atomdata2;
 | 
|---|
 | 119 |     testParser->load(&input);
 | 
|---|
 | 120 |     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 121 |     testParser->save(&output, atoms);
 | 
|---|
| [4d4d33] | 122 |     std::cout << output.str() << std::endl;
 | 
|---|
| [73916f] | 123 |     CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
 | 
|---|
 | 124 |     input.clear();
 | 
|---|
 | 125 |     output.clear();
 | 
|---|
 | 126 |   }
 | 
|---|
| [4fbca9c] | 127 | 
 | 
|---|
 | 128 |   // Invalid key in Atomdata line
 | 
|---|
 | 129 |   input << Tremolo_invalidkey;
 | 
|---|
 | 130 |   testParser->load(&input);
 | 
|---|
| [73916f] | 131 |   //TODO: prove invalidity
 | 
|---|
| [4fbca9c] | 132 |   input.clear();
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
 | 
|---|
 | 136 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 137 |   stringstream input;
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 |   // One simple data line
 | 
|---|
 | 140 |   input << Tremolo_Atomdata2;
 | 
|---|
 | 141 |   testParser->load(&input);
 | 
|---|
 | 142 |   CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
 | 
|---|
 | 143 |   input.clear();
 | 
|---|
 | 144 | }
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | void ParserTremoloUnitTest::readTremoloVelocityTest() {
 | 
|---|
 | 147 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 148 |   stringstream input;
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 |   // One simple data line
 | 
|---|
 | 151 |   input << Tremolo_velocity;
 | 
|---|
 | 152 |   testParser->load(&input);
 | 
|---|
| [bce72c] | 153 |   CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
 | 
|---|
| [4fbca9c] | 154 |   input.clear();
 | 
|---|
 | 155 | }
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
 | 
|---|
 | 158 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 159 |   stringstream input;
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 |   // Neighbor data
 | 
|---|
 | 162 |   input << Tremolo_neighbours;
 | 
|---|
 | 163 |   testParser->load(&input);
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 |   CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
 | 
|---|
 | 166 |   CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
 | 
|---|
 | 167 |       IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
 | 
|---|
 | 168 |   input.clear();
 | 
|---|
 | 169 | }
 | 
|---|
 | 170 | 
 | 
|---|
 | 171 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
 | 
|---|
 | 172 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 173 |   stringstream input, output;
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 |   // Neighbor data
 | 
|---|
| [73916f] | 176 |   {
 | 
|---|
 | 177 |     input << Tremolo_improper;
 | 
|---|
 | 178 |     testParser->load(&input);
 | 
|---|
 | 179 |     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 180 |     testParser->save(&output, atoms);
 | 
|---|
 | 181 |     CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
 | 
|---|
| [4d4d33] | 182 |     std::cout << output.str() << std::endl;
 | 
|---|
| [73916f] | 183 |     CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
 | 
|---|
 | 184 |     input.clear();
 | 
|---|
 | 185 |     output.clear();
 | 
|---|
 | 186 |   }
 | 
|---|
| [4fbca9c] | 187 | }
 | 
|---|
 | 188 | 
 | 
|---|
 | 189 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
 | 
|---|
 | 190 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 191 |   stringstream input, output;
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 |   // Neighbor data
 | 
|---|
| [73916f] | 194 |   {
 | 
|---|
 | 195 |     input << Tremolo_torsion;
 | 
|---|
 | 196 |     testParser->load(&input);
 | 
|---|
 | 197 |     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 198 |     testParser->save(&output, atoms);
 | 
|---|
 | 199 |     CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
 | 
|---|
| [4d4d33] | 200 |     std::cout << output.str() << std::endl;
 | 
|---|
| [73916f] | 201 |     CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
 | 
|---|
 | 202 |     input.clear();
 | 
|---|
 | 203 |     output.clear();
 | 
|---|
 | 204 |   }
 | 
|---|
| [4fbca9c] | 205 | }
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | void ParserTremoloUnitTest::writeTremoloTest() {
 | 
|---|
 | 208 |   TremoloParser* testParser = new TremoloParser();
 | 
|---|
 | 209 |   stringstream output;
 | 
|---|
 | 210 | 
 | 
|---|
 | 211 |   // with the maximum number of fields and minimal information, default values are printed
 | 
|---|
| [73916f] | 212 |   {
 | 
|---|
 | 213 |     atom* newAtom = World::getInstance().createAtom();
 | 
|---|
 | 214 |     newAtom->setType(1);
 | 
|---|
 | 215 |     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");
 | 
|---|
 | 216 |     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 217 |     testParser->save(&output, atoms);
 | 
|---|
 | 218 |     CPPUNIT_ASSERT(output.str() == Tremolo_full);
 | 
|---|
 | 219 |   }
 | 
|---|
| [4fbca9c] | 220 | 
 | 
|---|
 | 221 |   cout << "testing the tremolo parser is done" << endl;
 | 
|---|
 | 222 | }
 | 
|---|