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

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 e611dc was 311da7b, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: Changed MpqcParser.

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