source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 7d1b6a

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

FIX: ChangeTracker has not been observing AtomObserver so far.

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