source: src/Parser/unittests/ParserMpqcUnitTest.cpp@ acd638

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 acd638 was 44fce5, checked in by Frederik Heber <heber@…>, 14 years ago

Extended MpqcParser_Parameters, can set and get all values.

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