source: src/Parser/unittests/ParserPcpUnitTest.cpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 was fac58f, checked in by Frederik Heber <heber@…>, 9 years ago

Converted FormatParser::save() to using vector of const atom ptrs.

  • required to change all save() functions in all parsers.
  • Property mode set to 100644
File size: 6.9 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 * ParserPcpUnitTest.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 "ParserPcpUnitTest.hpp"
37
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41
42#include "Atom/atom.hpp"
43#include "Atom/AtomObserver.hpp"
44#include "CodePatterns/Log.hpp"
45#include "Descriptors/AtomTypeDescriptor.hpp"
46#include "Element/element.hpp"
47#include "Element/periodentafel.hpp"
48#include "Parser/ChangeTracker.hpp"
49#include "Parser/PcpParser.hpp"
50#include "World.hpp"
51
52#ifdef HAVE_TESTRUNNER
53#include "UnitTestMain.hpp"
54#endif /*HAVE_TESTRUNNER*/
55
56using namespace std;
57
58// Registers the fixture into the 'registry'
59CPPUNIT_TEST_SUITE_REGISTRATION( ParserPcpUnitTest );
60
61static string waterPcp = "# ParallelCarParinello - main configuration file - created with molecuilder\n\
62\n\
63mainname\tpcp\t# programm name (for runtime files)\n\
64defaultpath\not specified\t# where to put files during runtime\n\
65pseudopotpath\not specified\t# where to find pseudopotentials\n\
66\n\
67ProcPEGamma\t8\t# for parallel computing: share constants\n\
68ProcPEPsi\t1\t# for parallel computing: share wave functions\n\
69DoOutVis\t0\t# Output data for OpenDX\n\
70DoOutMes\t1\t# Output data for measurements\n\
71DoOutOrbitals\t0\t# Output all Orbitals\n\
72DoOutCurr\t0\t# Ouput current density for OpenDx\n\
73DoOutNICS\t0\t# Output Nucleus independent current shieldings\n\
74DoPerturbation\t0\t# Do perturbation calculate and determine susceptibility and shielding\n\
75DoFullCurrent\t0\t# Do full perturbation\n\
76DoConstrainedMD\t0\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD\n\
77Thermostat\tBerendsen\t2.5\t# Which Thermostat and its parameters to use in MD case.\n\
78PcpWannier\t0\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center\n\
79SawtoothStart\t0.01\t# Absolute value for smooth transition at cell border \n\
80VectorPlane\t0\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot\n\
81VectorCut\t0\t# Cut plane axis value\n\
82AddGramSch\t1\t# Additional GramSchmidtOrtogonalization to be safe\n\
83Seed\t1\t# initial value for random seed for Psi coefficients\n\
84\n\
85MaxOuterStep\t0\t# number of MolecularDynamics/Structure optimization steps\n\
86Deltat\t0.01\t# time per MD step\n\
87OutVisStep\t10\t# Output visual data every ...th step\n\
88OutSrcStep\t5\t# Output \"restart\" data every ..th step\n\
89TargetTemp\t0.000950045\t# Target temperature\n\
90MaxPsiStep\t3\t# number of Minimisation steps per state (0 - default)\n\
91EpsWannier\t1e-07\t# tolerance value for spread minimisation of orbitals\n\
92# Values specifying when to stop\n\
93MaxMinStep\t100\t# Maximum number of steps\n\
94RelEpsTotalE\t1e-07\t# relative change in total energy\n\
95RelEpsKineticE\t1e-05\t# relative change in kinetic energy\n\
96MaxMinStopStep\t2\t# check every ..th steps\n\
97MaxMinGapStopStep\t1\t# check every ..th steps\n\
98\n\
99# Values specifying when to stop for INIT, otherwise same as above\n\
100MaxInitMinStep\t100\t# Maximum number of steps\n\
101InitRelEpsTotalE\t1e-05\t# relative change in total energy\n\
102InitRelEpsKineticE\t0.0001\t# relative change in kinetic energy\n\
103InitMaxMinStopStep\t2\t# check every ..th steps\n\
104InitMaxMinGapStopStep\t1\t# check every ..th steps\n\
105\n\
106BoxLength\t# (Length of a unit cell)\n\
10720\n\
1080\t20\n\
1090\t0\t20\n\
110\n\
111ECut\t128\t# energy cutoff for discretization in Hartrees\n\
112MaxLevel\t5\t# number of different levels in the code, >=2\n\
113Level0Factor\t2\t# factor by which node number increases from S to 0 level\n\
114RiemannTensor\t0\t# (Use metric)\n\
115PsiType\t0\t# 0 - doubly occupied, 1 - SpinUp,SpinDown\n\
116MaxPsiDouble\t2\t# here: specifying both maximum number of SpinUp- and -Down-states\n\
117PsiMaxNoUp\t2\t# here: specifying maximum number of SpinUp-states\n\
118PsiMaxNoDown\t2\t# here: specifying maximum number of SpinDown-states\n\
119AddPsis\t0\t# Additional unoccupied Psis for bandgap determination\n\
120\n\
121RCut\t20\t# R-cut for the ewald summation\n\
122StructOpt\t0\t# Do structure optimization beforehand\n\
123IsAngstroem\t1\t# 0 - Bohr, 1 - Angstroem\n\
124RelativeCoord\t0\t# whether ion coordinates are relative (1) or absolute (0)\n\
125MaxTypes\t2\t# maximum number of different ion types\n\
126\n\
127# Ion type data (PP = PseudoPotential, Z = atomic number)\n\
128#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol\n\
129Ion_Type1\t2\t1\t1.0\t3\t3\t1.008\tHydrogen\tH\n\
130Ion_Type2\t1\t8\t1.0\t3\t3\t15.999\tOxygen\tO\n\
131#Ion_TypeNr._Nr.R[0]\tR[1]\tR[2]\tMoveType (0 MoveIon, 1 FixedIon)\n\
132Ion_Type2_1\t1.000000000\t0.000000000\t0.000000000\t0 # molecule nr 0\n\
133Ion_Type1_1\t0.758602\t0.000000000\t0.504284\t0 # molecule nr 1\n\
134Ion_Type1_2\t0.758602\t0.000000000\t-0.504284\t0 # molecule nr 2\n";
135
136void ParserPcpUnitTest::setUp() {
137 World::getInstance();
138
139 parser = new FormatParser<pcp>();
140
141 setVerbosity(2);
142
143 // we need hydrogens and oxygens in the following tests
144 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
145 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
146}
147
148void ParserPcpUnitTest::tearDown()
149{
150 delete parser;
151 ChangeTracker::purgeInstance();
152 World::purgeInstance();
153 AtomObserver::purgeInstance();
154}
155
156/************************************ tests ***********************************/
157
158void ParserPcpUnitTest::readwritePcpTest() {
159 stringstream input(waterPcp);
160 parser->load(&input);
161 input.clear();
162
163 CPPUNIT_ASSERT_EQUAL(3, const_cast<const World &>(World::getInstance()).numAtoms());
164
165 // check that equality function is ok
166 CPPUNIT_ASSERT(*parser == *parser);
167
168 stringstream output;
169 std::vector<const atom *> atoms = const_cast<const World &>(World::getInstance()).
170 getAllAtoms();
171 parser->save(&output, atoms);
172
173 input << output.str();
174 FormatParser<pcp>* parser2 = new FormatParser<pcp>();
175 parser2->load(&input);
176
177 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
178
179 CPPUNIT_ASSERT(*parser == *parser2);
180
181 delete parser2;
182}
Note: See TracBrowser for help on using the repository browser.