[9e4fd1] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[9e4fd1] | 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 |
|
---|
[61d69a4] | 26 | #include <boost/any.hpp>
|
---|
| 27 |
|
---|
[6f0841] | 28 | #include "Atom/atom.hpp"
|
---|
[006e1e] | 29 | #include "Atom/AtomObserver.hpp"
|
---|
| 30 | #include "CodePatterns/Assert.hpp"
|
---|
| 31 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
[3bdb6d] | 32 | #include "Element/element.hpp"
|
---|
| 33 | #include "Element/periodentafel.hpp"
|
---|
[765f16] | 34 | #include "Parser/ChangeTracker.hpp"
|
---|
| 35 | #include "Parser/MpqcParser.hpp"
|
---|
[006e1e] | 36 | #include "World.hpp"
|
---|
[9e4fd1] | 37 |
|
---|
| 38 | #ifdef HAVE_TESTRUNNER
|
---|
| 39 | #include "UnitTestMain.hpp"
|
---|
| 40 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 41 |
|
---|
| 42 | using namespace std;
|
---|
| 43 |
|
---|
| 44 | // Registers the fixture into the 'registry'
|
---|
| 45 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
|
---|
| 46 |
|
---|
[f31edc] | 47 | static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
|
---|
| 48 | mpqc: (\n\
|
---|
| 49 | \tsavestate = no\n\
|
---|
| 50 | \tdo_gradient = yes\n\
|
---|
| 51 | \tmole<CLHF>: (\n\
|
---|
| 52 | \t\tmolecule = $:molecule\n\
|
---|
| 53 | \t\tbasis = $:basis\n\
|
---|
[61d69a4] | 54 | \t\tmaxiter = 1000\n\
|
---|
[f31edc] | 55 | \t\tmemory = 16000000\n\
|
---|
| 56 | \t)\n\
|
---|
| 57 | )\n\
|
---|
| 58 | molecule<Molecule>: (\n\
|
---|
| 59 | \tunit = angstrom\n\
|
---|
| 60 | \t{ atoms geometry } = {\n\
|
---|
| 61 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 62 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 63 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 64 | \t}\n\
|
---|
| 65 | )\n\
|
---|
| 66 | basis<GaussianBasisSet>: (\n\
|
---|
| 67 | \tname = \"3-21G\"\n\
|
---|
| 68 | \tmolecule = $:molecule\n\
|
---|
| 69 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 70 | static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
|
---|
| 71 | mpqc: (\n\
|
---|
| 72 | \tsavestate = no\n\
|
---|
| 73 | \tdo_gradient = yes\n\
|
---|
| 74 | \tmole<CLKS>: (\n\
|
---|
| 75 | \t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
|
---|
| 76 | \t\tmolecule = $:molecule\n\
|
---|
| 77 | \t\tbasis = $:basis\n\
|
---|
[61d69a4] | 78 | \t\tmaxiter = 1000\n\
|
---|
[f31edc] | 79 | \t\tmemory = 16000000\n\
|
---|
| 80 | \t)\n\
|
---|
| 81 | )\n\
|
---|
| 82 | molecule<Molecule>: (\n\
|
---|
| 83 | \tunit = angstrom\n\
|
---|
| 84 | \t{ atoms geometry } = {\n\
|
---|
| 85 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 86 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 87 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 88 | \t}\n\
|
---|
| 89 | )\n\
|
---|
| 90 | basis<GaussianBasisSet>: (\n\
|
---|
| 91 | \tname = \"3-21G\"\n\
|
---|
| 92 | \tmolecule = $:molecule\n\
|
---|
| 93 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 94 | static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
|
---|
[9e4fd1] | 95 | mpqc: (\n\
|
---|
| 96 | \tsavestate = no\n\
|
---|
| 97 | \tdo_gradient = yes\n\
|
---|
| 98 | \tmole<MBPT2>: (\n\
|
---|
| 99 | \t\tbasis = $:basis\n\
|
---|
| 100 | \t\tmolecule = $:molecule\n\
|
---|
[61d69a4] | 101 | \t\tmemory = 16000000\n\
|
---|
[9e4fd1] | 102 | \t\treference<CLHF>: (\n\
|
---|
[bb74ba] | 103 | \t\t\tmaxiter = 1000\n\
|
---|
[9e4fd1] | 104 | \t\t\tbasis = $:basis\n\
|
---|
| 105 | \t\t\tmolecule = $:molecule\n\
|
---|
[61d69a4] | 106 | \t\t\tmemory = 16000000\n\
|
---|
[9e4fd1] | 107 | \t\t)\n\
|
---|
| 108 | \t)\n\
|
---|
| 109 | )\n\
|
---|
| 110 | molecule<Molecule>: (\n\
|
---|
| 111 | \tunit = angstrom\n\
|
---|
| 112 | \t{ atoms geometry } = {\n\
|
---|
| 113 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 114 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 115 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 116 | \t}\n\
|
---|
| 117 | )\n\
|
---|
| 118 | basis<GaussianBasisSet>: (\n\
|
---|
| 119 | \tname = \"3-21G\"\n\
|
---|
| 120 | \tmolecule = $:molecule\n\
|
---|
[f31edc] | 121 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 122 | static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
|
---|
| 123 | mpqc: (\n\
|
---|
| 124 | \tsavestate = no\n\
|
---|
| 125 | \tdo_gradient = yes\n\
|
---|
| 126 | \tmole<MBPT2_R12>: (\n\
|
---|
| 127 | \t\tmolecule = $:molecule\n\
|
---|
| 128 | \t\tbasis = $:basis\n\
|
---|
| 129 | \t\taux_basis = $:abasis\n\
|
---|
| 130 | \t\tstdapprox = \"A'\"\n\
|
---|
| 131 | \t\tnfzc = 1\n\
|
---|
| 132 | \t\tmemory = 16000000\n\
|
---|
| 133 | \t\tintegrals<IntegralCints>:()\n\
|
---|
| 134 | \t\treference<CLHF>: (\n\
|
---|
| 135 | \t\t\tmolecule = $:molecule\n\
|
---|
| 136 | \t\t\tbasis = $:basis\n\
|
---|
| 137 | \t\t\tmaxiter = 1000\n\
|
---|
| 138 | \t\t\tmemory = 16000000\n\
|
---|
| 139 | \t\t\tintegrals<IntegralCints>:()\n\
|
---|
| 140 | \t\t)\n\
|
---|
| 141 | \t)\n\
|
---|
| 142 | )\n\
|
---|
| 143 | molecule<Molecule>: (\n\
|
---|
| 144 | \tunit = angstrom\n\
|
---|
| 145 | \t{ atoms geometry } = {\n\
|
---|
| 146 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 147 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 148 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 149 | \t}\n\
|
---|
| 150 | )\n\
|
---|
| 151 | basis<GaussianBasisSet>: (\n\
|
---|
| 152 | \tname = \"3-21G\"\n\
|
---|
| 153 | \tmolecule = $:molecule\n\
|
---|
| 154 | )\n\
|
---|
| 155 | % auxiliary basis set specification\n\
|
---|
| 156 | \tabasis<GaussianBasisSet>: (\n\
|
---|
| 157 | \tname = \"aug-cc-pVDZ\"\n\
|
---|
| 158 | \tmolecule = $:molecule\n\
|
---|
| 159 | )\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
|
---|
[9e4fd1] | 160 |
|
---|
[3308b6] | 161 | void ParserMpqcUnitTest::setUp()
|
---|
| 162 | {
|
---|
| 163 | // failing asserts should be thrown
|
---|
| 164 | ASSERT_DO(Assert::Throw);
|
---|
| 165 |
|
---|
[765f16] | 166 | parser = new FormatParser<mpqc>();
|
---|
[61d69a4] | 167 |
|
---|
[9e4fd1] | 168 | World::getInstance();
|
---|
| 169 |
|
---|
| 170 | setVerbosity(2);
|
---|
| 171 |
|
---|
| 172 | // we need hydrogens and oxygens in the following tests
|
---|
| 173 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
| 174 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[3308b6] | 177 | void ParserMpqcUnitTest::tearDown()
|
---|
| 178 | {
|
---|
[765f16] | 179 | delete parser;
|
---|
[9e4fd1] | 180 | ChangeTracker::purgeInstance();
|
---|
[006e1e] | 181 | AtomObserver::purgeInstance();
|
---|
[9e4fd1] | 182 | World::purgeInstance();
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /************************************ tests ***********************************/
|
---|
| 186 |
|
---|
[61d69a4] | 187 | void ParserMpqcUnitTest::ParameterDefaultTest() {
|
---|
| 188 | // check default values
|
---|
[ee50c1] | 189 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
|
---|
| 190 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
|
---|
| 191 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
|
---|
| 192 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
|
---|
| 193 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
|
---|
| 194 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
|
---|
| 195 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
|
---|
| 196 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
|
---|
| 197 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
|
---|
| 198 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
|
---|
| 199 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
[61d69a4] | 200 | }
|
---|
| 201 |
|
---|
[c1db05] | 202 | void ParserMpqcUnitTest::ParameterCloneTest() {
|
---|
[765f16] | 203 | FormatParser_Parameters *clone = parser->getParams().clone();
|
---|
[ee50c1] | 204 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
[c1db05] | 205 | std::stringstream setvalue("theory = CLHF");
|
---|
[765f16] | 206 | setvalue >> parser->getParams();
|
---|
[ee50c1] | 207 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
|
---|
[765f16] | 208 | parser->getParams().makeClone(*clone);
|
---|
[ee50c1] | 209 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
|
---|
[c1db05] | 210 | }
|
---|
| 211 |
|
---|
[44fce5] | 212 | void ParserMpqcUnitTest::ParameterSetterTest() {
|
---|
| 213 | // test a string
|
---|
| 214 | {
|
---|
| 215 | std::stringstream setvalue("theory = CLHF");
|
---|
[765f16] | 216 | setvalue >> parser->getParams();
|
---|
[44fce5] | 217 | // std::cout << "integration method is "
|
---|
[765f16] | 218 | // << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
|
---|
[ee50c1] | 219 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
|
---|
[44fce5] | 220 | }
|
---|
| 221 | // test a bool
|
---|
| 222 | {
|
---|
| 223 | std::stringstream setvalue("Hessian = yes");
|
---|
[765f16] | 224 | setvalue >> parser->getParams();
|
---|
[44fce5] | 225 | // std::cout << "Hessian is "
|
---|
[765f16] | 226 | // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
|
---|
[ee50c1] | 227 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
|
---|
[44fce5] | 228 | }
|
---|
| 229 | // test int
|
---|
| 230 | {
|
---|
| 231 | std::stringstream setvalue("maxiter = 500");
|
---|
[765f16] | 232 | setvalue >> parser->getParams();
|
---|
[44fce5] | 233 | // std::cout << "maxiter is "
|
---|
[765f16] | 234 | // << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
|
---|
[ee50c1] | 235 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
|
---|
[44fce5] | 236 | }
|
---|
| 237 | // test whether unknown key fails
|
---|
[311da7b] | 238 | std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
|
---|
[44fce5] | 239 | {
|
---|
| 240 | std::stringstream setvalue("hessian = no");
|
---|
[311da7b] | 241 | #ifndef NDEBUG
|
---|
| 242 | ASSERT_DO(Assert::Throw);
|
---|
[765f16] | 243 | CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
|
---|
[311da7b] | 244 | #else
|
---|
[765f16] | 245 | setvalue >> parser->getParams();
|
---|
[311da7b] | 246 | #endif
|
---|
[44fce5] | 247 | // std::cout << "Hessian is still "
|
---|
[765f16] | 248 | // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
|
---|
[ee50c1] | 249 | CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
|
---|
[44fce5] | 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[aa8ef2] | 253 | void ParserMpqcUnitTest::readMpqcTest() {
|
---|
| 254 | stringstream input(waterMpqc_CLHF);
|
---|
[ee50c1] | 255 | parser->getParams().setParameter(
|
---|
| 256 | MpqcParser_Parameters::theoryParam,
|
---|
| 257 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
|
---|
| 258 | );
|
---|
[765f16] | 259 | parser->load(&input);
|
---|
[aa8ef2] | 260 |
|
---|
| 261 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 262 | }
|
---|
| 263 |
|
---|
[9e4fd1] | 264 | void ParserMpqcUnitTest::writeMpqcTest() {
|
---|
| 265 | // build up water molecule
|
---|
[f31edc] | 266 | string first;
|
---|
| 267 | string second;
|
---|
[9e4fd1] | 268 | atom *Walker = NULL;
|
---|
| 269 | Walker = World::getInstance().createAtom();
|
---|
| 270 | Walker->setType(8);
|
---|
| 271 | Walker->setPosition(Vector(0,0,0));
|
---|
| 272 | Walker = World::getInstance().createAtom();
|
---|
| 273 | Walker->setType(1);
|
---|
| 274 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
| 275 | Walker = World::getInstance().createAtom();
|
---|
| 276 | Walker->setType(1);
|
---|
| 277 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
| 278 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 279 |
|
---|
| 280 | // create two stringstreams, one stored, one created
|
---|
[f31edc] | 281 |
|
---|
[9e4fd1] | 282 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
[f31edc] | 283 | {
|
---|
| 284 | // compare both configs for CLHF
|
---|
| 285 | stringstream output;
|
---|
[ee50c1] | 286 | parser->getParams().setParameter(
|
---|
| 287 | MpqcParser_Parameters::theoryParam,
|
---|
| 288 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
|
---|
| 289 | );
|
---|
[765f16] | 290 | parser->save(&output, atoms);
|
---|
[f31edc] | 291 | stringstream input(waterMpqc_CLHF);
|
---|
[120a86] | 292 | // check for non-empty streams
|
---|
| 293 | input.peek();
|
---|
| 294 | output.peek();
|
---|
| 295 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
| 296 | // check equality of streams per line (for debugging)
|
---|
[f31edc] | 297 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 298 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 299 | CPPUNIT_ASSERT(first == second);
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | {
|
---|
| 303 | // compare both configs for CLKS
|
---|
| 304 | stringstream output;
|
---|
[ee50c1] | 305 | parser->getParams().setParameter(
|
---|
| 306 | MpqcParser_Parameters::theoryParam,
|
---|
| 307 | parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
|
---|
| 308 | );
|
---|
[120a86] | 309 | parser->save(&output, atoms);
|
---|
[f31edc] | 310 | stringstream input(waterMpqc_CLKS);
|
---|
[120a86] | 311 | // check for non-empty streams
|
---|
| 312 | input.peek();
|
---|
| 313 | output.peek();
|
---|
| 314 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
| 315 | // check equality of streams per line (for debugging)
|
---|
[f31edc] | 316 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 317 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 318 | CPPUNIT_ASSERT(first == second);
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 | {
|
---|
| 322 | // compare both configs for MBPT2
|
---|
| 323 | stringstream output;
|
---|
[ee50c1] | 324 | parser->getParams().setParameter(
|
---|
| 325 | MpqcParser_Parameters::theoryParam,
|
---|
| 326 | parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
|
---|
| 327 | );
|
---|
[120a86] | 328 | parser->save(&output, atoms);
|
---|
[f31edc] | 329 | stringstream input(waterMpqc_MBPT2);
|
---|
[120a86] | 330 | // check for non-empty streams
|
---|
| 331 | input.peek();
|
---|
| 332 | output.peek();
|
---|
| 333 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
| 334 | // check equality of streams per line (for debugging)
|
---|
[f31edc] | 335 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 336 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 337 | CPPUNIT_ASSERT(first == second);
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
| 340 | {
|
---|
| 341 | // compare both configs for MBPT2_R12
|
---|
| 342 | stringstream output;
|
---|
[ee50c1] | 343 | parser->getParams().setParameter(
|
---|
| 344 | MpqcParser_Parameters::theoryParam,
|
---|
| 345 | parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
|
---|
| 346 | );
|
---|
[120a86] | 347 | parser->save(&output, atoms);
|
---|
[f31edc] | 348 | stringstream input(waterMpqc_MBPT2_R12);
|
---|
[120a86] | 349 | // check for non-empty streams
|
---|
| 350 | input.peek();
|
---|
| 351 | output.peek();
|
---|
| 352 | CPPUNIT_ASSERT(input.good() && output.good());
|
---|
| 353 | // check equality of streams per line (for debugging)
|
---|
[f31edc] | 354 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 355 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 356 | CPPUNIT_ASSERT(first == second);
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
[9e4fd1] | 359 | }
|
---|