source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 39fa96

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 39fa96 was 3308b6, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: 3 out of 4 unit tests have not been told to throw AssertException instead of abort.

  • Property mode set to 100644
File size: 12.4 KB
Line 
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 * 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 "World.hpp"
29#include "atom.hpp"
30#include "element.hpp"
31#include "periodentafel.hpp"
32#include "Descriptors/AtomTypeDescriptor.hpp"
33#include "CodePatterns/Assert.hpp"
34#include "Parser/ChangeTracker.hpp"
35#include "Parser/MpqcParser.hpp"
36
37#ifdef HAVE_TESTRUNNER
38#include "UnitTestMain.hpp"
39#endif /*HAVE_TESTRUNNER*/
40
41using namespace std;
42
43// Registers the fixture into the 'registry'
44CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
45
46static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
47mpqc: (\n\
48\tsavestate = no\n\
49\tdo_gradient = yes\n\
50\tmole<CLHF>: (\n\
51\t\tmolecule = $:molecule\n\
52\t\tbasis = $:basis\n\
53\t\tmaxiter = 1000\n\
54\t\tmemory = 16000000\n\
55\t)\n\
56)\n\
57molecule<Molecule>: (\n\
58\tunit = angstrom\n\
59\t{ atoms geometry } = {\n\
60\t\tO [ -0.505735\t0\t0 ]\n\
61\t\tH [ 0.252867\t0\t0.504284 ]\n\
62\t\tH [ 0.252867\t0\t-0.504284 ]\n\
63\t}\n\
64)\n\
65basis<GaussianBasisSet>: (\n\
66\tname = \"3-21G\"\n\
67\tmolecule = $:molecule\n\
68)\n"; // tested with mpqc 3.0.0-alpha
69static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
70mpqc: (\n\
71\tsavestate = no\n\
72\tdo_gradient = yes\n\
73\tmole<CLKS>: (\n\
74\t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
75\t\tmolecule = $:molecule\n\
76\t\tbasis = $:basis\n\
77\t\tmaxiter = 1000\n\
78\t\tmemory = 16000000\n\
79\t)\n\
80)\n\
81molecule<Molecule>: (\n\
82\tunit = angstrom\n\
83\t{ atoms geometry } = {\n\
84\t\tO [ -0.505735\t0\t0 ]\n\
85\t\tH [ 0.252867\t0\t0.504284 ]\n\
86\t\tH [ 0.252867\t0\t-0.504284 ]\n\
87\t}\n\
88)\n\
89basis<GaussianBasisSet>: (\n\
90\tname = \"3-21G\"\n\
91\tmolecule = $:molecule\n\
92)\n"; // tested with mpqc 3.0.0-alpha
93static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
94mpqc: (\n\
95\tsavestate = no\n\
96\tdo_gradient = yes\n\
97\tmole<MBPT2>: (\n\
98\t\tbasis = $:basis\n\
99\t\tmolecule = $:molecule\n\
100\t\tmemory = 16000000\n\
101\t\treference<CLHF>: (\n\
102\t\t\tmaxiter = 1000\n\
103\t\t\tbasis = $:basis\n\
104\t\t\tmolecule = $:molecule\n\
105\t\t\tmemory = 16000000\n\
106\t\t)\n\
107\t)\n\
108)\n\
109molecule<Molecule>: (\n\
110\tunit = angstrom\n\
111\t{ atoms geometry } = {\n\
112\t\tO [ -0.505735\t0\t0 ]\n\
113\t\tH [ 0.252867\t0\t0.504284 ]\n\
114\t\tH [ 0.252867\t0\t-0.504284 ]\n\
115\t}\n\
116)\n\
117basis<GaussianBasisSet>: (\n\
118\tname = \"3-21G\"\n\
119\tmolecule = $:molecule\n\
120)\n"; // tested with mpqc 3.0.0-alpha
121static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
122mpqc: (\n\
123\tsavestate = no\n\
124\tdo_gradient = yes\n\
125\tmole<MBPT2_R12>: (\n\
126\t\tmolecule = $:molecule\n\
127\t\tbasis = $:basis\n\
128\t\taux_basis = $:abasis\n\
129\t\tstdapprox = \"A'\"\n\
130\t\tnfzc = 1\n\
131\t\tmemory = 16000000\n\
132\t\tintegrals<IntegralCints>:()\n\
133\t\treference<CLHF>: (\n\
134\t\t\tmolecule = $:molecule\n\
135\t\t\tbasis = $:basis\n\
136\t\t\tmaxiter = 1000\n\
137\t\t\tmemory = 16000000\n\
138\t\t\tintegrals<IntegralCints>:()\n\
139\t\t)\n\
140\t)\n\
141)\n\
142molecule<Molecule>: (\n\
143\tunit = angstrom\n\
144\t{ atoms geometry } = {\n\
145\t\tO [ -0.505735\t0\t0 ]\n\
146\t\tH [ 0.252867\t0\t0.504284 ]\n\
147\t\tH [ 0.252867\t0\t-0.504284 ]\n\
148\t}\n\
149)\n\
150basis<GaussianBasisSet>: (\n\
151\tname = \"3-21G\"\n\
152\tmolecule = $:molecule\n\
153)\n\
154% auxiliary basis set specification\n\
155\tabasis<GaussianBasisSet>: (\n\
156\tname = \"aug-cc-pVDZ\"\n\
157\tmolecule = $:molecule\n\
158)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
159
160void ParserMpqcUnitTest::setUp()
161{
162 // failing asserts should be thrown
163 ASSERT_DO(Assert::Throw);
164
165 parser = new FormatParser<mpqc>();
166
167 World::getInstance();
168
169 setVerbosity(2);
170
171 // we need hydrogens and oxygens in the following tests
172 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
173 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
174}
175
176void ParserMpqcUnitTest::tearDown()
177{
178 delete parser;
179 ChangeTracker::purgeInstance();
180 World::purgeInstance();
181}
182
183/************************************ tests ***********************************/
184
185void ParserMpqcUnitTest::ParameterTypeTest() {
186 // check types in boost::any map
187 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
188 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
189 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
190 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
191 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
192 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
193 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
194 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
195 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
196 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
197 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
198 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
199}
200
201void ParserMpqcUnitTest::ParameterDefaultTest() {
202 // check default values
203 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
204 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
205 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
206 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
207 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
208 CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
209 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
210 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
211 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
212 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
213 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
214 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
215 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
216 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
217 CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
218 CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
219
220 // check that values are not removed
221 CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
222
223 // check throw, for the moment aren't, are caught in getInt()
224 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
225 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
226
227}
228
229void ParserMpqcUnitTest::ParameterCloneTest() {
230 FormatParser_Parameters *clone = parser->getParams().clone();
231 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
232 std::stringstream setvalue("theory = CLHF");
233 setvalue >> parser->getParams();
234 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
235 parser->getParams().makeClone(*clone);
236 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
237}
238
239void ParserMpqcUnitTest::ParameterSetterTest() {
240 // test a string
241 {
242 std::stringstream setvalue("theory = CLHF");
243 setvalue >> parser->getParams();
244// std::cout << "integration method is "
245// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
246 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
247 }
248 // test a bool
249 {
250 std::stringstream setvalue("Hessian = yes");
251 setvalue >> parser->getParams();
252// std::cout << "Hessian is "
253// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
254 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
255 }
256 // test int
257 {
258 std::stringstream setvalue("maxiter = 500");
259 setvalue >> parser->getParams();
260// std::cout << "maxiter is "
261// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
262 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
263 }
264 // test whether unknown key fails
265 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
266 {
267 std::stringstream setvalue("hessian = no");
268#ifndef NDEBUG
269 ASSERT_DO(Assert::Throw);
270 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
271#else
272 setvalue >> parser->getParams();
273#endif
274// std::cout << "Hessian is still "
275// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
276 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
277 }
278}
279
280void ParserMpqcUnitTest::readMpqcTest() {
281 stringstream input(waterMpqc_CLHF);
282 parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
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<atom *> atoms = World::getInstance().getAllAtoms();
307 {
308 // compare both configs for CLHF
309 stringstream output;
310 parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
311 parser->save(&output, atoms);
312 stringstream input(waterMpqc_CLHF);
313 for (; std::getline(input, first) && std::getline(output, second); ) {
314 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
315 CPPUNIT_ASSERT(first == second);
316 }
317 }
318 {
319 // compare both configs for CLKS
320 stringstream output;
321 parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
322 parser->save(&output, atoms);
323 stringstream input(waterMpqc_CLKS);
324 for (; std::getline(input, first) && std::getline(output, second); ) {
325 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
326 CPPUNIT_ASSERT(first == second);
327 }
328 }
329 {
330 // compare both configs for MBPT2
331 stringstream output;
332 parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
333 parser->save(&output, atoms);
334 stringstream input(waterMpqc_MBPT2);
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().setTheory(MpqcParser_Parameters::MBPT2_R12);
344 parser->save(&output, atoms);
345 stringstream input(waterMpqc_MBPT2_R12);
346 for (; std::getline(input, first) && std::getline(output, second); ) {
347 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
348 CPPUNIT_ASSERT(first == second);
349 }
350 }
351}
Note: See TracBrowser for help on using the repository browser.