source: src/Parser/unittests/ParserPsi3UnitTest.cpp@ 5aaa43

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 5aaa43 was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 15.3 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 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * ParserPsi3UnitTest.cpp
26 *
27 * Created on: Mar 3, 2010
28 * Author: metzler
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "ParserPsi3UnitTest.hpp"
37
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41
42#include <boost/any.hpp>
43
44#include "CodePatterns/Log.hpp"
45
46#include "Atom/atom.hpp"
47#include "Atom/AtomObserver.hpp"
48#include "Element/element.hpp"
49#include "Element/periodentafel.hpp"
50#include "CodePatterns/Assert.hpp"
51#include "Descriptors/AtomTypeDescriptor.hpp"
52#include "Parser/ChangeTracker.hpp"
53#include "Parser/Psi3Parser.hpp"
54#include "World.hpp"
55
56#ifdef HAVE_TESTRUNNER
57#include "UnitTestMain.hpp"
58#endif /*HAVE_TESTRUNNER*/
59
60using namespace std;
61
62// Registers the fixture into the 'registry'
63CPPUNIT_TEST_SUITE_REGISTRATION( ParserPsi3UnitTest );
64
65static string hydrogenPsi3_RHF ="% Created by MoleCuilder\n\
66psi: (\n\
67\tlabel = \"cc-pVTZ SCF H2\"\n\
68\tjobtype = sp\n\
69\twfn = scf\n\
70\tmaxiter = 80\n\
71\treference = rhf\n\
72\tbasis = \"cc-pVTZ\"\n\
73\tfreeze_core = no\n\
74\tunits = angstrom\n\
75\tgeometry = (\n\
76\t( H\t0\t0\t-0.37 )\n\
77\t( H\t0\t0\t0.37 )\n\
78\t)\n\
79\torigin = (0.0\t0.0\t0.0)\n\
80)\n"; // tested with ???
81
82static string hydrogenPsi3_ROHF ="% Created by MoleCuilder\n\
83psi: (\n\
84\tlabel = \"cc-pVTZ SCF H2\"\n\
85\tjobtype = sp\n\
86\twfn = scf\n\
87\tmaxiter = 80\n\
88\treference = rohf\n\
89\tbasis = \"cc-pVTZ\"\n\
90\tfreeze_core = no\n\
91\tunits = angstrom\n\
92\tgeometry = (\n\
93\t( H\t0\t0\t-0.37 )\n\
94\t( H\t0\t0\t0.37 )\n\
95\t)\n\
96\torigin = (0.0\t0.0\t0.0)\n\
97)\n"; // tested with ???
98
99static string hydrogenPsi3_UHF ="% 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 = uhf\n\
106\tbasis = \"cc-pVTZ\"\n\
107\tmultp = 3\n\
108\tcharge = 2\n\
109\tfreeze_core = no\n\
110\tunits = angstrom\n\
111\tgeometry = (\n\
112\t( H\t0\t0\t-0.37 )\n\
113\t( H\t0\t0\t0.37 )\n\
114\t)\n\
115\torigin = (0.0\t0.0\t0.0)\n\
116)\n"; // tested with ???
117
118static string hydrogenPsi3_TWOCON ="% Created by MoleCuilder\n\
119psi: (\n\
120\tlabel = \"cc-pVTZ SCF H2\"\n\
121\tjobtype = sp\n\
122\twfn = scf\n\
123\tmaxiter = 80\n\
124\treference = twocon\n\
125\tbasis = \"cc-pVTZ\"\n\
126\tmultp = 3\n\
127\tcharge = 2\n\
128\tsocc = ( 1 1 0 0 0 0 0 0 )\n\
129\tdocc = ( 0 0 0 0 0 0 0 0 )\n\
130\tsubgroup = c2v\n\
131\tunique_axis = x\n\
132\tfreeze_core = no\n\
133\tunits = angstrom\n\
134\tgeometry = (\n\
135\t( H\t0\t0\t-0.37 )\n\
136\t( H\t0\t0\t0.37 )\n\
137\t)\n\
138\torigin = (0.0\t0.0\t0.0)\n\
139)\n"; // tested with ???
140
141void ParserPsi3UnitTest::setUp()
142{
143 // failing asserts should be thrown
144 ASSERT_DO(Assert::Throw);
145
146 parser = new FormatParser<psi3>();
147
148 params = &parser->getParams();
149
150 World::getInstance();
151
152 setVerbosity(2);
153
154 // we need hydrogens and oxygens in the following tests
155 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
156}
157
158void ParserPsi3UnitTest::tearDown()
159{
160 params = NULL;
161 delete parser;
162 ChangeTracker::purgeInstance();
163 World::purgeInstance();
164 AtomObserver::purgeInstance();
165}
166
167/************************************ tests ***********************************/
168
169void ParserPsi3UnitTest::ParameterDefaultTest() {
170 // check default values
171 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::labelParam) == std::string("unknown job"));
172 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
173 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::SCF]);
174 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("80"));
175 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::RHF]);
176 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::basisParam) == std::string("cc-pVTZ"));
177 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::YES]);
178 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::angstrom]);
179 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
180 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::originParam) == std::string("(0.0\t0.0\t0.0)"));
181 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::multiplicityParam) == std::string("1"));
182 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::chargeParam) == std::string("0"));
183 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::soccParam) == std::string("()"));
184 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::doccParam) == std::string("()"));
185 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::subgroupParam) == std::string(""));
186 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::X]);
187}
188
189void ParserPsi3UnitTest::ParameterCloneTest() {
190 FormatParser_Parameters *clone = params->clone();
191 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
192 std::stringstream setvalue(params->ParamNames[Psi3Parser_Parameters::jobtypeParam]+"="+params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
193 setvalue >> *params;
194 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
195 params->makeClone(*clone);
196 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
197}
198
199void ParserPsi3UnitTest::ParameterSetterTest() {
200 // test a jobtype
201 {
202 std::stringstream setvalue(
203 params->ParamNames[Psi3Parser_Parameters::jobtypeParam]
204 +" = "+params->ValidJobtypes[Psi3Parser_Parameters::OPT]
205 );
206 setvalue >> *params;
207 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
208 }
209 // test a wavefunction
210 {
211 std::stringstream setvalue(
212 params->ParamNames[Psi3Parser_Parameters::wavefunctionParam]
213 +" = "+params->ValidWavefunction[Psi3Parser_Parameters::MP2]
214 );
215 setvalue >> *params;
216 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::wavefunctionParam) == params->ValidWavefunction[Psi3Parser_Parameters::MP2]);
217 }
218 // test a reference
219 {
220 std::stringstream setvalue(
221 params->ParamNames[Psi3Parser_Parameters::referenceParam]
222 +" = "+params->ValidReference[Psi3Parser_Parameters::ROHF]
223 );
224 setvalue >> *params;
225 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::referenceParam) == params->ValidReference[Psi3Parser_Parameters::ROHF]);
226 }
227 // test a unique_axis
228 {
229 std::stringstream setvalue(
230 params->ParamNames[Psi3Parser_Parameters::unique_axisParam]
231 +" = "+params->ValidUniqueAxis[Psi3Parser_Parameters::Y]
232 );
233 setvalue >> *params;
234 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unique_axisParam) == params->ValidUniqueAxis[Psi3Parser_Parameters::Y]);
235 }
236 // test a units
237 {
238 std::stringstream setvalue(
239 params->ParamNames[Psi3Parser_Parameters::unitsParam]
240 +" = "+params->ValidUnits[Psi3Parser_Parameters::bohr]
241 );
242 setvalue >> *params;
243 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::unitsParam) == params->ValidUnits[Psi3Parser_Parameters::bohr]);
244 }
245 // test a dertype
246 {
247 std::stringstream setvalue(
248 params->ParamNames[Psi3Parser_Parameters::dertypeParam]
249 +" = "+params->ValidDerivativeType[Psi3Parser_Parameters::NONE]
250 );
251 setvalue >> *params;
252 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::dertypeParam) == params->ValidDerivativeType[Psi3Parser_Parameters::NONE]);
253 }
254 // test a freeze_core
255 {
256 std::stringstream setvalue(
257 params->ParamNames[Psi3Parser_Parameters::freeze_coreParam]
258 +" = "+params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]
259 );
260 setvalue >> *params;
261 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::freeze_coreParam) == params->ValidFreezeCore[Psi3Parser_Parameters::LARGE]);
262 }
263 // test int
264 {
265 std::stringstream setvalue(
266 params->ParamNames[Psi3Parser_Parameters::maxiterParam]
267 +" = 500"
268 );
269 setvalue >> *params;
270// std::cout << "maxiter is "
271// << params->getString(Psi3Parser_Parameters::maxiterParam) << std::endl;
272 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::maxiterParam) == std::string("500"));
273 }
274 // test whether unknown key fails
275 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl;
276 {
277 std::stringstream setvalue("sd = no");
278#ifndef NDEBUG
279 ASSERT_DO(Assert::Throw);
280 CPPUNIT_ASSERT_THROW(setvalue >> *params, Assert::AssertionFailure);
281#else
282 setvalue >> *params;
283#endif
284// std::cout << "Hessian is still "
285// << params->getString(Psi3Parser_Parameters::hessianParam) << std::endl;
286 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::OPT]);
287 }
288}
289
290void ParserPsi3UnitTest::readPsi3Test() {
291 stringstream input(hydrogenPsi3_RHF);
292 // set some other parameter for jobtype
293 params->setParameter(
294 Psi3Parser_Parameters::jobtypeParam,
295 params->ValidJobtypes[Psi3Parser_Parameters::OPT]
296 );
297 parser->load(&input);
298
299 // check for jobtype from file
300 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]);
301 // check for 2 hydrogens
302 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
303 // check that positions are right
304 Vector PositionSum;
305 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
306 for (std::vector<atom *>::const_iterator iter = atoms.begin();
307 iter != atoms.end();
308 ++iter)
309 PositionSum += (*iter)->getPosition();
310 CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0.,0.,0.) );
311}
312
313void ParserPsi3UnitTest::writePsi3Test() {
314 // build up hydrogen molecule
315 string first;
316 string second;
317 atom *Walker = NULL;
318 Walker = World::getInstance().createAtom();
319 Walker->setType(1);
320 Walker->setPosition(Vector(0.,0.,0.));
321 Walker = World::getInstance().createAtom();
322 Walker->setType(1);
323 Walker->setPosition(Vector(0.,0,0.74));
324 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms());
325
326 // set general parameters: label and freeze_core
327 params->setParameter(
328 Psi3Parser_Parameters::labelParam,
329 "cc-pVTZ SCF H2"
330 );
331 params->setParameter(
332 Psi3Parser_Parameters::freeze_coreParam,
333 params->ValidFreezeCore[Psi3Parser_Parameters::NO]
334 );
335 params->setParameter(
336 Psi3Parser_Parameters::unitsParam,
337 params->ValidUnits[Psi3Parser_Parameters::angstrom]
338 );
339
340 // create two stringstreams, one stored, one created
341 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
342 {
343 // compare both configs for RHF
344 stringstream output;
345 params->setParameter(
346 Psi3Parser_Parameters::referenceParam,
347 params->ValidReference[Psi3Parser_Parameters::RHF]
348 );
349 parser->save(&output, atoms);
350 stringstream input(hydrogenPsi3_RHF);
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 // compare both configs for ROHF
363 stringstream output;
364 params->setParameter(
365 Psi3Parser_Parameters::referenceParam,
366 params->ValidReference[Psi3Parser_Parameters::ROHF]
367 );
368 parser->save(&output, atoms);
369 stringstream input(hydrogenPsi3_ROHF);
370 // check for non-empty streams
371 input.peek();
372 output.peek();
373 CPPUNIT_ASSERT(input.good() && output.good());
374 // check equality of streams per line (for debugging)
375 for (; std::getline(input, first) && std::getline(output, second); ) {
376 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
377 CPPUNIT_ASSERT(first == second);
378 }
379 }
380 {
381 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "2");
382 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
383 // compare both configs for UHF
384 stringstream output;
385 params->setParameter(
386 Psi3Parser_Parameters::referenceParam,
387 params->ValidReference[Psi3Parser_Parameters::UHF]
388 );
389 parser->save(&output, atoms);
390 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
391 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
392 stringstream input(hydrogenPsi3_UHF);
393 // check for non-empty streams
394 input.peek();
395 output.peek();
396 CPPUNIT_ASSERT(input.good() && output.good());
397 // check equality of streams per line (for debugging)
398 for (; std::getline(input, first) && std::getline(output, second); ) {
399 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
400 CPPUNIT_ASSERT(first == second);
401 }
402 }
403 {
404 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
405 params->setParameter(Psi3Parser_Parameters::chargeParam, "2");
406 params->setParameter(Psi3Parser_Parameters::soccParam, "( 1 1 0 0 0 0 0 0 )");
407 params->setParameter(Psi3Parser_Parameters::doccParam, "( 0 0 0 0 0 0 0 0 )");
408 params->setParameter(Psi3Parser_Parameters::subgroupParam, "c2v");
409 params->setParameter(Psi3Parser_Parameters::unique_axisParam, "x");
410 // compare both configs for TWOCON
411 stringstream output;
412 params->setParameter(
413 Psi3Parser_Parameters::referenceParam,
414 params->ValidReference[Psi3Parser_Parameters::TWOCON]
415 );
416 parser->save(&output, atoms);
417 params->setParameter(Psi3Parser_Parameters::multiplicityParam, "1");
418 params->setParameter(Psi3Parser_Parameters::chargeParam, "0");
419 stringstream input(hydrogenPsi3_TWOCON);
420 // check for non-empty streams
421 input.peek();
422 output.peek();
423 CPPUNIT_ASSERT(input.good() && output.good());
424 // check equality of streams per line (for debugging)
425 for (; std::getline(input, first) && std::getline(output, second); ) {
426 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
427 CPPUNIT_ASSERT(first == second);
428 }
429 }
430}
Note: See TracBrowser for help on using the repository browser.