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 | * ParserPsi3UnitTest.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 "ParserPsi3UnitTest.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 | #include "CodePatterns/Assert.hpp"
|
---|
34 | #include "Parser/ChangeTracker.hpp"
|
---|
35 | #include "Parser/Psi3Parser.hpp"
|
---|
36 |
|
---|
37 | #ifdef HAVE_TESTRUNNER
|
---|
38 | #include "UnitTestMain.hpp"
|
---|
39 | #endif /*HAVE_TESTRUNNER*/
|
---|
40 |
|
---|
41 | using namespace std;
|
---|
42 |
|
---|
43 | // Registers the fixture into the 'registry'
|
---|
44 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserPsi3UnitTest );
|
---|
45 |
|
---|
46 | static string hydrogenPsi3_RHF ="% Created by MoleCuilder\n\
|
---|
47 | psi: (\n\
|
---|
48 | \tlabel = \"cc-pVTZ SCF H2\"\n\
|
---|
49 | \tjobtype = sp\n\
|
---|
50 | \twfn = scf\n\
|
---|
51 | \tmaxiter = 80\n\
|
---|
52 | \treference = rhf\n\
|
---|
53 | \tbasis = \"cc-pVTZ\"\n\
|
---|
54 | \tfreeze_core = no\n\
|
---|
55 | \tunits = bohr\n\
|
---|
56 | \tgeometry = (\n\
|
---|
57 | \t\t( H 0.0000 0.0000 0.0 )\n\
|
---|
58 | \t\t( H 0.0000 0.0000 0.74 )\n\
|
---|
59 | \t)\n\
|
---|
60 | \torigin = (0.0 0.0 0.0)\n\
|
---|
61 | )\n"; // tested with ???
|
---|
62 |
|
---|
63 | static string hydrogenPsi3_ROHF ="% Created by MoleCuilder\n\
|
---|
64 | psi: (\n\
|
---|
65 | \tlabel = \"cc-pVTZ SCF H2\"\n\
|
---|
66 | \tjobtype = sp\n\
|
---|
67 | \twfn = scf\n\
|
---|
68 | \tmaxiter = 80\n\
|
---|
69 | \treference = rohf\n\
|
---|
70 | \tbasis = \"cc-pVTZ\"\n\
|
---|
71 | \tfreeze_core = no\n\
|
---|
72 | \tunits = bohr\n\
|
---|
73 | \tgeometry = (\n\
|
---|
74 | \t\t( H 0.0000 0.0000 0.0 )\n\
|
---|
75 | \t\t( H 0.0000 0.0000 0.74 )\n\
|
---|
76 | \t)\n\
|
---|
77 | \torigin = (0.0 0.0 0.0)\n\
|
---|
78 | )\n"; // tested with ???
|
---|
79 |
|
---|
80 | static string hydrogenPsi3_UHF ="% Created by MoleCuilder\n\
|
---|
81 | psi: (\n\
|
---|
82 | \tlabel = \"cc-pVTZ SCF H2\"\n\
|
---|
83 | \tjobtype = sp\n\
|
---|
84 | \twfn = scf\n\
|
---|
85 | \tmaxiter = 80\n\
|
---|
86 | \treference = uhf\n\
|
---|
87 | \tbasis = \"cc-pVTZ\"\n\
|
---|
88 | \tmultp = 2\n\
|
---|
89 | \t%charge = 2\n\
|
---|
90 | \tfreeze_core = no\n\
|
---|
91 | \tunits = bohr\n\
|
---|
92 | \tgeometry = (\n\
|
---|
93 | \t\t( H 0.0000 0.0000 0.0 )\n\
|
---|
94 | \t\t( H 0.0000 0.0000 0.74 )\n\
|
---|
95 | \t)\n\
|
---|
96 | \torigin = (0.0 0.0 0.0)\n\
|
---|
97 | )\n"; // tested with ???
|
---|
98 |
|
---|
99 | static string hydrogenPsi3_TWOCON ="% Created by MoleCuilder\n\
|
---|
100 | psi: (\n\
|
---|
101 | \tlabel = \"cc-pVTZ SCF H2\"\n\
|
---|
102 | \tjobtype = sp\n\
|
---|
103 | \twfn = scf\n\
|
---|
104 | \tmaxiter = 80\n\
|
---|
105 | \treference = TWOCON\n\
|
---|
106 | \tbasis = \"cc-pVTZ\"\n\
|
---|
107 | \tmultp = 1\n\
|
---|
108 | \t%charge = 2\n\
|
---|
109 | \tsocc = ( 1 1 0 0 0 0 0 0)\n\
|
---|
110 | \tdocc = (0 0 0 0 0 0 0 0)\n\
|
---|
111 | \tfreeze_core = no\n\
|
---|
112 | \tunits = bohr\n\
|
---|
113 | \tgeometry = (\n\
|
---|
114 | \t\t( H 0.0000 0.0000 0.0 )\n\
|
---|
115 | \t\t( H 0.0000 0.0000 0.74 )\n\
|
---|
116 | \t)\n\
|
---|
117 | \torigin = (0.0 0.0 0.0)\n\
|
---|
118 | )\n"; // tested with ???
|
---|
119 |
|
---|
120 | void ParserPsi3UnitTest::setUp()
|
---|
121 | {
|
---|
122 | // failing asserts should be thrown
|
---|
123 | ASSERT_DO(Assert::Throw);
|
---|
124 |
|
---|
125 | parser = new FormatParser<psi3>();
|
---|
126 |
|
---|
127 | params = &parser->getParams();
|
---|
128 |
|
---|
129 | World::getInstance();
|
---|
130 |
|
---|
131 | setVerbosity(2);
|
---|
132 |
|
---|
133 | // we need hydrogens and oxygens in the following tests
|
---|
134 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void ParserPsi3UnitTest::tearDown()
|
---|
138 | {
|
---|
139 | params = NULL;
|
---|
140 | delete parser;
|
---|
141 | ChangeTracker::purgeInstance();
|
---|
142 | World::purgeInstance();
|
---|
143 | }
|
---|
144 |
|
---|
145 | /************************************ tests ***********************************/
|
---|
146 |
|
---|
147 | void ParserPsi3UnitTest::ParameterDefaultTest() {
|
---|
148 | // check default values
|
---|
149 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::labelParam) == std::string("unknown job"));
|
---|
150 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
|
---|
151 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::SCF]);
|
---|
152 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("80"));
|
---|
153 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::RHF]);
|
---|
154 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::basisParam) == std::string("cc-pVTZ"));
|
---|
155 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::YES]);
|
---|
156 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::angstrom]);
|
---|
157 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
|
---|
158 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::originParam) == std::string("(0.0\t0.0\t0.0)"));
|
---|
159 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::multipParam) == std::string("1"));
|
---|
160 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::chargeParam) == std::string("0"));
|
---|
161 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::soccParam) == std::string("()"));
|
---|
162 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::doccParam) == std::string("()"));
|
---|
163 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::subgroupParam) == std::string(""));
|
---|
164 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::X]);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void ParserPsi3UnitTest::ParameterCloneTest() {
|
---|
168 | FormatParser_Parameters *clone = params->clone();
|
---|
169 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
|
---|
170 | std::stringstream setvalue(params->ParamNames[Psi3Parser_Parameters::jobtypeParam]+"="+params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
|
---|
171 | setvalue >> *params;
|
---|
172 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
|
---|
173 | params->makeClone(*clone);
|
---|
174 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void ParserPsi3UnitTest::ParameterSetterTest() {
|
---|
178 | // test a jobtype
|
---|
179 | {
|
---|
180 | std::stringstream setvalue(
|
---|
181 | params->ParamNames[Psi3Parser_Parameters::jobtypeParam]
|
---|
182 | +" = "+params->ValidJobtypes[Psi3Parser_Parameters::OPT]
|
---|
183 | );
|
---|
184 | setvalue >> *params;
|
---|
185 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
|
---|
186 | }
|
---|
187 | // test a wavefunction
|
---|
188 | {
|
---|
189 | std::stringstream setvalue(
|
---|
190 | params->ParamNames[Psi3Parser_Parameters::wavefunctionParam]
|
---|
191 | +" = "+params->ValidWavefunction[Psi3Parser_Parameters::MP2]
|
---|
192 | );
|
---|
193 | setvalue >> *params;
|
---|
194 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::MP2]);
|
---|
195 | }
|
---|
196 | // test a reference
|
---|
197 | {
|
---|
198 | std::stringstream setvalue(
|
---|
199 | params->ParamNames[Psi3Parser_Parameters::referenceParam]
|
---|
200 | +" = "+params->ValidReference[Psi3Parser_Parameters::ROHF]
|
---|
201 | );
|
---|
202 | setvalue >> *params;
|
---|
203 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::ROHF]);
|
---|
204 | }
|
---|
205 | // test a unique_axis
|
---|
206 | {
|
---|
207 | std::stringstream setvalue(
|
---|
208 | params->ParamNames[Psi3Parser_Parameters::unique_axisParam]
|
---|
209 | +" = "+params->ValidUniqueAxis[Psi3Parser_Parameters::Y]
|
---|
210 | );
|
---|
211 | setvalue >> *params;
|
---|
212 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::Y]);
|
---|
213 | }
|
---|
214 | // test a units
|
---|
215 | {
|
---|
216 | std::stringstream setvalue(
|
---|
217 | params->ParamNames[Psi3Parser_Parameters::unitsParam]
|
---|
218 | +" = "+params->ValidUnits[Psi3Parser_Parameters::bohr]
|
---|
219 | );
|
---|
220 | setvalue >> *params;
|
---|
221 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::bohr]);
|
---|
222 | }
|
---|
223 | // test a dertype
|
---|
224 | {
|
---|
225 | std::stringstream setvalue(
|
---|
226 | params->ParamNames[Psi3Parser_Parameters::dertypeParam]
|
---|
227 | +" = "+params->ValidDerivativeType[Psi3Parser_Parameters::NONE]
|
---|
228 | );
|
---|
229 | setvalue >> *params;
|
---|
230 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
|
---|
231 | }
|
---|
232 | // test a freeze_core
|
---|
233 | {
|
---|
234 | std::stringstream setvalue(
|
---|
235 | params->ParamNames[Psi3Parser_Parameters::freeze_coreParam]
|
---|
236 | +" = "+params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]
|
---|
237 | );
|
---|
238 | setvalue >> *params;
|
---|
239 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]);
|
---|
240 | }
|
---|
241 | // test int
|
---|
242 | {
|
---|
243 | std::stringstream setvalue(
|
---|
244 | params->ParamNames[Psi3Parser_Parameters::maxiterParam]
|
---|
245 | +" = 500"
|
---|
246 | );
|
---|
247 | setvalue >> *params;
|
---|
248 | // std::cout << "maxiter is "
|
---|
249 | // << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
|
---|
250 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_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("sd = no");
|
---|
256 | #ifndef NDEBUG
|
---|
257 | ASSERT_DO(Assert::Throw);
|
---|
258 | CPPUNIT_ASSERT_THROW(setvalue >> *params, Assert::AssertionFailure);
|
---|
259 | #else
|
---|
260 | setvalue >> *params;
|
---|
261 | #endif
|
---|
262 | // std::cout << "Hessian is still "
|
---|
263 | // << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
|
---|
264 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | void ParserPsi3UnitTest::readPsi3Test() {
|
---|
269 | // stringstream input(waterPsi3_CLHF);
|
---|
270 | // params->setParameter(
|
---|
271 | // Psi3Parser_Parameters::theoryParam,
|
---|
272 | // params->getTheoryName(Psi3Parser_Parameters::CLHF)
|
---|
273 | // );
|
---|
274 | // parser->load(&input);
|
---|
275 | //
|
---|
276 | // CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
277 | }
|
---|
278 |
|
---|
279 | void ParserPsi3UnitTest::writePsi3Test() {
|
---|
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 | // params->setParameter(
|
---|
302 | // Psi3Parser_Parameters::theoryParam,
|
---|
303 | // params->getTheoryName(Psi3Parser_Parameters::CLHF)
|
---|
304 | // );
|
---|
305 | // parser->save(&output, atoms);
|
---|
306 | // stringstream input(waterPsi3_CLHF);
|
---|
307 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
308 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
309 | // CPPUNIT_ASSERT(first == second);
|
---|
310 | // }
|
---|
311 | // }
|
---|
312 | // {
|
---|
313 | // // compare both configs for CLKS
|
---|
314 | // stringstream output;
|
---|
315 | // params->setParameter(
|
---|
316 | // Psi3Parser_Parameters::theoryParam,
|
---|
317 | // params->getTheoryName(Psi3Parser_Parameters::CLKS)
|
---|
318 | // );
|
---|
319 | // stringstream input(waterPsi3_CLKS);
|
---|
320 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
321 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
322 | // CPPUNIT_ASSERT(first == second);
|
---|
323 | // }
|
---|
324 | // }
|
---|
325 | // {
|
---|
326 | // // compare both configs for MBPT2
|
---|
327 | // stringstream output;
|
---|
328 | // params->setParameter(
|
---|
329 | // Psi3Parser_Parameters::theoryParam,
|
---|
330 | // params->getTheoryName(Psi3Parser_Parameters::MBPT2)
|
---|
331 | // );
|
---|
332 | // stringstream input(waterPsi3_MBPT2);
|
---|
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 | // params->setParameter(
|
---|
342 | // Psi3Parser_Parameters::theoryParam,
|
---|
343 | // params->getTheoryName(Psi3Parser_Parameters::MBPT2_R12)
|
---|
344 | // );
|
---|
345 | // stringstream input(waterPsi3_MBPT2_R12);
|
---|
346 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
347 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
348 | // CPPUNIT_ASSERT(first == second);
|
---|
349 | // }
|
---|
350 | // }
|
---|
351 | }
|
---|