[9e4fd1] | 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 "Parser/MpqcParser.hpp"
|
---|
| 27 | #include "World.hpp"
|
---|
| 28 | #include "atom.hpp"
|
---|
| 29 | #include "element.hpp"
|
---|
| 30 | #include "periodentafel.hpp"
|
---|
| 31 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
| 32 |
|
---|
| 33 | #ifdef HAVE_TESTRUNNER
|
---|
| 34 | #include "UnitTestMain.hpp"
|
---|
| 35 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 36 |
|
---|
| 37 | using namespace std;
|
---|
| 38 |
|
---|
| 39 | // Registers the fixture into the 'registry'
|
---|
| 40 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
|
---|
| 41 |
|
---|
[f31edc] | 42 | static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
|
---|
| 43 | mpqc: (\n\
|
---|
| 44 | \tsavestate = no\n\
|
---|
| 45 | \tdo_gradient = yes\n\
|
---|
| 46 | \tmole<CLHF>: (\n\
|
---|
| 47 | \t\tmolecule = $:molecule\n\
|
---|
| 48 | \t\tbasis = $:basis\n\
|
---|
| 49 | \t\tmemory = 16000000\n\
|
---|
| 50 | \t)\n\
|
---|
| 51 | )\n\
|
---|
| 52 | molecule<Molecule>: (\n\
|
---|
| 53 | \tunit = angstrom\n\
|
---|
| 54 | \t{ atoms geometry } = {\n\
|
---|
| 55 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 56 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 57 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 58 | \t}\n\
|
---|
| 59 | )\n\
|
---|
| 60 | basis<GaussianBasisSet>: (\n\
|
---|
| 61 | \tname = \"3-21G\"\n\
|
---|
| 62 | \tmolecule = $:molecule\n\
|
---|
| 63 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 64 | static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
|
---|
| 65 | mpqc: (\n\
|
---|
| 66 | \tsavestate = no\n\
|
---|
| 67 | \tdo_gradient = yes\n\
|
---|
| 68 | \tmole<CLKS>: (\n\
|
---|
| 69 | \t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
|
---|
| 70 | \t\tmolecule = $:molecule\n\
|
---|
| 71 | \t\tbasis = $:basis\n\
|
---|
| 72 | \t\tmemory = 16000000\n\
|
---|
| 73 | \t)\n\
|
---|
| 74 | )\n\
|
---|
| 75 | molecule<Molecule>: (\n\
|
---|
| 76 | \tunit = angstrom\n\
|
---|
| 77 | \t{ atoms geometry } = {\n\
|
---|
| 78 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 79 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 80 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 81 | \t}\n\
|
---|
| 82 | )\n\
|
---|
| 83 | basis<GaussianBasisSet>: (\n\
|
---|
| 84 | \tname = \"3-21G\"\n\
|
---|
| 85 | \tmolecule = $:molecule\n\
|
---|
| 86 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 87 | static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
|
---|
[9e4fd1] | 88 | mpqc: (\n\
|
---|
| 89 | \tsavestate = no\n\
|
---|
| 90 | \tdo_gradient = yes\n\
|
---|
| 91 | \tmole<MBPT2>: (\n\
|
---|
| 92 | \t\tbasis = $:basis\n\
|
---|
| 93 | \t\tmolecule = $:molecule\n\
|
---|
| 94 | \t\treference<CLHF>: (\n\
|
---|
[bb74ba] | 95 | \t\t\tmaxiter = 1000\n\
|
---|
[9e4fd1] | 96 | \t\t\tbasis = $:basis\n\
|
---|
| 97 | \t\t\tmolecule = $:molecule\n\
|
---|
| 98 | \t\t)\n\
|
---|
| 99 | \t)\n\
|
---|
| 100 | )\n\
|
---|
| 101 | molecule<Molecule>: (\n\
|
---|
| 102 | \tunit = angstrom\n\
|
---|
| 103 | \t{ atoms geometry } = {\n\
|
---|
| 104 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 105 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 106 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 107 | \t}\n\
|
---|
| 108 | )\n\
|
---|
| 109 | basis<GaussianBasisSet>: (\n\
|
---|
| 110 | \tname = \"3-21G\"\n\
|
---|
| 111 | \tmolecule = $:molecule\n\
|
---|
[f31edc] | 112 | )\n"; // tested with mpqc 3.0.0-alpha
|
---|
| 113 | static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
|
---|
| 114 | mpqc: (\n\
|
---|
| 115 | \tsavestate = no\n\
|
---|
| 116 | \tdo_gradient = yes\n\
|
---|
| 117 | \tmole<MBPT2_R12>: (\n\
|
---|
| 118 | \t\tmolecule = $:molecule\n\
|
---|
| 119 | \t\tbasis = $:basis\n\
|
---|
| 120 | \t\taux_basis = $:abasis\n\
|
---|
| 121 | \t\tstdapprox = \"A'\"\n\
|
---|
| 122 | \t\tnfzc = 1\n\
|
---|
| 123 | \t\tmemory = 16000000\n\
|
---|
| 124 | \t\tintegrals<IntegralCints>:()\n\
|
---|
| 125 | \t\treference<CLHF>: (\n\
|
---|
| 126 | \t\t\tmolecule = $:molecule\n\
|
---|
| 127 | \t\t\tbasis = $:basis\n\
|
---|
| 128 | \t\t\tmaxiter = 1000\n\
|
---|
| 129 | \t\t\tmemory = 16000000\n\
|
---|
| 130 | \t\t\tintegrals<IntegralCints>:()\n\
|
---|
| 131 | \t\t)\n\
|
---|
| 132 | \t)\n\
|
---|
| 133 | )\n\
|
---|
| 134 | molecule<Molecule>: (\n\
|
---|
| 135 | \tunit = angstrom\n\
|
---|
| 136 | \t{ atoms geometry } = {\n\
|
---|
| 137 | \t\tO [ -0.505735\t0\t0 ]\n\
|
---|
| 138 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
---|
| 139 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
---|
| 140 | \t}\n\
|
---|
| 141 | )\n\
|
---|
| 142 | basis<GaussianBasisSet>: (\n\
|
---|
| 143 | \tname = \"3-21G\"\n\
|
---|
| 144 | \tmolecule = $:molecule\n\
|
---|
| 145 | )\n\
|
---|
| 146 | % auxiliary basis set specification\n\
|
---|
| 147 | \tabasis<GaussianBasisSet>: (\n\
|
---|
| 148 | \tname = \"aug-cc-pVDZ\"\n\
|
---|
| 149 | \tmolecule = $:molecule\n\
|
---|
| 150 | )\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
|
---|
[9e4fd1] | 151 |
|
---|
| 152 | void ParserMpqcUnitTest::setUp() {
|
---|
| 153 | World::getInstance();
|
---|
| 154 |
|
---|
| 155 | setVerbosity(2);
|
---|
| 156 |
|
---|
| 157 | // we need hydrogens and oxygens in the following tests
|
---|
| 158 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
| 159 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | void ParserMpqcUnitTest::tearDown() {
|
---|
| 163 | ChangeTracker::purgeInstance();
|
---|
| 164 | World::purgeInstance();
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | /************************************ tests ***********************************/
|
---|
| 168 |
|
---|
[aa8ef2] | 169 | void ParserMpqcUnitTest::readMpqcTest() {
|
---|
| 170 | stringstream input(waterMpqc_CLHF);
|
---|
| 171 | MpqcParser* testParser = new MpqcParser();
|
---|
| 172 | testParser->setTheory(MpqcParser::CLHF);
|
---|
| 173 | testParser->load(&input);
|
---|
| 174 |
|
---|
| 175 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[9e4fd1] | 178 | void ParserMpqcUnitTest::writeMpqcTest() {
|
---|
| 179 | // build up water molecule
|
---|
[f31edc] | 180 | string first;
|
---|
| 181 | string second;
|
---|
[9e4fd1] | 182 | atom *Walker = NULL;
|
---|
| 183 | Walker = World::getInstance().createAtom();
|
---|
| 184 | Walker->setType(8);
|
---|
| 185 | Walker->setPosition(Vector(0,0,0));
|
---|
| 186 | Walker = World::getInstance().createAtom();
|
---|
| 187 | Walker->setType(1);
|
---|
| 188 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
| 189 | Walker = World::getInstance().createAtom();
|
---|
| 190 | Walker->setType(1);
|
---|
| 191 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
| 192 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 193 |
|
---|
| 194 | // create two stringstreams, one stored, one created
|
---|
[f31edc] | 195 |
|
---|
[9e4fd1] | 196 | MpqcParser* testParser = new MpqcParser();
|
---|
| 197 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
[f31edc] | 198 | {
|
---|
| 199 | // compare both configs for CLHF
|
---|
| 200 | stringstream output;
|
---|
| 201 | testParser->setTheory(MpqcParser::CLHF);
|
---|
| 202 | testParser->save(&output, atoms);
|
---|
| 203 | stringstream input(waterMpqc_CLHF);
|
---|
| 204 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 205 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 206 | CPPUNIT_ASSERT(first == second);
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | {
|
---|
| 210 | // compare both configs for CLKS
|
---|
| 211 | stringstream output;
|
---|
| 212 | testParser->setTheory(MpqcParser::CLKS);
|
---|
| 213 | testParser->save(&output, atoms);
|
---|
| 214 | stringstream input(waterMpqc_CLKS);
|
---|
| 215 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 216 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 217 | CPPUNIT_ASSERT(first == second);
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | {
|
---|
| 221 | // compare both configs for MBPT2
|
---|
| 222 | stringstream output;
|
---|
| 223 | testParser->setTheory(MpqcParser::MBPT2);
|
---|
| 224 | testParser->save(&output, atoms);
|
---|
| 225 | stringstream input(waterMpqc_MBPT2);
|
---|
| 226 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 227 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 228 | CPPUNIT_ASSERT(first == second);
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 | {
|
---|
| 232 | // compare both configs for MBPT2_R12
|
---|
| 233 | stringstream output;
|
---|
| 234 | testParser->setTheory(MpqcParser::MBPT2_R12);
|
---|
| 235 | testParser->save(&output, atoms);
|
---|
| 236 | stringstream input(waterMpqc_MBPT2_R12);
|
---|
| 237 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
| 238 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
| 239 | CPPUNIT_ASSERT(first == second);
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
[9e4fd1] | 242 | }
|
---|