source: src/Parser/unittests/ParserPsi3UnitTest.cpp@ 154a45

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 154a45 was 154a45, checked in by Frederik Heber <heber@…>, 14 years ago

ParserPsi3UnitTest::ParameterCloneTest() is working.

  • Property mode set to 100644
File size: 10.5 KB
Line 
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 * 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 "World.hpp"
29#include "atom.hpp"
30#include "element.hpp"
31#include "periodentafel.hpp"
32#include "Descriptors/AtomTypeDescriptor.hpp"
33#include "CodePatterns/Assert.hpp"
34#include "Parser/ChangeTracker.hpp"
35#include "Parser/Psi3Parser.hpp"
36
37#ifdef HAVE_TESTRUNNER
38#include "UnitTestMain.hpp"
39#endif /*HAVE_TESTRUNNER*/
40
41using namespace std;
42
43// Registers the fixture into the 'registry'
44CPPUNIT_TEST_SUITE_REGISTRATION( ParserPsi3UnitTest );
45
46static string hydrogenPsi3_RHF ="% Created by MoleCuilder\n\
47psi: (\n\
48\tlabel = \"cc-pVTZ SCF H2\"\n\
49\tjobtype = sp\n\
50\twfn = scf\n\
51\tmaxiter = 80\n\
52\treference = rhf\n\
53\tbasis = \"cc-pVTZ\"\n\
54\tfreeze_core = no\n\
55\tunits = bohr\n\
56\tgeometry = (\n\
57\t\t( H 0.0000 0.0000 0.0 )\n\
58\t\t( H 0.0000 0.0000 0.74 )\n\
59\t)\n\
60\torigin = (0.0 0.0 0.0)\n\
61)\n"; // tested with ???
62
63static string hydrogenPsi3_ROHF ="% Created by MoleCuilder\n\
64psi: (\n\
65\tlabel = \"cc-pVTZ SCF H2\"\n\
66\tjobtype = sp\n\
67\twfn = scf\n\
68\tmaxiter = 80\n\
69\treference = rohf\n\
70\tbasis = \"cc-pVTZ\"\n\
71\tfreeze_core = no\n\
72\tunits = bohr\n\
73\tgeometry = (\n\
74\t\t( H 0.0000 0.0000 0.0 )\n\
75\t\t( H 0.0000 0.0000 0.74 )\n\
76\t)\n\
77\torigin = (0.0 0.0 0.0)\n\
78)\n"; // tested with ???
79
80static string hydrogenPsi3_UHF ="% Created by MoleCuilder\n\
81psi: (\n\
82\tlabel = \"cc-pVTZ SCF H2\"\n\
83\tjobtype = sp\n\
84\twfn = scf\n\
85\tmaxiter = 80\n\
86\treference = uhf\n\
87\tbasis = \"cc-pVTZ\"\n\
88\tmultp = 2\n\
89\t%charge = 2\n\
90\tfreeze_core = no\n\
91\tunits = bohr\n\
92\tgeometry = (\n\
93\t\t( H 0.0000 0.0000 0.0 )\n\
94\t\t( H 0.0000 0.0000 0.74 )\n\
95\t)\n\
96\torigin = (0.0 0.0 0.0)\n\
97)\n"; // tested with ???
98
99static string hydrogenPsi3_TWOCON ="% Created by MoleCuilder\n\
100psi: (\n\
101\tlabel = \"cc-pVTZ SCF H2\"\n\
102\tjobtype = sp\n\
103\twfn = scf\n\
104\tmaxiter = 80\n\
105\treference = TWOCON\n\
106\tbasis = \"cc-pVTZ\"\n\
107\tmultp = 1\n\
108\t%charge = 2\n\
109\tsocc = ( 1 1 0 0 0 0 0 0)\n\
110\tdocc = (0 0 0 0 0 0 0 0)\n\
111\tfreeze_core = no\n\
112\tunits = bohr\n\
113\tgeometry = (\n\
114\t\t( H 0.0000 0.0000 0.0 )\n\
115\t\t( H 0.0000 0.0000 0.74 )\n\
116\t)\n\
117\torigin = (0.0 0.0 0.0)\n\
118)\n"; // tested with ???
119
120void ParserPsi3UnitTest::setUp()
121{
122 // failing asserts should be thrown
123 ASSERT_DO(Assert::Throw);
124
125 parser = new FormatParser<psi3>();
126
127 params = &parser->getParams();
128
129 World::getInstance();
130
131 setVerbosity(2);
132
133 // we need hydrogens and oxygens in the following tests
134 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
135}
136
137void ParserPsi3UnitTest::tearDown()
138{
139 params = NULL;
140 delete parser;
141 ChangeTracker::purgeInstance();
142 World::purgeInstance();
143}
144
145/************************************ tests ***********************************/
146
147void ParserPsi3UnitTest::ParameterDefaultTest() {
148 // check default values
149 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::labelParam) == std::string("unknown job"));
150 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
151 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::SCF]);
152 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("80"));
153 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::RHF]);
154 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::basisParam) == std::string("cc-pVTZ"));
155 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::YES]);
156 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::angstrom]);
157 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
158 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::originParam) == std::string("(0.0\t0.0\t0.0)"));
159 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::multipParam) == std::string("1"));
160 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::chargeParam) == std::string("0"));
161 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::soccParam) == std::string("()"));
162 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::doccParam) == std::string("()"));
163 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::subgroupParam) == std::string(""));
164 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::X]);
165}
166
167void ParserPsi3UnitTest::ParameterCloneTest() {
168 FormatParser_Parameters *clone = params->clone();
169 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
170 std::stringstream setvalue(params->ParamNames[Psi3Parser_Parameters::jobtypeParam]+"="+params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
171 setvalue >> *params;
172 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
173 params->makeClone(*clone);
174 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
175}
176
177void ParserPsi3UnitTest::ParameterSetterTest() {
178// // test a string
179// {
180// std::stringstream setvalue("theory = CLHF");
181// setvalue >> parser->getParams();
182//// std::cout << "integration method is "
183//// << params->getString(Psi3Parser_Parameters::theoryParam) << std::endl;
184// CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::theoryParam) == std::string("CLHF"));
185// }
186// // test a bool
187// {
188// std::stringstream setvalue("Hessian = yes");
189// setvalue >> parser->getParams();
190//// std::cout << "Hessian is "
191//// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
192// CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::hessianParam) == std::string("yes"));
193// }
194// // test int
195// {
196// std::stringstream setvalue("maxiter = 500");
197// setvalue >> parser->getParams();
198//// std::cout << "maxiter is "
199//// << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
200// CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("500"));
201// }
202// // test whether unknown key fails
203// std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
204// {
205// std::stringstream setvalue("hessian = no");
206//#ifndef NDEBUG
207// ASSERT_DO(Assert::Throw);
208// CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
209//#else
210// setvalue >> parser->getParams();
211//#endif
212//// std::cout << "Hessian is still "
213//// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
214// CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::hessianParam) == std::string("yes"));
215// }
216}
217
218void ParserPsi3UnitTest::readPsi3Test() {
219// stringstream input(waterPsi3_CLHF);
220// params->setParameter(
221// Psi3Parser_Parameters::theoryParam,
222// params->getTheoryName(Psi3Parser_Parameters::CLHF)
223// );
224// parser->load(&input);
225//
226// CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
227}
228
229void ParserPsi3UnitTest::writePsi3Test() {
230// // build up water molecule
231// string first;
232// string second;
233// atom *Walker = NULL;
234// Walker = World::getInstance().createAtom();
235// Walker->setType(8);
236// Walker->setPosition(Vector(0,0,0));
237// Walker = World::getInstance().createAtom();
238// Walker->setType(1);
239// Walker->setPosition(Vector(0.758602,0,0.504284));
240// Walker = World::getInstance().createAtom();
241// Walker->setType(1);
242// Walker->setPosition(Vector(0.758602,0,-0.504284));
243// CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
244//
245// // create two stringstreams, one stored, one created
246//
247// std::vector<atom *> atoms = World::getInstance().getAllAtoms();
248// {
249// // compare both configs for CLHF
250// stringstream output;
251// params->setParameter(
252// Psi3Parser_Parameters::theoryParam,
253// params->getTheoryName(Psi3Parser_Parameters::CLHF)
254// );
255// parser->save(&output, atoms);
256// stringstream input(waterPsi3_CLHF);
257// for (; std::getline(input, first) && std::getline(output, second); ) {
258// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
259// CPPUNIT_ASSERT(first == second);
260// }
261// }
262// {
263// // compare both configs for CLKS
264// stringstream output;
265// params->setParameter(
266// Psi3Parser_Parameters::theoryParam,
267// params->getTheoryName(Psi3Parser_Parameters::CLKS)
268// );
269// stringstream input(waterPsi3_CLKS);
270// for (; std::getline(input, first) && std::getline(output, second); ) {
271// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
272// CPPUNIT_ASSERT(first == second);
273// }
274// }
275// {
276// // compare both configs for MBPT2
277// stringstream output;
278// params->setParameter(
279// Psi3Parser_Parameters::theoryParam,
280// params->getTheoryName(Psi3Parser_Parameters::MBPT2)
281// );
282// stringstream input(waterPsi3_MBPT2);
283// for (; std::getline(input, first) && std::getline(output, second); ) {
284// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
285// CPPUNIT_ASSERT(first == second);
286// }
287// }
288// {
289// // compare both configs for MBPT2_R12
290// stringstream output;
291// params->setParameter(
292// Psi3Parser_Parameters::theoryParam,
293// params->getTheoryName(Psi3Parser_Parameters::MBPT2_R12)
294// );
295// stringstream input(waterPsi3_MBPT2_R12);
296// for (; std::getline(input, first) && std::getline(output, second); ) {
297// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
298// CPPUNIT_ASSERT(first == second);
299// }
300// }
301}
Note: See TracBrowser for help on using the repository browser.