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 |
|
---|
46 | static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n";
|
---|
47 | static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
48 | static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
|
---|
49 | static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
50 | static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
|
---|
51 | static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
52 | static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
53 | static string Tremolo_full = "# 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\n0\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";
|
---|
54 |
|
---|
55 | void ParserTremoloUnitTest::setUp() {
|
---|
56 | World::getInstance();
|
---|
57 |
|
---|
58 | // we need hydrogens and oxygens in the following tests
|
---|
59 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
60 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
---|
61 | }
|
---|
62 |
|
---|
63 | void ParserTremoloUnitTest::tearDown() {
|
---|
64 | ChangeTracker::purgeInstance();
|
---|
65 | World::purgeInstance();
|
---|
66 | }
|
---|
67 |
|
---|
68 | /************************************ tests ***********************************/
|
---|
69 |
|
---|
70 | void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
|
---|
71 | cout << "Testing the tremolo parser." << endl;
|
---|
72 | TremoloParser* testParser = new TremoloParser();
|
---|
73 | stringstream input, output;
|
---|
74 |
|
---|
75 | // Atomdata beginning with "# ATOMDATA"
|
---|
76 | input << Tremolo_Atomdata1;
|
---|
77 | testParser->load(&input);
|
---|
78 | testParser->save(&output);
|
---|
79 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
|
---|
80 | input.clear();
|
---|
81 | output.clear();
|
---|
82 |
|
---|
83 | // Atomdata beginning with "#ATOMDATA"
|
---|
84 | input << Tremolo_Atomdata2;
|
---|
85 | testParser->load(&input);
|
---|
86 | testParser->save(&output);
|
---|
87 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
|
---|
88 | input.clear();
|
---|
89 | output.clear();
|
---|
90 |
|
---|
91 | // Invalid key in Atomdata line
|
---|
92 | input << Tremolo_invalidkey;
|
---|
93 | testParser->load(&input);
|
---|
94 | //TODO: proove invalidity
|
---|
95 | input.clear();
|
---|
96 | }
|
---|
97 |
|
---|
98 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
|
---|
99 | TremoloParser* testParser = new TremoloParser();
|
---|
100 | stringstream input;
|
---|
101 |
|
---|
102 | // One simple data line
|
---|
103 | input << Tremolo_Atomdata2;
|
---|
104 | testParser->load(&input);
|
---|
105 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
|
---|
106 | input.clear();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void ParserTremoloUnitTest::readTremoloVelocityTest() {
|
---|
110 | TremoloParser* testParser = new TremoloParser();
|
---|
111 | stringstream input;
|
---|
112 |
|
---|
113 | // One simple data line
|
---|
114 | input << Tremolo_velocity;
|
---|
115 | testParser->load(&input);
|
---|
116 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
|
---|
117 | input.clear();
|
---|
118 | }
|
---|
119 |
|
---|
120 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
|
---|
121 | TremoloParser* testParser = new TremoloParser();
|
---|
122 | stringstream input;
|
---|
123 |
|
---|
124 | // Neighbor data
|
---|
125 | input << Tremolo_neighbours;
|
---|
126 | testParser->load(&input);
|
---|
127 |
|
---|
128 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
129 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
|
---|
130 | IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
|
---|
131 | input.clear();
|
---|
132 | }
|
---|
133 |
|
---|
134 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
|
---|
135 | TremoloParser* testParser = new TremoloParser();
|
---|
136 | stringstream input, output;
|
---|
137 |
|
---|
138 | // Neighbor data
|
---|
139 | input << Tremolo_improper;
|
---|
140 | testParser->load(&input);
|
---|
141 | testParser->save(&output);
|
---|
142 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
143 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
144 | input.clear();
|
---|
145 | output.clear();
|
---|
146 | }
|
---|
147 |
|
---|
148 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
|
---|
149 | TremoloParser* testParser = new TremoloParser();
|
---|
150 | stringstream input, output;
|
---|
151 |
|
---|
152 | // Neighbor data
|
---|
153 | input << Tremolo_torsion;
|
---|
154 | testParser->load(&input);
|
---|
155 | testParser->save(&output);
|
---|
156 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
157 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
158 | input.clear();
|
---|
159 | output.clear();
|
---|
160 | }
|
---|
161 |
|
---|
162 | void ParserTremoloUnitTest::writeTremoloTest() {
|
---|
163 | TremoloParser* testParser = new TremoloParser();
|
---|
164 | stringstream output;
|
---|
165 |
|
---|
166 | // with the maximum number of fields and minimal information, default values are printed
|
---|
167 | atom* newAtom = World::getInstance().createAtom();
|
---|
168 | newAtom->setType(1);
|
---|
169 | 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");
|
---|
170 | testParser->save(&output);
|
---|
171 | CPPUNIT_ASSERT(output.str() == Tremolo_full);
|
---|
172 |
|
---|
173 | cout << "testing the tremolo parser is done" << endl;
|
---|
174 | }
|
---|