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