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(hydrogenPsi3_RHF);
|
---|
270 | // set some other parameter for jobtype
|
---|
271 | params->setParameter(
|
---|
272 | Psi3Parser_Parameters::jobtypeParam,
|
---|
273 | params->ValidJobtypes[Psi3Parser_Parameters::OPT]
|
---|
274 | );
|
---|
275 | parser->load(&input);
|
---|
276 |
|
---|
277 | // check for jobtype from file
|
---|
278 | CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
|
---|
279 | // check for 2 hydrogens
|
---|
280 | CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
|
---|
281 | // check that positions are right
|
---|
282 | Vector PositionSum;
|
---|
283 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
284 | for (std::vector<atom *>::const_iterator iter = atoms.begin();
|
---|
285 | iter != atoms.end();
|
---|
286 | ++iter)
|
---|
287 | PositionSum += (*iter)->getPosition();
|
---|
288 | CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0,0,0.74) );
|
---|
289 | }
|
---|
290 |
|
---|
291 | void ParserPsi3UnitTest::writePsi3Test() {
|
---|
292 | // // build up water molecule
|
---|
293 | // string first;
|
---|
294 | // string second;
|
---|
295 | // atom *Walker = NULL;
|
---|
296 | // Walker = World::getInstance().createAtom();
|
---|
297 | // Walker->setType(8);
|
---|
298 | // Walker->setPosition(Vector(0,0,0));
|
---|
299 | // Walker = World::getInstance().createAtom();
|
---|
300 | // Walker->setType(1);
|
---|
301 | // Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
302 | // Walker = World::getInstance().createAtom();
|
---|
303 | // Walker->setType(1);
|
---|
304 | // Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
305 | // CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
306 | //
|
---|
307 | // // create two stringstreams, one stored, one created
|
---|
308 | //
|
---|
309 | // std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
310 | // {
|
---|
311 | // // compare both configs for CLHF
|
---|
312 | // stringstream output;
|
---|
313 | // params->setParameter(
|
---|
314 | // Psi3Parser_Parameters::theoryParam,
|
---|
315 | // params->getTheoryName(Psi3Parser_Parameters::CLHF)
|
---|
316 | // );
|
---|
317 | // parser->save(&output, atoms);
|
---|
318 | // stringstream input(waterPsi3_CLHF);
|
---|
319 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
320 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
321 | // CPPUNIT_ASSERT(first == second);
|
---|
322 | // }
|
---|
323 | // }
|
---|
324 | // {
|
---|
325 | // // compare both configs for CLKS
|
---|
326 | // stringstream output;
|
---|
327 | // params->setParameter(
|
---|
328 | // Psi3Parser_Parameters::theoryParam,
|
---|
329 | // params->getTheoryName(Psi3Parser_Parameters::CLKS)
|
---|
330 | // );
|
---|
331 | // stringstream input(waterPsi3_CLKS);
|
---|
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 | // params->setParameter(
|
---|
341 | // Psi3Parser_Parameters::theoryParam,
|
---|
342 | // params->getTheoryName(Psi3Parser_Parameters::MBPT2)
|
---|
343 | // );
|
---|
344 | // stringstream input(waterPsi3_MBPT2);
|
---|
345 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
346 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
347 | // CPPUNIT_ASSERT(first == second);
|
---|
348 | // }
|
---|
349 | // }
|
---|
350 | // {
|
---|
351 | // // compare both configs for MBPT2_R12
|
---|
352 | // stringstream output;
|
---|
353 | // params->setParameter(
|
---|
354 | // Psi3Parser_Parameters::theoryParam,
|
---|
355 | // params->getTheoryName(Psi3Parser_Parameters::MBPT2_R12)
|
---|
356 | // );
|
---|
357 | // stringstream input(waterPsi3_MBPT2_R12);
|
---|
358 | // for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
359 | // //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
360 | // CPPUNIT_ASSERT(first == second);
|
---|
361 | // }
|
---|
362 | // }
|
---|
363 | }
|
---|