source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 6f0841

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

Shifted all modules related to atoms into own subfolder src/Atom/

  • also created own convenience library for this. This makes unit testing on list containing TesselPoint or atom a lot easier.
  • shifted TesselPoint to src/Atom from src/Tesselation and adapted include's.
  • 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-2011 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/atom.hpp"
30#include "Element/element.hpp"
31#include "Element/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::ParameterDefaultTest() {
186 // check default values
187 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
188 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
189 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
190 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
191 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
192 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
193 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
194 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
195 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
196 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
197 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
198}
199
200void ParserMpqcUnitTest::ParameterCloneTest() {
201 FormatParser_Parameters *clone = parser->getParams().clone();
202 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
203 std::stringstream setvalue("theory = CLHF");
204 setvalue >> parser->getParams();
205 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
206 parser->getParams().makeClone(*clone);
207 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
208}
209
210void ParserMpqcUnitTest::ParameterSetterTest() {
211 // test a string
212 {
213 std::stringstream setvalue("theory = CLHF");
214 setvalue >> parser->getParams();
215// std::cout << "integration method is "
216// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
217 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
218 }
219 // test a bool
220 {
221 std::stringstream setvalue("Hessian = yes");
222 setvalue >> parser->getParams();
223// std::cout << "Hessian is "
224// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
225 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
226 }
227 // test int
228 {
229 std::stringstream setvalue("maxiter = 500");
230 setvalue >> parser->getParams();
231// std::cout << "maxiter is "
232// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
233 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
234 }
235 // test whether unknown key fails
236 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
237 {
238 std::stringstream setvalue("hessian = no");
239#ifndef NDEBUG
240 ASSERT_DO(Assert::Throw);
241 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
242#else
243 setvalue >> parser->getParams();
244#endif
245// std::cout << "Hessian is still "
246// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
247 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
248 }
249}
250
251void ParserMpqcUnitTest::readMpqcTest() {
252 stringstream input(waterMpqc_CLHF);
253 parser->getParams().setParameter(
254 MpqcParser_Parameters::theoryParam,
255 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
256 );
257 parser->load(&input);
258
259 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
260}
261
262void ParserMpqcUnitTest::writeMpqcTest() {
263 // build up water molecule
264 string first;
265 string second;
266 atom *Walker = NULL;
267 Walker = World::getInstance().createAtom();
268 Walker->setType(8);
269 Walker->setPosition(Vector(0,0,0));
270 Walker = World::getInstance().createAtom();
271 Walker->setType(1);
272 Walker->setPosition(Vector(0.758602,0,0.504284));
273 Walker = World::getInstance().createAtom();
274 Walker->setType(1);
275 Walker->setPosition(Vector(0.758602,0,-0.504284));
276 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
277
278 // create two stringstreams, one stored, one created
279
280 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
281 {
282 // compare both configs for CLHF
283 stringstream output;
284 parser->getParams().setParameter(
285 MpqcParser_Parameters::theoryParam,
286 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
287 );
288 parser->save(&output, atoms);
289 stringstream input(waterMpqc_CLHF);
290 // check for non-empty streams
291 input.peek();
292 output.peek();
293 CPPUNIT_ASSERT(input.good() && output.good());
294 // check equality of streams per line (for debugging)
295 for (; std::getline(input, first) && std::getline(output, second); ) {
296 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
297 CPPUNIT_ASSERT(first == second);
298 }
299 }
300 {
301 // compare both configs for CLKS
302 stringstream output;
303 parser->getParams().setParameter(
304 MpqcParser_Parameters::theoryParam,
305 parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
306 );
307 parser->save(&output, atoms);
308 stringstream input(waterMpqc_CLKS);
309 // check for non-empty streams
310 input.peek();
311 output.peek();
312 CPPUNIT_ASSERT(input.good() && output.good());
313 // check equality of streams per line (for debugging)
314 for (; std::getline(input, first) && std::getline(output, second); ) {
315 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
316 CPPUNIT_ASSERT(first == second);
317 }
318 }
319 {
320 // compare both configs for MBPT2
321 stringstream output;
322 parser->getParams().setParameter(
323 MpqcParser_Parameters::theoryParam,
324 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
325 );
326 parser->save(&output, atoms);
327 stringstream input(waterMpqc_MBPT2);
328 // check for non-empty streams
329 input.peek();
330 output.peek();
331 CPPUNIT_ASSERT(input.good() && output.good());
332 // check equality of streams per line (for debugging)
333 for (; std::getline(input, first) && std::getline(output, second); ) {
334 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
335 CPPUNIT_ASSERT(first == second);
336 }
337 }
338 {
339 // compare both configs for MBPT2_R12
340 stringstream output;
341 parser->getParams().setParameter(
342 MpqcParser_Parameters::theoryParam,
343 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
344 );
345 parser->save(&output, atoms);
346 stringstream input(waterMpqc_MBPT2_R12);
347 // check for non-empty streams
348 input.peek();
349 output.peek();
350 CPPUNIT_ASSERT(input.good() && output.good());
351 // check equality of streams per line (for debugging)
352 for (; std::getline(input, first) && std::getline(output, second); ) {
353 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
354 CPPUNIT_ASSERT(first == second);
355 }
356 }
357}
Note: See TracBrowser for help on using the repository browser.