source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ 286a967

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 v1.3.3
Last change on this file since 286a967 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

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