source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 was e3c4c5, checked in by Frederik Heber <heber@…>, 9 years ago

MpqcParser additionally allows to save optimization jobs.

  • this is enabled via a new flag "jobtype" that can be either Default or Optimization.
  • also storing "checkpoint = no" per default for all mpqc input files. This is a safety measures such that no old checkpoint files are used that reside in the same folder accidentally. This is especially important for fragment files.
  • TESTFIX: changed all regression tests comparing against .in files, added new checkpoint statement.
  • TESTFIX: changed unit test ParserMpqcUnitTest in the same manner.
  • Property mode set to 100644
File size: 12.5 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\tsavestate = no\n\
67\tdo_gradient = yes\n\
68\tmole<CLHF>: (\n\
69\t\tmolecule = $:molecule\n\
70\t\tbasis = $:basis\n\
71\t\tmaxiter = 1000\n\
72\t\tmemory = 16000000\n\
73\t)\n\
74)\n\
75molecule<Molecule>: (\n\
76\tunit = angstrom\n\
77\t{ atoms geometry } = {\n\
78\t\tO [ 0\t0\t0 ]\n\
79\t\tH [ 0.758602\t0\t0.504284 ]\n\
80\t\tH [ 0.758602\t0\t-0.504284 ]\n\
81\t}\n\
82)\n\
83basis<GaussianBasisSet>: (\n\
84\tname = \"3-21G\"\n\
85\tmolecule = $:molecule\n\
86)\n"; // tested with mpqc 3.0.0-alpha
87static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
88mpqc: (\n\
89\tcheckpoint = no\n\
90\tsavestate = no\n\
91\tdo_gradient = yes\n\
92\tmole<CLKS>: (\n\
93\t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
94\t\tmolecule = $:molecule\n\
95\t\tbasis = $:basis\n\
96\t\tmaxiter = 1000\n\
97\t\tmemory = 16000000\n\
98\t)\n\
99)\n\
100molecule<Molecule>: (\n\
101\tunit = angstrom\n\
102\t{ atoms geometry } = {\n\
103\t\tO [ 0\t0\t0 ]\n\
104\t\tH [ 0.758602\t0\t0.504284 ]\n\
105\t\tH [ 0.758602\t0\t-0.504284 ]\n\
106\t}\n\
107)\n\
108basis<GaussianBasisSet>: (\n\
109\tname = \"3-21G\"\n\
110\tmolecule = $:molecule\n\
111)\n"; // tested with mpqc 3.0.0-alpha
112static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
113mpqc: (\n\
114\tcheckpoint = no\n\
115\tsavestate = no\n\
116\tdo_gradient = yes\n\
117\tmole<MBPT2>: (\n\
118\t\tbasis = $:basis\n\
119\t\tmolecule = $:molecule\n\
120\t\tmemory = 16000000\n\
121\t\treference<CLHF>: (\n\
122\t\t\tmaxiter = 1000\n\
123\t\t\tbasis = $:basis\n\
124\t\t\tmolecule = $:molecule\n\
125\t\t\tmemory = 16000000\n\
126\t\t)\n\
127\t)\n\
128)\n\
129molecule<Molecule>: (\n\
130\tunit = angstrom\n\
131\t{ atoms geometry } = {\n\
132\t\tO [ 0\t0\t0 ]\n\
133\t\tH [ 0.758602\t0\t0.504284 ]\n\
134\t\tH [ 0.758602\t0\t-0.504284 ]\n\
135\t}\n\
136)\n\
137basis<GaussianBasisSet>: (\n\
138\tname = \"3-21G\"\n\
139\tmolecule = $:molecule\n\
140)\n"; // tested with mpqc 3.0.0-alpha
141static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
142mpqc: (\n\
143\tcheckpoint = no\n\
144\tsavestate = no\n\
145\tdo_gradient = yes\n\
146\tmole<MBPT2_R12>: (\n\
147\t\tmolecule = $:molecule\n\
148\t\tbasis = $:basis\n\
149\t\taux_basis = $:abasis\n\
150\t\tstdapprox = \"A'\"\n\
151\t\tnfzc = 1\n\
152\t\tmemory = 16000000\n\
153\t\tintegrals<IntegralCints>:()\n\
154\t\treference<CLHF>: (\n\
155\t\t\tmolecule = $:molecule\n\
156\t\t\tbasis = $:basis\n\
157\t\t\tmaxiter = 1000\n\
158\t\t\tmemory = 16000000\n\
159\t\t\tintegrals<IntegralCints>:()\n\
160\t\t)\n\
161\t)\n\
162)\n\
163molecule<Molecule>: (\n\
164\tunit = angstrom\n\
165\t{ atoms geometry } = {\n\
166\t\tO [ 0\t0\t0 ]\n\
167\t\tH [ 0.758602\t0\t0.504284 ]\n\
168\t\tH [ 0.758602\t0\t-0.504284 ]\n\
169\t}\n\
170)\n\
171basis<GaussianBasisSet>: (\n\
172\tname = \"3-21G\"\n\
173\tmolecule = $:molecule\n\
174)\n\
175% auxiliary basis set specification\n\
176\tabasis<GaussianBasisSet>: (\n\
177\tname = \"aug-cc-pVDZ\"\n\
178\tmolecule = $:molecule\n\
179)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
180
181void ParserMpqcUnitTest::setUp()
182{
183 // failing asserts should be thrown
184 ASSERT_DO(Assert::Throw);
185
186 parser = new FormatParser<mpqc>();
187
188 World::getInstance();
189
190 setVerbosity(2);
191
192 // we need hydrogens and oxygens in the following tests
193 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
194 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
195}
196
197void ParserMpqcUnitTest::tearDown()
198{
199 delete parser;
200 ChangeTracker::purgeInstance();
201 World::purgeInstance();
202 AtomObserver::purgeInstance();
203}
204
205/************************************ tests ***********************************/
206
207void ParserMpqcUnitTest::ParameterDefaultTest() {
208 // check default values
209 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
210 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
211 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
212 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
213 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
214 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
215 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
216 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
217 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
218 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
219 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
220}
221
222void ParserMpqcUnitTest::ParameterCloneTest() {
223 FormatParser_Parameters *clone = parser->getParams().clone();
224 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
225 std::stringstream setvalue("theory = CLHF");
226 setvalue >> parser->getParams();
227 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
228 parser->getParams().makeClone(*clone);
229 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
230}
231
232void ParserMpqcUnitTest::ParameterSetterTest() {
233 // test a string
234 {
235 std::stringstream setvalue("theory = CLHF");
236 setvalue >> parser->getParams();
237// std::cout << "integration method is "
238// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
239 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
240 }
241 // test a bool
242 {
243 std::stringstream setvalue("Hessian = yes");
244 setvalue >> parser->getParams();
245// std::cout << "Hessian is "
246// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
247 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
248 }
249 // test int
250 {
251 std::stringstream setvalue("maxiter = 500");
252 setvalue >> parser->getParams();
253// std::cout << "maxiter is "
254// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
255 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
256 }
257 // test whether unknown key fails
258 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
259 {
260 std::stringstream setvalue("hessian = no");
261#ifndef NDEBUG
262 ASSERT_DO(Assert::Throw);
263 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
264#else
265 setvalue >> parser->getParams();
266#endif
267// std::cout << "Hessian is still "
268// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
269 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
270 }
271}
272
273void ParserMpqcUnitTest::readMpqcTest() {
274 stringstream input(waterMpqc_CLHF);
275 parser->getParams().setParameter(
276 MpqcParser_Parameters::theoryParam,
277 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
278 );
279 parser->load(&input);
280
281 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
282}
283
284void ParserMpqcUnitTest::writeMpqcTest() {
285 // build up water molecule
286 string first;
287 string second;
288 atom *Walker = NULL;
289 Walker = World::getInstance().createAtom();
290 Walker->setType(8);
291 Walker->setPosition(Vector(0,0,0));
292 Walker = World::getInstance().createAtom();
293 Walker->setType(1);
294 Walker->setPosition(Vector(0.758602,0,0.504284));
295 Walker = World::getInstance().createAtom();
296 Walker->setType(1);
297 Walker->setPosition(Vector(0.758602,0,-0.504284));
298 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
299
300 // create two stringstreams, one stored, one created
301
302 std::vector<const atom *> atoms = const_cast<const World &>(World::getInstance()).
303 getAllAtoms();
304 {
305 // compare both configs for CLHF
306 stringstream output;
307 parser->getParams().setParameter(
308 MpqcParser_Parameters::theoryParam,
309 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
310 );
311 parser->save(&output, atoms);
312 stringstream input(waterMpqc_CLHF);
313 // check for non-empty streams
314 input.peek();
315 output.peek();
316 CPPUNIT_ASSERT(input.good() && output.good());
317 // check equality of streams per line (for debugging)
318 for (; std::getline(input, first) && std::getline(output, second); ) {
319 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
320 CPPUNIT_ASSERT(first == second);
321 }
322 }
323 {
324 // compare both configs for CLKS
325 stringstream output;
326 parser->getParams().setParameter(
327 MpqcParser_Parameters::theoryParam,
328 parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
329 );
330 parser->save(&output, atoms);
331 stringstream input(waterMpqc_CLKS);
332 // check for non-empty streams
333 input.peek();
334 output.peek();
335 CPPUNIT_ASSERT(input.good() && output.good());
336 // check equality of streams per line (for debugging)
337 for (; std::getline(input, first) && std::getline(output, second); ) {
338 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
339 CPPUNIT_ASSERT(first == second);
340 }
341 }
342 {
343 // compare both configs for MBPT2
344 stringstream output;
345 parser->getParams().setParameter(
346 MpqcParser_Parameters::theoryParam,
347 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
348 );
349 parser->save(&output, atoms);
350 stringstream input(waterMpqc_MBPT2);
351 // check for non-empty streams
352 input.peek();
353 output.peek();
354 CPPUNIT_ASSERT(input.good() && output.good());
355 // check equality of streams per line (for debugging)
356 for (; std::getline(input, first) && std::getline(output, second); ) {
357 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
358 CPPUNIT_ASSERT(first == second);
359 }
360 }
361 {
362 // compare both configs for MBPT2_R12
363 stringstream output;
364 parser->getParams().setParameter(
365 MpqcParser_Parameters::theoryParam,
366 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
367 );
368 parser->save(&output, atoms);
369 stringstream input(waterMpqc_MBPT2_R12);
370 // check for non-empty streams
371 input.peek();
372 output.peek();
373 CPPUNIT_ASSERT(input.good() && output.good());
374 // check equality of streams per line (for debugging)
375 for (; std::getline(input, first) && std::getline(output, second); ) {
376 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
377 CPPUNIT_ASSERT(first == second);
378 }
379 }
380}
Note: See TracBrowser for help on using the repository browser.