source: src/Parser/unittests/ParserPsi3UnitTest.cpp@ 6f0841

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 6f0841 was 6f0841, checked in by Frederik Heber <heber@…>, 13 years ago

Shifted all modules related to atoms into own subfolder src/Atom/

  • also created own convenience library for this. This makes unit testing on list containing TesselPoint or atom a lot easier.
  • shifted TesselPoint to src/Atom from src/Tesselation and adapted include's.
  • 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-2011 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 "CodePatterns/Assert.hpp"
29
30#include "Atom/atom.hpp"
31#include "Descriptors/AtomTypeDescriptor.hpp"
32#include "Element/element.hpp"
33#include "Element/periodentafel.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 World::purgeInstance();
146}
147
148/************************************ tests ***********************************/
149
150void ParserPsi3UnitTest::ParameterDefaultTest() {
151 // check default values
152 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::labelParam) == std::string("unknown job"));
153 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
154 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::SCF]);
155 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("80"));
156 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::RHF]);
157 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::basisParam) == std::string("cc-pVTZ"));
158 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::YES]);
159 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::angstrom]);
160 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
161 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::originParam) == std::string("(0.0\t0.0\t0.0)"));
162 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::multiplicityParam) == std::string("1"));
163 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::chargeParam) == std::string("0"));
164 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::soccParam) == std::string("()"));
165 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::doccParam) == std::string("()"));
166 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::subgroupParam) == std::string(""));
167 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::X]);
168}
169
170void ParserPsi3UnitTest::ParameterCloneTest() {
171 FormatParser_Parameters *clone = params->clone();
172 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
173 std::stringstream setvalue(params->ParamNames[Psi3Parser_Parameters::jobtypeParam]+"="+params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
174 setvalue >> *params;
175 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
176 params->makeClone(*clone);
177 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
178}
179
180void ParserPsi3UnitTest::ParameterSetterTest() {
181 // test a jobtype
182 {
183 std::stringstream setvalue(
184 params->ParamNames[Psi3Parser_Parameters::jobtypeParam]
185 +" = "+params->ValidJobtypes[Psi3Parser_Parameters::OPT]
186 );
187 setvalue >> *params;
188 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
189 }
190 // test a wavefunction
191 {
192 std::stringstream setvalue(
193 params->ParamNames[Psi3Parser_Parameters::wavefunctionParam]
194 +" = "+params->ValidWavefunction[Psi3Parser_Parameters::MP2]
195 );
196 setvalue >> *params;
197 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::MP2]);
198 }
199 // test a reference
200 {
201 std::stringstream setvalue(
202 params->ParamNames[Psi3Parser_Parameters::referenceParam]
203 +" = "+params->ValidReference[Psi3Parser_Parameters::ROHF]
204 );
205 setvalue >> *params;
206 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::ROHF]);
207 }
208 // test a unique_axis
209 {
210 std::stringstream setvalue(
211 params->ParamNames[Psi3Parser_Parameters::unique_axisParam]
212 +" = "+params->ValidUniqueAxis[Psi3Parser_Parameters::Y]
213 );
214 setvalue >> *params;
215 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::Y]);
216 }
217 // test a units
218 {
219 std::stringstream setvalue(
220 params->ParamNames[Psi3Parser_Parameters::unitsParam]
221 +" = "+params->ValidUnits[Psi3Parser_Parameters::bohr]
222 );
223 setvalue >> *params;
224 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::bohr]);
225 }
226 // test a dertype
227 {
228 std::stringstream setvalue(
229 params->ParamNames[Psi3Parser_Parameters::dertypeParam]
230 +" = "+params->ValidDerivativeType[Psi3Parser_Parameters::NONE]
231 );
232 setvalue >> *params;
233 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
234 }
235 // test a freeze_core
236 {
237 std::stringstream setvalue(
238 params->ParamNames[Psi3Parser_Parameters::freeze_coreParam]
239 +" = "+params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]
240 );
241 setvalue >> *params;
242 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]);
243 }
244 // test int
245 {
246 std::stringstream setvalue(
247 params->ParamNames[Psi3Parser_Parameters::maxiterParam]
248 +" = 500"
249 );
250 setvalue >> *params;
251// std::cout << "maxiter is "
252// << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
253 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("500"));
254 }
255 // test whether unknown key fails
256 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
257 {
258 std::stringstream setvalue("sd = no");
259#ifndef NDEBUG
260 ASSERT_DO(Assert::Throw);
261 CPPUNIT_ASSERT_THROW(setvalue >> *params, Assert::AssertionFailure);
262#else
263 setvalue >> *params;
264#endif
265// std::cout << "Hessian is still "
266// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
267 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
268 }
269}
270
271void ParserPsi3UnitTest::readPsi3Test() {
272 stringstream input(hydrogenPsi3_RHF);
273 // set some other parameter for jobtype
274 params->setParameter(
275 Psi3Parser_Parameters::jobtypeParam,
276 params->ValidJobtypes[Psi3Parser_Parameters::OPT]
277 );
278 parser->load(&input);
279
280 // check for jobtype from file
281 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
282 // check for 2 hydrogens
283 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
284 // check that positions are right
285 Vector PositionSum;
286 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
287 for (std::vector<atom *>::const_iterator iter = atoms.begin();
288 iter != atoms.end();
289 ++iter)
290 PositionSum += (*iter)->getPosition();
291 CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0.,0.,0.) );
292}
293
294void ParserPsi3UnitTest::writePsi3Test() {
295 // build up hydrogen molecule
296 string first;
297 string second;
298 atom *Walker = NULL;
299 Walker = World::getInstance().createAtom();
300 Walker->setType(1);
301 Walker->setPosition(Vector(0.,0.,0.));
302 Walker = World::getInstance().createAtom();
303 Walker->setType(1);
304 Walker->setPosition(Vector(0.,0,0.74));
305 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
306
307 // set general parameters: label and freeze_core
308 params->setParameter(
309 Psi3Parser_Parameters::labelParam,
310 "cc-pVTZ SCF H2"
311 );
312 params->setParameter(
313 Psi3Parser_Parameters::freeze_coreParam,
314 params->ValidFreezeCore[Psi3Parser_Parameters::NO]
315 );
316 params->setParameter(
317 Psi3Parser_Parameters::unitsParam,
318 params->ValidUnits[Psi3Parser_Parameters::angstrom]
319 );
320
321 // create two stringstreams, one stored, one created
322 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
323 {
324 // compare both configs for RHF
325 stringstream output;
326 params->setParameter(
327 Psi3Parser_Parameters::referenceParam,
328 params->ValidReference[Psi3Parser_Parameters::RHF]
329 );
330 parser->save(&output, atoms);
331 stringstream input(hydrogenPsi3_RHF);
332 // check for non-empty streams
333 input.peek();
334 output.peek();
335 CPPUNIT_ASSERT(input.good() && output.good());
336 // check equality of streams per line (for debugging)
337 for (; std::getline(input, first) && std::getline(output, second); ) {
338 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
339 CPPUNIT_ASSERT(first == second);
340 }
341 }
342 {
343 // compare both configs for ROHF
344 stringstream output;
345 params->setParameter(
346 Psi3Parser_Parameters::referenceParam,
347 params->ValidReference[Psi3Parser_Parameters::ROHF]
348 );
349 parser->save(&output, atoms);
350 stringstream input(hydrogenPsi3_ROHF);
351 // check for non-empty streams
352 input.peek();
353 output.peek();
354 CPPUNIT_ASSERT(input.good() && output.good());
355 // check equality of streams per line (for debugging)
356 for (; std::getline(input, first) && std::getline(output, second); ) {
357 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
358 CPPUNIT_ASSERT(first == second);
359 }
360 }
361 {
362 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "2");
363 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
364 // compare both configs for UHF
365 stringstream output;
366 params->setParameter(
367 Psi3Parser_Parameters::referenceParam,
368 params->ValidReference[Psi3Parser_Parameters::UHF]
369 );
370 parser->save(&output, atoms);
371 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
372 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
373 stringstream input(hydrogenPsi3_UHF);
374 // check for non-empty streams
375 input.peek();
376 output.peek();
377 CPPUNIT_ASSERT(input.good() && output.good());
378 // check equality of streams per line (for debugging)
379 for (; std::getline(input, first) && std::getline(output, second); ) {
380 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
381 CPPUNIT_ASSERT(first == second);
382 }
383 }
384 {
385 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
386 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
387 params->setParameter(Psi3Parser_Parameters::soccParam, "( 1 1 0 0 0 0 0 0 )");
388 params->setParameter(Psi3Parser_Parameters::doccParam, "( 0 0 0 0 0 0 0 0 )");
389 params->setParameter(Psi3Parser_Parameters::subgroupParam, "c2v");
390 params->setParameter(Psi3Parser_Parameters::unique_axisParam, "x");
391 // compare both configs for TWOCON
392 stringstream output;
393 params->setParameter(
394 Psi3Parser_Parameters::referenceParam,
395 params->ValidReference[Psi3Parser_Parameters::TWOCON]
396 );
397 parser->save(&output, atoms);
398 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
399 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
400 stringstream input(hydrogenPsi3_TWOCON);
401 // check for non-empty streams
402 input.peek();
403 output.peek();
404 CPPUNIT_ASSERT(input.good() && output.good());
405 // check equality of streams per line (for debugging)
406 for (; std::getline(input, first) && std::getline(output, second); ) {
407 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
408 CPPUNIT_ASSERT(first == second);
409 }
410 }
411}
Note: See TracBrowser for help on using the repository browser.