source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 99db9b

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 99db9b was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • 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-2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * ParserMpqcUnitTest.cpp
26 *
27 * Created on: Mar 3, 2010
28 * Author: metzler
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "ParserMpqcUnitTest.hpp"
37
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41
42#include <boost/any.hpp>
43
44#include "Atom/atom.hpp"
45#include "Atom/AtomObserver.hpp"
46#include "CodePatterns/Assert.hpp"
47#include "Descriptors/AtomTypeDescriptor.hpp"
48#include "Element/element.hpp"
49#include "Element/periodentafel.hpp"
50#include "Parser/ChangeTracker.hpp"
51#include "Parser/MpqcParser.hpp"
52#include "World.hpp"
53
54#ifdef HAVE_TESTRUNNER
55#include "UnitTestMain.hpp"
56#endif /*HAVE_TESTRUNNER*/
57
58using namespace std;
59
60// Registers the fixture into the 'registry'
61CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
62
63static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
64mpqc: (\n\
65\tsavestate = no\n\
66\tdo_gradient = yes\n\
67\tmole<CLHF>: (\n\
68\t\tmolecule = $:molecule\n\
69\t\tbasis = $:basis\n\
70\t\tmaxiter = 1000\n\
71\t\tmemory = 16000000\n\
72\t)\n\
73)\n\
74molecule<Molecule>: (\n\
75\tunit = angstrom\n\
76\t{ atoms geometry } = {\n\
77\t\tO [ 0\t0\t0 ]\n\
78\t\tH [ 0.758602\t0\t0.504284 ]\n\
79\t\tH [ 0.758602\t0\t-0.504284 ]\n\
80\t}\n\
81)\n\
82basis<GaussianBasisSet>: (\n\
83\tname = \"3-21G\"\n\
84\tmolecule = $:molecule\n\
85)\n"; // tested with mpqc 3.0.0-alpha
86static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
87mpqc: (\n\
88\tsavestate = no\n\
89\tdo_gradient = yes\n\
90\tmole<CLKS>: (\n\
91\t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
92\t\tmolecule = $:molecule\n\
93\t\tbasis = $:basis\n\
94\t\tmaxiter = 1000\n\
95\t\tmemory = 16000000\n\
96\t)\n\
97)\n\
98molecule<Molecule>: (\n\
99\tunit = angstrom\n\
100\t{ atoms geometry } = {\n\
101\t\tO [ 0\t0\t0 ]\n\
102\t\tH [ 0.758602\t0\t0.504284 ]\n\
103\t\tH [ 0.758602\t0\t-0.504284 ]\n\
104\t}\n\
105)\n\
106basis<GaussianBasisSet>: (\n\
107\tname = \"3-21G\"\n\
108\tmolecule = $:molecule\n\
109)\n"; // tested with mpqc 3.0.0-alpha
110static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
111mpqc: (\n\
112\tsavestate = no\n\
113\tdo_gradient = yes\n\
114\tmole<MBPT2>: (\n\
115\t\tbasis = $:basis\n\
116\t\tmolecule = $:molecule\n\
117\t\tmemory = 16000000\n\
118\t\treference<CLHF>: (\n\
119\t\t\tmaxiter = 1000\n\
120\t\t\tbasis = $:basis\n\
121\t\t\tmolecule = $:molecule\n\
122\t\t\tmemory = 16000000\n\
123\t\t)\n\
124\t)\n\
125)\n\
126molecule<Molecule>: (\n\
127\tunit = angstrom\n\
128\t{ atoms geometry } = {\n\
129\t\tO [ 0\t0\t0 ]\n\
130\t\tH [ 0.758602\t0\t0.504284 ]\n\
131\t\tH [ 0.758602\t0\t-0.504284 ]\n\
132\t}\n\
133)\n\
134basis<GaussianBasisSet>: (\n\
135\tname = \"3-21G\"\n\
136\tmolecule = $:molecule\n\
137)\n"; // tested with mpqc 3.0.0-alpha
138static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
139mpqc: (\n\
140\tsavestate = no\n\
141\tdo_gradient = yes\n\
142\tmole<MBPT2_R12>: (\n\
143\t\tmolecule = $:molecule\n\
144\t\tbasis = $:basis\n\
145\t\taux_basis = $:abasis\n\
146\t\tstdapprox = \"A'\"\n\
147\t\tnfzc = 1\n\
148\t\tmemory = 16000000\n\
149\t\tintegrals<IntegralCints>:()\n\
150\t\treference<CLHF>: (\n\
151\t\t\tmolecule = $:molecule\n\
152\t\t\tbasis = $:basis\n\
153\t\t\tmaxiter = 1000\n\
154\t\t\tmemory = 16000000\n\
155\t\t\tintegrals<IntegralCints>:()\n\
156\t\t)\n\
157\t)\n\
158)\n\
159molecule<Molecule>: (\n\
160\tunit = angstrom\n\
161\t{ atoms geometry } = {\n\
162\t\tO [ 0\t0\t0 ]\n\
163\t\tH [ 0.758602\t0\t0.504284 ]\n\
164\t\tH [ 0.758602\t0\t-0.504284 ]\n\
165\t}\n\
166)\n\
167basis<GaussianBasisSet>: (\n\
168\tname = \"3-21G\"\n\
169\tmolecule = $:molecule\n\
170)\n\
171% auxiliary basis set specification\n\
172\tabasis<GaussianBasisSet>: (\n\
173\tname = \"aug-cc-pVDZ\"\n\
174\tmolecule = $:molecule\n\
175)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
176
177void ParserMpqcUnitTest::setUp()
178{
179 // failing asserts should be thrown
180 ASSERT_DO(Assert::Throw);
181
182 parser = new FormatParser<mpqc>();
183
184 World::getInstance();
185
186 setVerbosity(2);
187
188 // we need hydrogens and oxygens in the following tests
189 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
190 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
191}
192
193void ParserMpqcUnitTest::tearDown()
194{
195 delete parser;
196 ChangeTracker::purgeInstance();
197 World::purgeInstance();
198 AtomObserver::purgeInstance();
199}
200
201/************************************ tests ***********************************/
202
203void ParserMpqcUnitTest::ParameterDefaultTest() {
204 // check default values
205 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
206 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
207 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
208 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
209 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
210 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
211 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
212 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
213 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
214 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
215 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
216}
217
218void ParserMpqcUnitTest::ParameterCloneTest() {
219 FormatParser_Parameters *clone = parser->getParams().clone();
220 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
221 std::stringstream setvalue("theory = CLHF");
222 setvalue >> parser->getParams();
223 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
224 parser->getParams().makeClone(*clone);
225 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
226}
227
228void ParserMpqcUnitTest::ParameterSetterTest() {
229 // test a string
230 {
231 std::stringstream setvalue("theory = CLHF");
232 setvalue >> parser->getParams();
233// std::cout << "integration method is "
234// << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
235 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
236 }
237 // test a bool
238 {
239 std::stringstream setvalue("Hessian = yes");
240 setvalue >> parser->getParams();
241// std::cout << "Hessian is "
242// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
243 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
244 }
245 // test int
246 {
247 std::stringstream setvalue("maxiter = 500");
248 setvalue >> parser->getParams();
249// std::cout << "maxiter is "
250// << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
251 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
252 }
253 // test whether unknown key fails
254 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
255 {
256 std::stringstream setvalue("hessian = no");
257#ifndef NDEBUG
258 ASSERT_DO(Assert::Throw);
259 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
260#else
261 setvalue >> parser->getParams();
262#endif
263// std::cout << "Hessian is still "
264// << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
265 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
266 }
267}
268
269void ParserMpqcUnitTest::readMpqcTest() {
270 stringstream input(waterMpqc_CLHF);
271 parser->getParams().setParameter(
272 MpqcParser_Parameters::theoryParam,
273 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
274 );
275 parser->load(&input);
276
277 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
278}
279
280void ParserMpqcUnitTest::writeMpqcTest() {
281 // build up water molecule
282 string first;
283 string second;
284 atom *Walker = NULL;
285 Walker = World::getInstance().createAtom();
286 Walker->setType(8);
287 Walker->setPosition(Vector(0,0,0));
288 Walker = World::getInstance().createAtom();
289 Walker->setType(1);
290 Walker->setPosition(Vector(0.758602,0,0.504284));
291 Walker = World::getInstance().createAtom();
292 Walker->setType(1);
293 Walker->setPosition(Vector(0.758602,0,-0.504284));
294 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
295
296 // create two stringstreams, one stored, one created
297
298 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
299 {
300 // compare both configs for CLHF
301 stringstream output;
302 parser->getParams().setParameter(
303 MpqcParser_Parameters::theoryParam,
304 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
305 );
306 parser->save(&output, atoms);
307 stringstream input(waterMpqc_CLHF);
308 // check for non-empty streams
309 input.peek();
310 output.peek();
311 CPPUNIT_ASSERT(input.good() && output.good());
312 // check equality of streams per line (for debugging)
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().setParameter(
322 MpqcParser_Parameters::theoryParam,
323 parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
324 );
325 parser->save(&output, atoms);
326 stringstream input(waterMpqc_CLKS);
327 // check for non-empty streams
328 input.peek();
329 output.peek();
330 CPPUNIT_ASSERT(input.good() && output.good());
331 // check equality of streams per line (for debugging)
332 for (; std::getline(input, first) && std::getline(output, second); ) {
333 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
334 CPPUNIT_ASSERT(first == second);
335 }
336 }
337 {
338 // compare both configs for MBPT2
339 stringstream output;
340 parser->getParams().setParameter(
341 MpqcParser_Parameters::theoryParam,
342 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
343 );
344 parser->save(&output, atoms);
345 stringstream input(waterMpqc_MBPT2);
346 // check for non-empty streams
347 input.peek();
348 output.peek();
349 CPPUNIT_ASSERT(input.good() && output.good());
350 // check equality of streams per line (for debugging)
351 for (; std::getline(input, first) && std::getline(output, second); ) {
352 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
353 CPPUNIT_ASSERT(first == second);
354 }
355 }
356 {
357 // compare both configs for MBPT2_R12
358 stringstream output;
359 parser->getParams().setParameter(
360 MpqcParser_Parameters::theoryParam,
361 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
362 );
363 parser->save(&output, atoms);
364 stringstream input(waterMpqc_MBPT2_R12);
365 // check for non-empty streams
366 input.peek();
367 output.peek();
368 CPPUNIT_ASSERT(input.good() && output.good());
369 // check equality of streams per line (for debugging)
370 for (; std::getline(input, first) && std::getline(output, second); ) {
371 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
372 CPPUNIT_ASSERT(first == second);
373 }
374 }
375}
Note: See TracBrowser for help on using the repository browser.