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_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\
|
---|
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\
|
---|
95 | \t\t\tmaxiter = 1000\n\
|
---|
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\
|
---|
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)
|
---|
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 |
|
---|
169 | void ParserMpqcUnitTest::writeMpqcTest() {
|
---|
170 | // build up water molecule
|
---|
171 | string first;
|
---|
172 | string second;
|
---|
173 | atom *Walker = NULL;
|
---|
174 | Walker = World::getInstance().createAtom();
|
---|
175 | Walker->setType(8);
|
---|
176 | Walker->setPosition(Vector(0,0,0));
|
---|
177 | Walker = World::getInstance().createAtom();
|
---|
178 | Walker->setType(1);
|
---|
179 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
180 | Walker = World::getInstance().createAtom();
|
---|
181 | Walker->setType(1);
|
---|
182 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
183 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
184 |
|
---|
185 | // create two stringstreams, one stored, one created
|
---|
186 |
|
---|
187 | MpqcParser* testParser = new MpqcParser();
|
---|
188 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
189 | {
|
---|
190 | // compare both configs for CLHF
|
---|
191 | stringstream output;
|
---|
192 | testParser->setTheory(MpqcParser::CLHF);
|
---|
193 | testParser->save(&output, atoms);
|
---|
194 | stringstream input(waterMpqc_CLHF);
|
---|
195 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
196 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
197 | CPPUNIT_ASSERT(first == second);
|
---|
198 | }
|
---|
199 | }
|
---|
200 | {
|
---|
201 | // compare both configs for CLKS
|
---|
202 | stringstream output;
|
---|
203 | testParser->setTheory(MpqcParser::CLKS);
|
---|
204 | testParser->save(&output, atoms);
|
---|
205 | stringstream input(waterMpqc_CLKS);
|
---|
206 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
207 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
208 | CPPUNIT_ASSERT(first == second);
|
---|
209 | }
|
---|
210 | }
|
---|
211 | {
|
---|
212 | // compare both configs for MBPT2
|
---|
213 | stringstream output;
|
---|
214 | testParser->setTheory(MpqcParser::MBPT2);
|
---|
215 | testParser->save(&output, atoms);
|
---|
216 | stringstream input(waterMpqc_MBPT2);
|
---|
217 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
218 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
219 | CPPUNIT_ASSERT(first == second);
|
---|
220 | }
|
---|
221 | }
|
---|
222 | {
|
---|
223 | // compare both configs for MBPT2_R12
|
---|
224 | stringstream output;
|
---|
225 | testParser->setTheory(MpqcParser::MBPT2_R12);
|
---|
226 | testParser->save(&output, atoms);
|
---|
227 | stringstream input(waterMpqc_MBPT2_R12);
|
---|
228 | for (; std::getline(input, first) && std::getline(output, second); ) {
|
---|
229 | //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
|
---|
230 | CPPUNIT_ASSERT(first == second);
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|