source: src/Parser/unittests/ParserPsi3UnitTest.cpp@ 032f31

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

Implemented Psi3Parser::load().

  • also we now have working unit test on this functionality.
  • Property mode set to 100644
File size: 12.8 KB
RevLine 
[1bef07]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
[154a45]127 params = &parser->getParams();
128
[1bef07]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{
[154a45]139 params = NULL;
[1bef07]140 delete parser;
141 ChangeTracker::purgeInstance();
142 World::purgeInstance();
143}
144
145/************************************ tests ***********************************/
146
147void ParserPsi3UnitTest::ParameterDefaultTest() {
148 // check default values
[154a45]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]);
[1bef07]165}
166
167void ParserPsi3UnitTest::ParameterCloneTest() {
[154a45]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]);
[1bef07]175}
176
177void ParserPsi3UnitTest::ParameterSetterTest() {
[f758dd]178 // test a jobtype
179 {
180 std::stringstream setvalue(
181 params->ParamNames[Psi3Parser_Parameters::jobtypeParam]
182 +" = "+params->ValidJobtypes[Psi3Parser_Parameters::OPT]
183 );
184 setvalue >> *params;
185 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
186 }
187 // test a wavefunction
188 {
189 std::stringstream setvalue(
190 params->ParamNames[Psi3Parser_Parameters::wavefunctionParam]
191 +" = "+params->ValidWavefunction[Psi3Parser_Parameters::MP2]
192 );
193 setvalue >> *params;
194 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::MP2]);
195 }
196 // test a reference
197 {
198 std::stringstream setvalue(
199 params->ParamNames[Psi3Parser_Parameters::referenceParam]
200 +" = "+params->ValidReference[Psi3Parser_Parameters::ROHF]
201 );
202 setvalue >> *params;
203 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::ROHF]);
204 }
205 // test a unique_axis
206 {
207 std::stringstream setvalue(
208 params->ParamNames[Psi3Parser_Parameters::unique_axisParam]
209 +" = "+params->ValidUniqueAxis[Psi3Parser_Parameters::Y]
210 );
211 setvalue >> *params;
212 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::Y]);
213 }
214 // test a units
215 {
216 std::stringstream setvalue(
217 params->ParamNames[Psi3Parser_Parameters::unitsParam]
218 +" = "+params->ValidUnits[Psi3Parser_Parameters::bohr]
219 );
220 setvalue >> *params;
221 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::bohr]);
222 }
223 // test a dertype
224 {
225 std::stringstream setvalue(
226 params->ParamNames[Psi3Parser_Parameters::dertypeParam]
227 +" = "+params->ValidDerivativeType[Psi3Parser_Parameters::NONE]
228 );
229 setvalue >> *params;
230 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
231 }
232 // test a freeze_core
233 {
234 std::stringstream setvalue(
235 params->ParamNames[Psi3Parser_Parameters::freeze_coreParam]
236 +" = "+params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]
237 );
238 setvalue >> *params;
239 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]);
240 }
241 // test int
242 {
243 std::stringstream setvalue(
244 params->ParamNames[Psi3Parser_Parameters::maxiterParam]
245 +" = 500"
246 );
247 setvalue >> *params;
248// std::cout << "maxiter is "
249// << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
250 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("500"));
251 }
252 // test whether unknown key fails
253 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
254 {
255 std::stringstream setvalue("sd = no");
256#ifndef NDEBUG
257 ASSERT_DO(Assert::Throw);
258 CPPUNIT_ASSERT_THROW(setvalue >> *params, Assert::AssertionFailure);
259#else
260 setvalue >> *params;
261#endif
262// std::cout << "Hessian is still "
263// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
264 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
265 }
[1bef07]266}
267
268void ParserPsi3UnitTest::readPsi3Test() {
[032f31]269 stringstream input(hydrogenPsi3_RHF);
270 // set some other parameter for jobtype
271 params->setParameter(
272 Psi3Parser_Parameters::jobtypeParam,
273 params->ValidJobtypes[Psi3Parser_Parameters::OPT]
274 );
275 parser->load(&input);
276
277 // check for jobtype from file
278 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
279 // check for 2 hydrogens
280 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
281 // check that positions are right
282 Vector PositionSum;
283 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
284 for (std::vector<atom *>::const_iterator iter = atoms.begin();
285 iter != atoms.end();
286 ++iter)
287 PositionSum += (*iter)->getPosition();
288 CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0,0,0.74) );
[1bef07]289}
290
291void ParserPsi3UnitTest::writePsi3Test() {
292// // build up water molecule
293// string first;
294// string second;
295// atom *Walker = NULL;
296// Walker = World::getInstance().createAtom();
297// Walker->setType(8);
298// Walker->setPosition(Vector(0,0,0));
299// Walker = World::getInstance().createAtom();
300// Walker->setType(1);
301// Walker->setPosition(Vector(0.758602,0,0.504284));
302// Walker = World::getInstance().createAtom();
303// Walker->setType(1);
304// Walker->setPosition(Vector(0.758602,0,-0.504284));
305// CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
306//
307// // create two stringstreams, one stored, one created
308//
309// std::vector<atom *> atoms = World::getInstance().getAllAtoms();
310// {
311// // compare both configs for CLHF
312// stringstream output;
[154a45]313// params->setParameter(
[1bef07]314// Psi3Parser_Parameters::theoryParam,
[154a45]315// params->getTheoryName(Psi3Parser_Parameters::CLHF)
[1bef07]316// );
317// parser->save(&output, atoms);
318// stringstream input(waterPsi3_CLHF);
319// for (; std::getline(input, first) && std::getline(output, second); ) {
320// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
321// CPPUNIT_ASSERT(first == second);
322// }
323// }
324// {
325// // compare both configs for CLKS
326// stringstream output;
[154a45]327// params->setParameter(
[1bef07]328// Psi3Parser_Parameters::theoryParam,
[154a45]329// params->getTheoryName(Psi3Parser_Parameters::CLKS)
[1bef07]330// );
331// stringstream input(waterPsi3_CLKS);
332// for (; std::getline(input, first) && std::getline(output, second); ) {
333// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
334// CPPUNIT_ASSERT(first == second);
335// }
336// }
337// {
338// // compare both configs for MBPT2
339// stringstream output;
[154a45]340// params->setParameter(
[1bef07]341// Psi3Parser_Parameters::theoryParam,
[154a45]342// params->getTheoryName(Psi3Parser_Parameters::MBPT2)
[1bef07]343// );
344// stringstream input(waterPsi3_MBPT2);
345// for (; std::getline(input, first) && std::getline(output, second); ) {
346// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
347// CPPUNIT_ASSERT(first == second);
348// }
349// }
350// {
351// // compare both configs for MBPT2_R12
352// stringstream output;
[154a45]353// params->setParameter(
[1bef07]354// Psi3Parser_Parameters::theoryParam,
[154a45]355// params->getTheoryName(Psi3Parser_Parameters::MBPT2_R12)
[1bef07]356// );
357// stringstream input(waterPsi3_MBPT2_R12);
358// for (; std::getline(input, first) && std::getline(output, second); ) {
359// //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
360// CPPUNIT_ASSERT(first == second);
361// }
362// }
363}
Note: See TracBrowser for help on using the repository browser.