source: src/Parser/unittests/ParserPsi3UnitTest.cpp@ 7d1b6a

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 7d1b6a was 006e1e, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: ChangeTracker has not been observing AtomObserver so far.

  • This is introduced due to cleaning of observer structure.
  • FIX: Cleaned ChangeTracker declaration from false includes.
  • FIX: TextWindow.cpp lacked include World.
  • TESTFIX: All Parser...UnitTest needed to purge AtomObserver instance.
  • Property mode set to 100644
File size: 14.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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 "Atom/atom.hpp"
29#include "Atom/AtomObserver.hpp"
30#include "Element/element.hpp"
31#include "Element/periodentafel.hpp"
32#include "CodePatterns/Assert.hpp"
33#include "Descriptors/AtomTypeDescriptor.hpp"
34#include "Parser/ChangeTracker.hpp"
35#include "Parser/Psi3Parser.hpp"
36#include "World.hpp"
37
38#ifdef HAVE_TESTRUNNER
39#include "UnitTestMain.hpp"
40#endif /*HAVE_TESTRUNNER*/
41
42using namespace std;
43
44// Registers the fixture into the 'registry'
45CPPUNIT_TEST_SUITE_REGISTRATION( ParserPsi3UnitTest );
46
47static string hydrogenPsi3_RHF ="% Created by MoleCuilder\n\
48psi: (\n\
49\tlabel = \"cc-pVTZ SCF H2\"\n\
50\tjobtype = sp\n\
51\twfn = scf\n\
52\tmaxiter = 80\n\
53\treference = rhf\n\
54\tbasis = \"cc-pVTZ\"\n\
55\tfreeze_core = no\n\
56\tunits = angstrom\n\
57\tgeometry = (\n\
58\t( H\t0\t0\t-0.37 )\n\
59\t( H\t0\t0\t0.37 )\n\
60\t)\n\
61\torigin = (0.0\t0.0\t0.0)\n\
62)\n"; // tested with ???
63
64static string hydrogenPsi3_ROHF ="% Created by MoleCuilder\n\
65psi: (\n\
66\tlabel = \"cc-pVTZ SCF H2\"\n\
67\tjobtype = sp\n\
68\twfn = scf\n\
69\tmaxiter = 80\n\
70\treference = rohf\n\
71\tbasis = \"cc-pVTZ\"\n\
72\tfreeze_core = no\n\
73\tunits = angstrom\n\
74\tgeometry = (\n\
75\t( H\t0\t0\t-0.37 )\n\
76\t( H\t0\t0\t0.37 )\n\
77\t)\n\
78\torigin = (0.0\t0.0\t0.0)\n\
79)\n"; // tested with ???
80
81static string hydrogenPsi3_UHF ="% Created by MoleCuilder\n\
82psi: (\n\
83\tlabel = \"cc-pVTZ SCF H2\"\n\
84\tjobtype = sp\n\
85\twfn = scf\n\
86\tmaxiter = 80\n\
87\treference = uhf\n\
88\tbasis = \"cc-pVTZ\"\n\
89\tmultp = 2\n\
90\tcharge = 2\n\
91\tfreeze_core = no\n\
92\tunits = angstrom\n\
93\tgeometry = (\n\
94\t( H\t0\t0\t-0.37 )\n\
95\t( H\t0\t0\t0.37 )\n\
96\t)\n\
97\torigin = (0.0\t0.0\t0.0)\n\
98)\n"; // tested with ???
99
100static string hydrogenPsi3_TWOCON ="% Created by MoleCuilder\n\
101psi: (\n\
102\tlabel = \"cc-pVTZ SCF H2\"\n\
103\tjobtype = sp\n\
104\twfn = scf\n\
105\tmaxiter = 80\n\
106\treference = twocon\n\
107\tbasis = \"cc-pVTZ\"\n\
108\tmultp = 1\n\
109\tcharge = 2\n\
110\tsocc = ( 1 1 0 0 0 0 0 0 )\n\
111\tdocc = ( 0 0 0 0 0 0 0 0 )\n\
112\tsubgroup = c2v\n\
113\tunique_axis = x\n\
114\tfreeze_core = no\n\
115\tunits = angstrom\n\
116\tgeometry = (\n\
117\t( H\t0\t0\t-0.37 )\n\
118\t( H\t0\t0\t0.37 )\n\
119\t)\n\
120\torigin = (0.0\t0.0\t0.0)\n\
121)\n"; // tested with ???
122
123void ParserPsi3UnitTest::setUp()
124{
125 // failing asserts should be thrown
126 ASSERT_DO(Assert::Throw);
127
128 parser = new FormatParser<psi3>();
129
130 params = &parser->getParams();
131
132 World::getInstance();
133
134 setVerbosity(2);
135
136 // we need hydrogens and oxygens in the following tests
137 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
138}
139
140void ParserPsi3UnitTest::tearDown()
141{
142 params = NULL;
143 delete parser;
144 ChangeTracker::purgeInstance();
145 AtomObserver::purgeInstance();
146 World::purgeInstance();
147}
148
149/************************************ tests ***********************************/
150
151void ParserPsi3UnitTest::ParameterDefaultTest() {
152 // check default values
153 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::labelParam) == std::string("unknown job"));
154 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
155 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::SCF]);
156 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("80"));
157 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::RHF]);
158 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::basisParam) == std::string("cc-pVTZ"));
159 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::YES]);
160 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::angstrom]);
161 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
162 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::originParam) == std::string("(0.0\t0.0\t0.0)"));
163 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::multiplicityParam) == std::string("1"));
164 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::chargeParam) == std::string("0"));
165 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::soccParam) == std::string("()"));
166 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::doccParam) == std::string("()"));
167 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::subgroupParam) == std::string(""));
168 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::X]);
169}
170
171void ParserPsi3UnitTest::ParameterCloneTest() {
172 FormatParser_Parameters *clone = params->clone();
173 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
174 std::stringstream setvalue(params->ParamNames[Psi3Parser_Parameters::jobtypeParam]+"="+params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
175 setvalue >> *params;
176 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
177 params->makeClone(*clone);
178 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
179}
180
181void ParserPsi3UnitTest::ParameterSetterTest() {
182 // test a jobtype
183 {
184 std::stringstream setvalue(
185 params->ParamNames[Psi3Parser_Parameters::jobtypeParam]
186 +" = "+params->ValidJobtypes[Psi3Parser_Parameters::OPT]
187 );
188 setvalue >> *params;
189 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
190 }
191 // test a wavefunction
192 {
193 std::stringstream setvalue(
194 params->ParamNames[Psi3Parser_Parameters::wavefunctionParam]
195 +" = "+params->ValidWavefunction[Psi3Parser_Parameters::MP2]
196 );
197 setvalue >> *params;
198 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::MP2]);
199 }
200 // test a reference
201 {
202 std::stringstream setvalue(
203 params->ParamNames[Psi3Parser_Parameters::referenceParam]
204 +" = "+params->ValidReference[Psi3Parser_Parameters::ROHF]
205 );
206 setvalue >> *params;
207 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::ROHF]);
208 }
209 // test a unique_axis
210 {
211 std::stringstream setvalue(
212 params->ParamNames[Psi3Parser_Parameters::unique_axisParam]
213 +" = "+params->ValidUniqueAxis[Psi3Parser_Parameters::Y]
214 );
215 setvalue >> *params;
216 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::Y]);
217 }
218 // test a units
219 {
220 std::stringstream setvalue(
221 params->ParamNames[Psi3Parser_Parameters::unitsParam]
222 +" = "+params->ValidUnits[Psi3Parser_Parameters::bohr]
223 );
224 setvalue >> *params;
225 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::bohr]);
226 }
227 // test a dertype
228 {
229 std::stringstream setvalue(
230 params->ParamNames[Psi3Parser_Parameters::dertypeParam]
231 +" = "+params->ValidDerivativeType[Psi3Parser_Parameters::NONE]
232 );
233 setvalue >> *params;
234 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
235 }
236 // test a freeze_core
237 {
238 std::stringstream setvalue(
239 params->ParamNames[Psi3Parser_Parameters::freeze_coreParam]
240 +" = "+params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]
241 );
242 setvalue >> *params;
243 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]);
244 }
245 // test int
246 {
247 std::stringstream setvalue(
248 params->ParamNames[Psi3Parser_Parameters::maxiterParam]
249 +" = 500"
250 );
251 setvalue >> *params;
252// std::cout << "maxiter is "
253// << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
254 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("500"));
255 }
256 // test whether unknown key fails
257 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
258 {
259 std::stringstream setvalue("sd = no");
260#ifndef NDEBUG
261 ASSERT_DO(Assert::Throw);
262 CPPUNIT_ASSERT_THROW(setvalue >> *params, Assert::AssertionFailure);
263#else
264 setvalue >> *params;
265#endif
266// std::cout << "Hessian is still "
267// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
268 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
269 }
270}
271
272void ParserPsi3UnitTest::readPsi3Test() {
273 stringstream input(hydrogenPsi3_RHF);
274 // set some other parameter for jobtype
275 params->setParameter(
276 Psi3Parser_Parameters::jobtypeParam,
277 params->ValidJobtypes[Psi3Parser_Parameters::OPT]
278 );
279 parser->load(&input);
280
281 // check for jobtype from file
282 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
283 // check for 2 hydrogens
284 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
285 // check that positions are right
286 Vector PositionSum;
287 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
288 for (std::vector<atom *>::const_iterator iter = atoms.begin();
289 iter != atoms.end();
290 ++iter)
291 PositionSum += (*iter)->getPosition();
292 CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0.,0.,0.) );
293}
294
295void ParserPsi3UnitTest::writePsi3Test() {
296 // build up hydrogen molecule
297 string first;
298 string second;
299 atom *Walker = NULL;
300 Walker = World::getInstance().createAtom();
301 Walker->setType(1);
302 Walker->setPosition(Vector(0.,0.,0.));
303 Walker = World::getInstance().createAtom();
304 Walker->setType(1);
305 Walker->setPosition(Vector(0.,0,0.74));
306 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
307
308 // set general parameters: label and freeze_core
309 params->setParameter(
310 Psi3Parser_Parameters::labelParam,
311 "cc-pVTZ SCF H2"
312 );
313 params->setParameter(
314 Psi3Parser_Parameters::freeze_coreParam,
315 params->ValidFreezeCore[Psi3Parser_Parameters::NO]
316 );
317 params->setParameter(
318 Psi3Parser_Parameters::unitsParam,
319 params->ValidUnits[Psi3Parser_Parameters::angstrom]
320 );
321
322 // create two stringstreams, one stored, one created
323 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
324 {
325 // compare both configs for RHF
326 stringstream output;
327 params->setParameter(
328 Psi3Parser_Parameters::referenceParam,
329 params->ValidReference[Psi3Parser_Parameters::RHF]
330 );
331 parser->save(&output, atoms);
332 stringstream input(hydrogenPsi3_RHF);
333 // check for non-empty streams
334 input.peek();
335 output.peek();
336 CPPUNIT_ASSERT(input.good() && output.good());
337 // check equality of streams per line (for debugging)
338 for (; std::getline(input, first) && std::getline(output, second); ) {
339 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
340 CPPUNIT_ASSERT(first == second);
341 }
342 }
343 {
344 // compare both configs for ROHF
345 stringstream output;
346 params->setParameter(
347 Psi3Parser_Parameters::referenceParam,
348 params->ValidReference[Psi3Parser_Parameters::ROHF]
349 );
350 parser->save(&output, atoms);
351 stringstream input(hydrogenPsi3_ROHF);
352 // check for non-empty streams
353 input.peek();
354 output.peek();
355 CPPUNIT_ASSERT(input.good() && output.good());
356 // check equality of streams per line (for debugging)
357 for (; std::getline(input, first) && std::getline(output, second); ) {
358 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
359 CPPUNIT_ASSERT(first == second);
360 }
361 }
362 {
363 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "2");
364 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
365 // compare both configs for UHF
366 stringstream output;
367 params->setParameter(
368 Psi3Parser_Parameters::referenceParam,
369 params->ValidReference[Psi3Parser_Parameters::UHF]
370 );
371 parser->save(&output, atoms);
372 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
373 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
374 stringstream input(hydrogenPsi3_UHF);
375 // check for non-empty streams
376 input.peek();
377 output.peek();
378 CPPUNIT_ASSERT(input.good() && output.good());
379 // check equality of streams per line (for debugging)
380 for (; std::getline(input, first) && std::getline(output, second); ) {
381 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
382 CPPUNIT_ASSERT(first == second);
383 }
384 }
385 {
386 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
387 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
388 params->setParameter(Psi3Parser_Parameters::soccParam, "( 1 1 0 0 0 0 0 0 )");
389 params->setParameter(Psi3Parser_Parameters::doccParam, "( 0 0 0 0 0 0 0 0 )");
390 params->setParameter(Psi3Parser_Parameters::subgroupParam, "c2v");
391 params->setParameter(Psi3Parser_Parameters::unique_axisParam, "x");
392 // compare both configs for TWOCON
393 stringstream output;
394 params->setParameter(
395 Psi3Parser_Parameters::referenceParam,
396 params->ValidReference[Psi3Parser_Parameters::TWOCON]
397 );
398 parser->save(&output, atoms);
399 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
400 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
401 stringstream input(hydrogenPsi3_TWOCON);
402 // check for non-empty streams
403 input.peek();
404 output.peek();
405 CPPUNIT_ASSERT(input.good() && output.good());
406 // check equality of streams per line (for debugging)
407 for (; std::getline(input, first) && std::getline(output, second); ) {
408 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
409 CPPUNIT_ASSERT(first == second);
410 }
411 }
412}
Note: See TracBrowser for help on using the repository browser.