| 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 |
|
|---|
| 42 | static string waterMpqc ="% Created by MoleCuilder\n\
|
|---|
| 43 | mpqc: (\n\
|
|---|
| 44 | \tsavestate = no\n\
|
|---|
| 45 | \tdo_gradient = yes\n\
|
|---|
| 46 | \tmole<MBPT2>: (\n\
|
|---|
| 47 | \t\tbasis = $:basis\n\
|
|---|
| 48 | \t\tmolecule = $:molecule\n\
|
|---|
| 49 | \t\treference<CLHF>: (\n\
|
|---|
| 50 | \t\t\tmaxiter = 1000\n\
|
|---|
| 51 | \t\t\tbasis = $:basis\n\
|
|---|
| 52 | \t\t\tmolecule = $:molecule\n\
|
|---|
| 53 | \t\t)\n\
|
|---|
| 54 | \t)\n\
|
|---|
| 55 | )\n\
|
|---|
| 56 | molecule<Molecule>: (\n\
|
|---|
| 57 | \tunit = angstrom\n\
|
|---|
| 58 | \t{ atoms geometry } = {\n\
|
|---|
| 59 | \t\tO [ -0.505735\t0\t0 ]\n\
|
|---|
| 60 | \t\tH [ 0.252867\t0\t0.504284 ]\n\
|
|---|
| 61 | \t\tH [ 0.252867\t0\t-0.504284 ]\n\
|
|---|
| 62 | \t}\n\
|
|---|
| 63 | )\n\
|
|---|
| 64 | basis<GaussianBasisSet>: (\n\
|
|---|
| 65 | \tname = \"3-21G\"\n\
|
|---|
| 66 | \tmolecule = $:molecule\n\
|
|---|
| 67 | )\n";
|
|---|
| 68 |
|
|---|
| 69 | void ParserMpqcUnitTest::setUp() {
|
|---|
| 70 | World::getInstance();
|
|---|
| 71 |
|
|---|
| 72 | setVerbosity(2);
|
|---|
| 73 |
|
|---|
| 74 | // we need hydrogens and oxygens in the following tests
|
|---|
| 75 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
|---|
| 76 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void ParserMpqcUnitTest::tearDown() {
|
|---|
| 80 | ChangeTracker::purgeInstance();
|
|---|
| 81 | World::purgeInstance();
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /************************************ tests ***********************************/
|
|---|
| 85 |
|
|---|
| 86 | void ParserMpqcUnitTest::writeMpqcTest() {
|
|---|
| 87 | // build up water molecule
|
|---|
| 88 | atom *Walker = NULL;
|
|---|
| 89 | Walker = World::getInstance().createAtom();
|
|---|
| 90 | Walker->setType(8);
|
|---|
| 91 | Walker->setPosition(Vector(0,0,0));
|
|---|
| 92 | Walker = World::getInstance().createAtom();
|
|---|
| 93 | Walker->setType(1);
|
|---|
| 94 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
|---|
| 95 | Walker = World::getInstance().createAtom();
|
|---|
| 96 | Walker->setType(1);
|
|---|
| 97 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
|---|
| 98 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
|---|
| 99 |
|
|---|
| 100 | // create two stringstreams, one stored, one created
|
|---|
| 101 | stringstream input(waterMpqc);
|
|---|
| 102 | MpqcParser* testParser = new MpqcParser();
|
|---|
| 103 | stringstream output;
|
|---|
| 104 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
|---|
| 105 | testParser->save(&output, atoms);
|
|---|
| 106 |
|
|---|
| 107 | // compare both configs
|
|---|
| 108 | string first = input.str();
|
|---|
| 109 | string second = output.str();
|
|---|
| 110 | CPPUNIT_ASSERT(first == second);
|
|---|
| 111 | }
|
|---|