source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 765f16

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 765f16 was 765f16, checked in by Frederik Heber <heber@…>, 13 years ago

Huge Refactoring of FormatParserStorage and all FormatParser's.

FormatParser:

FormatParserStorage:

  • We construct all lookup tables and alikes via boost preprocessor magic from a list of all available parser (enums).
  • we use the templated getParser() and addParser() functions to serve parsers to the outside. Instances are as usual created only once.

Tests:

  • tests only had to be changed because of the "renaming" of the Parsers.
  • Property mode set to 100644
File size: 12.3 KB
RevLine 
[9e4fd1]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
[61d69a4]26#include <boost/any.hpp>
27
[9e4fd1]28#include "World.hpp"
29#include "atom.hpp"
30#include "element.hpp"
31#include "periodentafel.hpp"
32#include "Descriptors/AtomTypeDescriptor.hpp"
[311da7b]33#include "CodePatterns/Assert.hpp"
[765f16]34#include "Parser/ChangeTracker.hpp"
35#include "Parser/MpqcParser.hpp"
[9e4fd1]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
[f31edc]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\
[61d69a4]53\t\tmaxiter = 1000\n\
[f31edc]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\
[61d69a4]77\t\tmaxiter = 1000\n\
[f31edc]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\
[9e4fd1]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\
[61d69a4]100\t\tmemory = 16000000\n\
[9e4fd1]101\t\treference<CLHF>: (\n\
[bb74ba]102\t\t\tmaxiter = 1000\n\
[9e4fd1]103\t\t\tbasis = $:basis\n\
104\t\t\tmolecule = $:molecule\n\
[61d69a4]105\t\t\tmemory = 16000000\n\
[9e4fd1]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\
[f31edc]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)
[9e4fd1]159
160void ParserMpqcUnitTest::setUp() {
[765f16]161 parser = new FormatParser<mpqc>();
[61d69a4]162
[9e4fd1]163 World::getInstance();
164
165 setVerbosity(2);
166
167 // we need hydrogens and oxygens in the following tests
168 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
169 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
170}
171
172void ParserMpqcUnitTest::tearDown() {
[765f16]173 delete parser;
[9e4fd1]174 ChangeTracker::purgeInstance();
175 World::purgeInstance();
176}
177
178/************************************ tests ***********************************/
179
[61d69a4]180void ParserMpqcUnitTest::ParameterTypeTest() {
181 // check types in boost::any map
[765f16]182 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
183 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
184 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
185 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
186 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
187 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
188 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
189 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
190 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
191 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
192 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
193 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
[61d69a4]194}
195
196void ParserMpqcUnitTest::ParameterDefaultTest() {
197 // check default values
[765f16]198 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
199 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
200 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
201 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
202 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
203 CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
204 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
205 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
206 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
207 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
208 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
209 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
210 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
211 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
212 CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
213 CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
[61d69a4]214
215 // check that values are not removed
[765f16]216 CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
[61d69a4]217
218 // check throw, for the moment aren't, are caught in getInt()
[765f16]219 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
220 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
[61d69a4]221
222}
223
[c1db05]224void ParserMpqcUnitTest::ParameterCloneTest() {
[765f16]225 FormatParser_Parameters *clone = parser->getParams().clone();
226 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
[c1db05]227 std::stringstream setvalue("theory = CLHF");
[765f16]228 setvalue >> parser->getParams();
229 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
230 parser->getParams().makeClone(*clone);
231 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
[c1db05]232}
233
[44fce5]234void ParserMpqcUnitTest::ParameterSetterTest() {
235 // test a string
236 {
237 std::stringstream setvalue("theory = CLHF");
[765f16]238 setvalue >> parser->getParams();
[44fce5]239// std::cout << "integration method is "
[765f16]240// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
241 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
[44fce5]242 }
243 // test a bool
244 {
245 std::stringstream setvalue("Hessian = yes");
[765f16]246 setvalue >> parser->getParams();
[44fce5]247// std::cout << "Hessian is "
[765f16]248// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
249 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
[44fce5]250 }
251 // test int
252 {
253 std::stringstream setvalue("maxiter = 500");
[765f16]254 setvalue >> parser->getParams();
[44fce5]255// std::cout << "maxiter is "
[765f16]256// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
257 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
[44fce5]258 }
259 // test whether unknown key fails
[311da7b]260 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
[44fce5]261 {
262 std::stringstream setvalue("hessian = no");
[311da7b]263#ifndef NDEBUG
264 ASSERT_DO(Assert::Throw);
[765f16]265 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
[311da7b]266#else
[765f16]267 setvalue >> parser->getParams();
[311da7b]268#endif
[44fce5]269// std::cout << "Hessian is still "
[765f16]270// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
271 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
[44fce5]272 }
273}
274
[aa8ef2]275void ParserMpqcUnitTest::readMpqcTest() {
276 stringstream input(waterMpqc_CLHF);
[765f16]277 parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
278 parser->load(&input);
[aa8ef2]279
280 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
281}
282
[9e4fd1]283void ParserMpqcUnitTest::writeMpqcTest() {
284 // build up water molecule
[f31edc]285 string first;
286 string second;
[9e4fd1]287 atom *Walker = NULL;
288 Walker = World::getInstance().createAtom();
289 Walker->setType(8);
290 Walker->setPosition(Vector(0,0,0));
291 Walker = World::getInstance().createAtom();
292 Walker->setType(1);
293 Walker->setPosition(Vector(0.758602,0,0.504284));
294 Walker = World::getInstance().createAtom();
295 Walker->setType(1);
296 Walker->setPosition(Vector(0.758602,0,-0.504284));
297 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
298
299 // create two stringstreams, one stored, one created
[f31edc]300
[9e4fd1]301 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[f31edc]302 {
303 // compare both configs for CLHF
304 stringstream output;
[765f16]305 parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
306 parser->save(&output, atoms);
[f31edc]307 stringstream input(waterMpqc_CLHF);
308 for (; std::getline(input, first) && std::getline(output, second); ) {
309 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
310 CPPUNIT_ASSERT(first == second);
311 }
312 }
313 {
314 // compare both configs for CLKS
315 stringstream output;
[765f16]316 parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
317 parser->save(&output, atoms);
[f31edc]318 stringstream input(waterMpqc_CLKS);
319 for (; std::getline(input, first) && std::getline(output, second); ) {
320 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
321 CPPUNIT_ASSERT(first == second);
322 }
323 }
324 {
325 // compare both configs for MBPT2
326 stringstream output;
[765f16]327 parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
328 parser->save(&output, atoms);
[f31edc]329 stringstream input(waterMpqc_MBPT2);
330 for (; std::getline(input, first) && std::getline(output, second); ) {
331 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
332 CPPUNIT_ASSERT(first == second);
333 }
334 }
335 {
336 // compare both configs for MBPT2_R12
337 stringstream output;
[765f16]338 parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
339 parser->save(&output, atoms);
[f31edc]340 stringstream input(waterMpqc_MBPT2_R12);
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 }
[9e4fd1]346}
Note: See TracBrowser for help on using the repository browser.