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 | * ParserMpqcUnitTest.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 "ParserMpqcUnitTest.hpp"
|
---|
21 |
|
---|
22 | #include <cppunit/CompilerOutputter.h>
|
---|
23 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
24 | #include <cppunit/ui/text/TestRunner.h>
|
---|
25 |
|
---|
26 | #include <boost/any.hpp>
|
---|
27 |
|
---|
28 | #include "Atom/atom.hpp"
|
---|
29 | #include "Atom/AtomObserver.hpp"
|
---|
30 | #include "CodePatterns/Assert.hpp"
|
---|
31 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
32 | #include "Element/element.hpp"
|
---|
33 | #include "Element/periodentafel.hpp"
|
---|
34 | #include "Parser/ChangeTracker.hpp"
|
---|
35 | #include "Parser/MpqcParser.hpp"
|
---|
36 | #include "World.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( ParserMpqcUnitTest );
|
---|
46 |
|
---|
47 | static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
|
---|
48 | mpqc: (\n\
|
---|
49 | \tsavestate = no\n\
|
---|
50 | \tdo_gradient = yes\n\
|
---|
51 | \tmole<CLHF>: (\n\
|
---|
52 | \t\tmolecule = $:molecule\n\
|
---|
53 | \t\tbasis = $:basis\n\
|
---|
54 | \t\tmaxiter = 1000\n\
|
---|
55 | \t\tmemory = 16000000\n\
|
---|
56 | \t)\n\
|
---|
57 | )\n\
|
---|
58 | molecule<Molecule>: (\n\
|
---|
59 | \tunit = angstrom\n\
|
---|
60 | \t{ atoms geometry } = {\n\
|
---|
61 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
62 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
63 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
64 | \t}\n\
|
---|
65 | )\n\
|
---|
66 | basis<GaussianBasisSet>: (\n\
|
---|
67 | \tname = \"3-21G\"\n\
|
---|
68 | \tmolecule = $:molecule\n\
|
---|
69 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
70 | static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
|
---|
71 | mpqc: (\n\
|
---|
72 | \tsavestate = no\n\
|
---|
73 | \tdo_gradient = yes\n\
|
---|
74 | \tmole<CLKS>: (\n\
|
---|
75 | \t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
|
---|
76 | \t\tmolecule = $:molecule\n\
|
---|
77 | \t\tbasis = $:basis\n\
|
---|
78 | \t\tmaxiter = 1000\n\
|
---|
79 | \t\tmemory = 16000000\n\
|
---|
80 | \t)\n\
|
---|
81 | )\n\
|
---|
82 | molecule<Molecule>: (\n\
|
---|
83 | \tunit = angstrom\n\
|
---|
84 | \t{ atoms geometry } = {\n\
|
---|
85 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
86 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
87 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
88 | \t}\n\
|
---|
89 | )\n\
|
---|
90 | basis<GaussianBasisSet>: (\n\
|
---|
91 | \tname = \"3-21G\"\n\
|
---|
92 | \tmolecule = $:molecule\n\
|
---|
93 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
94 | static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
|
---|
95 | mpqc: (\n\
|
---|
96 | \tsavestate = no\n\
|
---|
97 | \tdo_gradient = yes\n\
|
---|
98 | \tmole<MBPT2>: (\n\
|
---|
99 | \t\tbasis = $:basis\n\
|
---|
100 | \t\tmolecule = $:molecule\n\
|
---|
101 | \t\tmemory = 16000000\n\
|
---|
102 | \t\treference<CLHF>: (\n\
|
---|
103 | \t\t\tmaxiter = 1000\n\
|
---|
104 | \t\t\tbasis = $:basis\n\
|
---|
105 | \t\t\tmolecule = $:molecule\n\
|
---|
106 | \t\t\tmemory = 16000000\n\
|
---|
107 | \t\t)\n\
|
---|
108 | \t)\n\
|
---|
109 | )\n\
|
---|
110 | molecule<Molecule>: (\n\
|
---|
111 | \tunit = angstrom\n\
|
---|
112 | \t{ atoms geometry } = {\n\
|
---|
113 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
114 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
115 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
116 | \t}\n\
|
---|
117 | )\n\
|
---|
118 | basis<GaussianBasisSet>: (\n\
|
---|
119 | \tname = \"3-21G\"\n\
|
---|
120 | \tmolecule = $:molecule\n\
|
---|
121 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
122 | static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
|
---|
123 | mpqc: (\n\
|
---|
124 | \tsavestate = no\n\
|
---|
125 | \tdo_gradient = yes\n\
|
---|
126 | \tmole<MBPT2_R12>: (\n\
|
---|
127 | \t\tmolecule = $:molecule\n\
|
---|
128 | \t\tbasis = $:basis\n\
|
---|
129 | \t\taux_basis = $:abasis\n\
|
---|
130 | \t\tstdapprox = \"A'\"\n\
|
---|
131 | \t\tnfzc = 1\n\
|
---|
132 | \t\tmemory = 16000000\n\
|
---|
133 | \t\tintegrals<IntegralCints>:()\n\
|
---|
134 | \t\treference<CLHF>: (\n\
|
---|
135 | \t\t\tmolecule = $:molecule\n\
|
---|
136 | \t\t\tbasis = $:basis\n\
|
---|
137 | \t\t\tmaxiter = 1000\n\
|
---|
138 | \t\t\tmemory = 16000000\n\
|
---|
139 | \t\t\tintegrals<IntegralCints>:()\n\
|
---|
140 | \t\t)\n\
|
---|
141 | \t)\n\
|
---|
142 | )\n\
|
---|
143 | molecule<Molecule>: (\n\
|
---|
144 | \tunit = angstrom\n\
|
---|
145 | \t{ atoms geometry } = {\n\
|
---|
146 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
147 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
148 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
149 | \t}\n\
|
---|
150 | )\n\
|
---|
151 | basis<GaussianBasisSet>: (\n\
|
---|
152 | \tname = \"3-21G\"\n\
|
---|
153 | \tmolecule = $:molecule\n\
|
---|
154 | )\n\
|
---|
155 | % auxiliary basis set specification\n\
|
---|
156 | \tabasis<GaussianBasisSet>: (\n\
|
---|
157 | \tname = \"aug-cc-pVDZ\"\n\
|
---|
158 | \tmolecule = $:molecule\n\
|
---|
159 | )\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
|
---|
160 |
|
---|
161 | void ParserMpqcUnitTest::setUp()
|
---|
162 | {
|
---|
163 | // failing asserts should be thrown
|
---|
164 | ASSERT_DO(Assert::Throw);
|
---|
165 |
|
---|
166 | parser = new FormatParser<mpqc>();
|
---|
167 |
|
---|
168 | World::getInstance();
|
---|
169 |
|
---|
170 | setVerbosity(2);
|
---|
171 |
|
---|
172 | // we need hydrogens and oxygens in the following tests
|
---|
173 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
174 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void ParserMpqcUnitTest::tearDown()
|
---|
178 | {
|
---|
179 | delete parser;
|
---|
180 | ChangeTracker::purgeInstance();
|
---|
181 | AtomObserver::purgeInstance();
|
---|
182 | World::purgeInstance();
|
---|
183 | }
|
---|
184 |
|
---|
185 | /************************************ tests ***********************************/
|
---|
186 |
|
---|
187 | void ParserMpqcUnitTest::ParameterDefaultTest() {
|
---|
188 | // check default values
|
---|
189 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
|
---|
190 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
|
---|
191 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
|
---|
192 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
|
---|
193 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
|
---|
194 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
|
---|
195 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
|
---|
196 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
|
---|
197 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
|
---|
198 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
|
---|
199 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
200 | }
|
---|
201 |
|
---|
202 | void ParserMpqcUnitTest::ParameterCloneTest() {
|
---|
203 | FormatParser_Parameters *clone = parser->getParams().clone();
|
---|
204 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
205 | std::stringstream setvalue("theory = CLHF");
|
---|
206 | setvalue >> parser->getParams();
|
---|
207 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
|
---|
208 | parser->getParams().makeClone(*clone);
|
---|
209 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
210 | }
|
---|
211 |
|
---|
212 | void ParserMpqcUnitTest::ParameterSetterTest() {
|
---|
213 | // test a string
|
---|
214 | {
|
---|
215 | std::stringstream setvalue("theory = CLHF");
|
---|
216 | setvalue >> parser->getParams();
|
---|
217 | // std::cout << "integration method is "
|
---|
218 | // << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
|
---|
219 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
|
---|
220 | }
|
---|
221 | // test a bool
|
---|
222 | {
|
---|
223 | std::stringstream setvalue("Hessian = yes");
|
---|
224 | setvalue >> parser->getParams();
|
---|
225 | // std::cout << "Hessian is "
|
---|
226 | // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
|
---|
227 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
|
---|
228 | }
|
---|
229 | // test int
|
---|
230 | {
|
---|
231 | std::stringstream setvalue("maxiter = 500");
|
---|
232 | setvalue >> parser->getParams();
|
---|
233 | // std::cout << "maxiter is "
|
---|
234 | // << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
|
---|
235 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
|
---|
236 | }
|
---|
237 | // test whether unknown key fails
|
---|
238 | std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
|
---|
239 | {
|
---|
240 | std::stringstream setvalue("hessian = no");
|
---|
241 | #ifndef NDEBUG
|
---|
242 | ASSERT_DO(Assert::Throw);
|
---|
243 | CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
|
---|
244 | #else
|
---|
245 | setvalue >> parser->getParams();
|
---|
246 | #endif
|
---|
247 | // std::cout << "Hessian is still "
|
---|
248 | // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
|
---|
249 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | void ParserMpqcUnitTest::readMpqcTest() {
|
---|
254 | stringstream input(waterMpqc_CLHF);
|
---|
255 | parser->getParams().setParameter(
|
---|
256 | MpqcParser_Parameters::theoryParam,
|
---|
257 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
|
---|
258 | );
|
---|
259 | parser->load(&input);
|
---|
260 |
|
---|
261 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
262 | }
|
---|
263 |
|
---|
264 | void ParserMpqcUnitTest::writeMpqcTest() {
|
---|
265 | // build up water molecule
|
---|
266 | string first;
|
---|
267 | string second;
|
---|
268 | atom *Walker = NULL;
|
---|
269 | Walker = World::getInstance().createAtom();
|
---|
270 | Walker->setType(8);
|
---|
271 | Walker->setPosition(Vector(0,0,0));
|
---|
272 | Walker = World::getInstance().createAtom();
|
---|
273 | Walker->setType(1);
|
---|
274 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
275 | Walker = World::getInstance().createAtom();
|
---|
276 | Walker->setType(1);
|
---|
277 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
278 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
279 |
|
---|
280 | // create two stringstreams, one stored, one created
|
---|
281 |
|
---|
282 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
283 | {
|
---|
284 | // compare both configs for CLHF
|
---|
285 | stringstream output;
|
---|
286 | parser->getParams().setParameter(
|
---|
287 | MpqcParser_Parameters::theoryParam,
|
---|
288 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
|
---|
289 | );
|
---|
290 | parser->save(&output, atoms);
|
---|
291 | stringstream input(waterMpqc_CLHF);
|
---|
292 | // check for non-empty streams
|
---|
293 | input.peek();
|
---|
294 | output.peek();
|
---|
295 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
296 | // check equality of streams per line (for debugging)
|
---|
297 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
298 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
299 | CPPUNIT_ASSERT(first == second);
|
---|
300 | }
|
---|
301 | }
|
---|
302 | {
|
---|
303 | // compare both configs for CLKS
|
---|
304 | stringstream output;
|
---|
305 | parser->getParams().setParameter(
|
---|
306 | MpqcParser_Parameters::theoryParam,
|
---|
307 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
|
---|
308 | );
|
---|
309 | parser->save(&output, atoms);
|
---|
310 | stringstream input(waterMpqc_CLKS);
|
---|
311 | // check for non-empty streams
|
---|
312 | input.peek();
|
---|
313 | output.peek();
|
---|
314 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
315 | // check equality of streams per line (for debugging)
|
---|
316 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
317 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
318 | CPPUNIT_ASSERT(first == second);
|
---|
319 | }
|
---|
320 | }
|
---|
321 | {
|
---|
322 | // compare both configs for MBPT2
|
---|
323 | stringstream output;
|
---|
324 | parser->getParams().setParameter(
|
---|
325 | MpqcParser_Parameters::theoryParam,
|
---|
326 | parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
|
---|
327 | );
|
---|
328 | parser->save(&output, atoms);
|
---|
329 | stringstream input(waterMpqc_MBPT2);
|
---|
330 | // check for non-empty streams
|
---|
331 | input.peek();
|
---|
332 | output.peek();
|
---|
333 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
334 | // check equality of streams per line (for debugging)
|
---|
335 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
336 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
337 | CPPUNIT_ASSERT(first == second);
|
---|
338 | }
|
---|
339 | }
|
---|
340 | {
|
---|
341 | // compare both configs for MBPT2_R12
|
---|
342 | stringstream output;
|
---|
343 | parser->getParams().setParameter(
|
---|
344 | MpqcParser_Parameters::theoryParam,
|
---|
345 | parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
|
---|
346 | );
|
---|
347 | parser->save(&output, atoms);
|
---|
348 | stringstream input(waterMpqc_MBPT2_R12);
|
---|
349 | // check for non-empty streams
|
---|
350 | input.peek();
|
---|
351 | output.peek();
|
---|
352 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
353 | // check equality of streams per line (for debugging)
|
---|
354 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
355 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
356 | CPPUNIT_ASSERT(first == second);
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|