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