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