source: src/Parser/unittests/ParserMpqcUnitTest.cpp

Candidate_v1.6.1
Last change on this file was 3fb9ab, checked in by Frederik Heber <heber@…>, 8 years ago

FIX: Preventing MPQC from using old temp files for restart.

  • TESTFIX: needed to add "checkstate=no" to file contents contained in unit test.
  • TESTFIX: needed to adapt all check .in files of MPQC and other regression tests.
  • Property mode set to 100644
File size: 12.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * ParserMpqcUnitTest.cpp
26 *
27 * Created on: Mar 3, 2010
28 * Author: metzler
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "ParserMpqcUnitTest.hpp"
37
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41
42#include <boost/any.hpp>
43
44#include "Atom/atom.hpp"
45#include "Atom/AtomObserver.hpp"
46#include "CodePatterns/Assert.hpp"
47#include "Descriptors/AtomTypeDescriptor.hpp"
48#include "Element/element.hpp"
49#include "Element/periodentafel.hpp"
50#include "Parser/ChangeTracker.hpp"
51#include "Parser/MpqcParser.hpp"
52#include "World.hpp"
53
54#ifdef HAVE_TESTRUNNER
55#include "UnitTestMain.hpp"
56#endif /*HAVE_TESTRUNNER*/
57
58using namespace std;
59
60// Registers the fixture into the 'registry'
61CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
62
63static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
64mpqc: (\n\
65\tcheckpoint = no\n\
66\trestart = no\n\
67\tsavestate = no\n\
68\tdo_gradient = yes\n\
69\tmole<CLHF>: (\n\
70\t\tmolecule = $:molecule\n\
71\t\tbasis = $:basis\n\
72\t\tmaxiter = 1000\n\
73\t\tmemory = 16000000\n\
74\t)\n\
75)\n\
76molecule<Molecule>: (\n\
77\tunit = angstrom\n\
78\t{ atoms geometry } = {\n\
79\t\tO [ 0\t0\t0 ]\n\
80\t\tH [ 0.758602\t0\t0.504284 ]\n\
81\t\tH [ 0.758602\t0\t-0.504284 ]\n\
82\t}\n\
83)\n\
84basis<GaussianBasisSet>: (\n\
85\tname = \"3-21G\"\n\
86\tmolecule = $:molecule\n\
87)\n"; // tested with mpqc 3.0.0-alpha
88static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
89mpqc: (\n\
90\tcheckpoint = no\n\
91\trestart = no\n\
92\tsavestate = no\n\
93\tdo_gradient = yes\n\
94\tmole<CLKS>: (\n\
95\t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
96\t\tmolecule = $:molecule\n\
97\t\tbasis = $:basis\n\
98\t\tmaxiter = 1000\n\
99\t\tmemory = 16000000\n\
100\t)\n\
101)\n\
102molecule<Molecule>: (\n\
103\tunit = angstrom\n\
104\t{ atoms geometry } = {\n\
105\t\tO [ 0\t0\t0 ]\n\
106\t\tH [ 0.758602\t0\t0.504284 ]\n\
107\t\tH [ 0.758602\t0\t-0.504284 ]\n\
108\t}\n\
109)\n\
110basis<GaussianBasisSet>: (\n\
111\tname = \"3-21G\"\n\
112\tmolecule = $:molecule\n\
113)\n"; // tested with mpqc 3.0.0-alpha
114static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
115mpqc: (\n\
116\tcheckpoint = no\n\
117\trestart = no\n\
118\tsavestate = no\n\
119\tdo_gradient = yes\n\
120\tmole<MBPT2>: (\n\
121\t\tbasis = $:basis\n\
122\t\tmolecule = $:molecule\n\
123\t\tmemory = 16000000\n\
124\t\treference<CLHF>: (\n\
125\t\t\tmaxiter = 1000\n\
126\t\t\tbasis = $:basis\n\
127\t\t\tmolecule = $:molecule\n\
128\t\t\tmemory = 16000000\n\
129\t\t)\n\
130\t)\n\
131)\n\
132molecule<Molecule>: (\n\
133\tunit = angstrom\n\
134\t{ atoms geometry } = {\n\
135\t\tO [ 0\t0\t0 ]\n\
136\t\tH [ 0.758602\t0\t0.504284 ]\n\
137\t\tH [ 0.758602\t0\t-0.504284 ]\n\
138\t}\n\
139)\n\
140basis<GaussianBasisSet>: (\n\
141\tname = \"3-21G\"\n\
142\tmolecule = $:molecule\n\
143)\n"; // tested with mpqc 3.0.0-alpha
144static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
145mpqc: (\n\
146\tcheckpoint = no\n\
147\trestart = no\n\
148\tsavestate = no\n\
149\tdo_gradient = yes\n\
150\tmole<MBPT2_R12>: (\n\
151\t\tmolecule = $:molecule\n\
152\t\tbasis = $:basis\n\
153\t\taux_basis = $:abasis\n\
154\t\tstdapprox = \"A'\"\n\
155\t\tnfzc = 1\n\
156\t\tmemory = 16000000\n\
157\t\tintegrals<IntegralCints>:()\n\
158\t\treference<CLHF>: (\n\
159\t\t\tmolecule = $:molecule\n\
160\t\t\tbasis = $:basis\n\
161\t\t\tmaxiter = 1000\n\
162\t\t\tmemory = 16000000\n\
163\t\t\tintegrals<IntegralCints>:()\n\
164\t\t)\n\
165\t)\n\
166)\n\
167molecule<Molecule>: (\n\
168\tunit = angstrom\n\
169\t{ atoms geometry } = {\n\
170\t\tO [ 0\t0\t0 ]\n\
171\t\tH [ 0.758602\t0\t0.504284 ]\n\
172\t\tH [ 0.758602\t0\t-0.504284 ]\n\
173\t}\n\
174)\n\
175basis<GaussianBasisSet>: (\n\
176\tname = \"3-21G\"\n\
177\tmolecule = $:molecule\n\
178)\n\
179% auxiliary basis set specification\n\
180\tabasis<GaussianBasisSet>: (\n\
181\tname = \"aug-cc-pVDZ\"\n\
182\tmolecule = $:molecule\n\
183)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
184
185void ParserMpqcUnitTest::setUp()
186{
187 // failing asserts should be thrown
188 ASSERT_DO(Assert::Throw);
189
190 parser = new FormatParser<mpqc>();
191
192 World::getInstance();
193
194 setVerbosity(2);
195
196 // we need hydrogens and oxygens in the following tests
197 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
198 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
199}
200
201void ParserMpqcUnitTest::tearDown()
202{
203 delete parser;
204 ChangeTracker::purgeInstance();
205 World::purgeInstance();
206 AtomObserver::purgeInstance();
207}
208
209/************************************ tests ***********************************/
210
211void ParserMpqcUnitTest::ParameterDefaultTest() {
212 // check default values
213 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
214 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
215 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
216 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
217 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
218 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
219 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
220 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
221 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
222 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
223 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
224}
225
226void ParserMpqcUnitTest::ParameterCloneTest() {
227 FormatParser_Parameters *clone = parser->getParams().clone();
228 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
229 std::stringstream setvalue("theory = CLHF");
230 setvalue >> parser->getParams();
231 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
232 parser->getParams().makeClone(*clone);
233 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
234}
235
236void ParserMpqcUnitTest::ParameterSetterTest() {
237 // test a string
238 {
239 std::stringstream setvalue("theory = CLHF");
240 setvalue >> parser->getParams();
241// std::cout << "integration method is "
242// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
243 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
244 }
245 // test a bool
246 {
247 std::stringstream setvalue("Hessian = yes");
248 setvalue >> parser->getParams();
249// std::cout << "Hessian is "
250// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
251 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
252 }
253 // test int
254 {
255 std::stringstream setvalue("maxiter = 500");
256 setvalue >> parser->getParams();
257// std::cout << "maxiter is "
258// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
259 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
260 }
261 // test whether unknown key fails
262 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
263 {
264 std::stringstream setvalue("hessian = no");
265#ifndef NDEBUG
266 ASSERT_DO(Assert::Throw);
267 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
268#else
269 setvalue >> parser->getParams();
270#endif
271// std::cout << "Hessian is still "
272// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
273 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
274 }
275}
276
277void ParserMpqcUnitTest::readMpqcTest() {
278 stringstream input(waterMpqc_CLHF);
279 parser->getParams().setParameter(
280 MpqcParser_Parameters::theoryParam,
281 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
282 );
283 parser->load(&input);
284
285 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
286}
287
288void ParserMpqcUnitTest::writeMpqcTest() {
289 // build up water molecule
290 string first;
291 string second;
292 atom *Walker = NULL;
293 Walker = World::getInstance().createAtom();
294 Walker->setType(8);
295 Walker->setPosition(Vector(0,0,0));
296 Walker = World::getInstance().createAtom();
297 Walker->setType(1);
298 Walker->setPosition(Vector(0.758602,0,0.504284));
299 Walker = World::getInstance().createAtom();
300 Walker->setType(1);
301 Walker->setPosition(Vector(0.758602,0,-0.504284));
302 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
303
304 // create two stringstreams, one stored, one created
305
306 std::vector<const atom *> atoms = const_cast<const World &>(World::getInstance()).
307 getAllAtoms();
308 {
309 // compare both configs for CLHF
310 stringstream output;
311 parser->getParams().setParameter(
312 MpqcParser_Parameters::theoryParam,
313 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
314 );
315 parser->save(&output, atoms);
316 stringstream input(waterMpqc_CLHF);
317 // check for non-empty streams
318 input.peek();
319 output.peek();
320 CPPUNIT_ASSERT(input.good() && output.good());
321 // check equality of streams per line (for debugging)
322 for (; std::getline(input, first) && std::getline(output, second); ) {
323 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
324 CPPUNIT_ASSERT(first == second);
325 }
326 }
327 {
328 // compare both configs for CLKS
329 stringstream output;
330 parser->getParams().setParameter(
331 MpqcParser_Parameters::theoryParam,
332 parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
333 );
334 parser->save(&output, atoms);
335 stringstream input(waterMpqc_CLKS);
336 // check for non-empty streams
337 input.peek();
338 output.peek();
339 CPPUNIT_ASSERT(input.good() && output.good());
340 // check equality of streams per line (for debugging)
341 for (; std::getline(input, first) && std::getline(output, second); ) {
342 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
343 CPPUNIT_ASSERT(first == second);
344 }
345 }
346 {
347 // compare both configs for MBPT2
348 stringstream output;
349 parser->getParams().setParameter(
350 MpqcParser_Parameters::theoryParam,
351 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
352 );
353 parser->save(&output, atoms);
354 stringstream input(waterMpqc_MBPT2);
355 // check for non-empty streams
356 input.peek();
357 output.peek();
358 CPPUNIT_ASSERT(input.good() && output.good());
359 // check equality of streams per line (for debugging)
360 for (; std::getline(input, first) && std::getline(output, second); ) {
361 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
362 CPPUNIT_ASSERT(first == second);
363 }
364 }
365 {
366 // compare both configs for MBPT2_R12
367 stringstream output;
368 parser->getParams().setParameter(
369 MpqcParser_Parameters::theoryParam,
370 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
371 );
372 parser->save(&output, atoms);
373 stringstream input(waterMpqc_MBPT2_R12);
374 // check for non-empty streams
375 input.peek();
376 output.peek();
377 CPPUNIT_ASSERT(input.good() && output.good());
378 // check equality of streams per line (for debugging)
379 for (; std::getline(input, first) && std::getline(output, second); ) {
380 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
381 CPPUNIT_ASSERT(first == second);
382 }
383 }
384}
Note: See TracBrowser for help on using the repository browser.