source: src/unittests/ParserUnitTest.cpp@ 13e3c3

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 11.7 KB
Line 
1/*
2 * ParserUnitTest.cpp
3 *
4 * Created on: Mar 3, 2010
5 * Author: metzler
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "ParserUnitTest.hpp"
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
19#include "Parser/MpqcParser.hpp"
20#include "Parser/PcpParser.hpp"
21#include "Parser/TremoloParser.hpp"
22#include "Parser/XyzParser.hpp"
23#include "World.hpp"
24#include "atom.hpp"
25#include "element.hpp"
26#include "periodentafel.hpp"
27#include "Descriptors/AtomTypeDescriptor.hpp"
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33using namespace std;
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
37
38static string waterPcp = "# ParallelCarParinello - main configuration file - created with molecuilder\n\
39\n\
40mainname\tpcp\t# programm name (for runtime files)\n\
41defaultpath\not specified\t# where to put files during runtime\n\
42pseudopotpath\not specified\t# where to find pseudopotentials\n\
43\n\
44ProcPEGamma\t8\t# for parallel computing: share constants\n\
45ProcPEPsi\t1\t# for parallel computing: share wave functions\n\
46DoOutVis\t0\t# Output data for OpenDX\n\
47DoOutMes\t1\t# Output data for measurements\n\
48DoOutOrbitals\t0\t# Output all Orbitals\n\
49DoOutCurr\t0\t# Ouput current density for OpenDx\n\
50DoOutNICS\t0\t# Output Nucleus independent current shieldings\n\
51DoPerturbation\t0\t# Do perturbation calculate and determine susceptibility and shielding\n\
52DoFullCurrent\t0\t# Do full perturbation\n\
53DoConstrainedMD\t0\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD\n\
54Thermostat\tBerendsen\t2.5\t# Which Thermostat and its parameters to use in MD case.\n\
55CommonWannier\t0\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center\n\
56SawtoothStart\t0.01\t# Absolute value for smooth transition at cell border \n\
57VectorPlane\t0\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot\n\
58VectorCut\t0\t# Cut plane axis value\n\
59AddGramSch\t1\t# Additional GramSchmidtOrtogonalization to be safe\n\
60Seed\t1\t# initial value for random seed for Psi coefficients\n\
61\n\
62MaxOuterStep\t0\t# number of MolecularDynamics/Structure optimization steps\n\
63Deltat\t0.01\t# time per MD step\n\
64OutVisStep\t10\t# Output visual data every ...th step\n\
65OutSrcStep\t5\t# Output \"restart\" data every ..th step\n\
66TargetTemp\t0.000950045\t# Target temperature\n\
67MaxPsiStep\t3\t# number of Minimisation steps per state (0 - default)\n\
68EpsWannier\t1e-07\t# tolerance value for spread minimisation of orbitals\n\
69# Values specifying when to stop\n\
70MaxMinStep\t100\t# Maximum number of steps\n\
71RelEpsTotalE\t1e-07\t# relative change in total energy\n\
72RelEpsKineticE\t1e-05\t# relative change in kinetic energy\n\
73MaxMinStopStep\t2\t# check every ..th steps\n\
74MaxMinGapStopStep\t1\t# check every ..th steps\n\
75\n\
76# Values specifying when to stop for INIT, otherwise same as above\n\
77MaxInitMinStep\t100\t# Maximum number of steps\n\
78InitRelEpsTotalE\t1e-05\t# relative change in total energy\n\
79InitRelEpsKineticE\t0.0001\t# relative change in kinetic energy\n\
80InitMaxMinStopStep\t2\t# check every ..th steps\n\
81InitMaxMinGapStopStep\t1\t# check every ..th steps\n\
82\n\
83BoxLength\t# (Length of a unit cell)\n\
8420\n\
850\t20\n\
860\t0\t20\n\
87\n\
88ECut\t128\t# energy cutoff for discretization in Hartrees\n\
89MaxLevel\t5\t# number of different levels in the code, >=2\n\
90Level0Factor\t2\t# factor by which node number increases from S to 0 level\n\
91RiemannTensor\t0\t# (Use metric)\n\
92PsiType\t0\t# 0 - doubly occupied, 1 - SpinUp,SpinDown\n\
93MaxPsiDouble\t2\t# here: specifying both maximum number of SpinUp- and -Down-states\n\
94PsiMaxNoUp\t2\t# here: specifying maximum number of SpinUp-states\n\
95PsiMaxNoDown\t2\t# here: specifying maximum number of SpinDown-states\n\
96AddPsis\t0\t# Additional unoccupied Psis for bandgap determination\n\
97\n\
98RCut\t20\t# R-cut for the ewald summation\n\
99StructOpt\t0\t# Do structure optimization beforehand\n\
100IsAngstroem\t1\t# 0 - Bohr, 1 - Angstroem\n\
101RelativeCoord\t0\t# whether ion coordinates are relative (1) or absolute (0)\n\
102MaxTypes\t2\t# maximum number of different ion types\n\
103\n\
104# Ion type data (PP = PseudoPotential, Z = atomic number)\n\
105#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol\n\
106Ion_Type1\t2\t1\t1.0\t3\t3\t1.008\tHydrogen\tH\n\
107Ion_Type2\t1\t8\t1.0\t3\t3\t15.999\tOxygen\tO\n\
108#Ion_TypeNr._Nr.R[0]\tR[1]\tR[2]\tMoveType (0 MoveIon, 1 FixedIon)\n\
109Ion_Type2_1\t0.000000000\t0.000000000\t0.000000000\t0 # molecule nr 0\n\
110Ion_Type1_1\t0.758602\t0.000000000\t0.504284\t0 # molecule nr 1\n\
111Ion_Type1_2\t0.758602\t0.000000000\t-0.504284\t0 # molecule nr 2\n";
112static string waterMpqc ="% Created by MoleCuilder\n\
113mpqc: (\n\
114\tsavestate = no\n\
115\tdo_gradient = yes\n\
116\tmole<MBPT2>: (\n\
117\t\tmaxiter = 200\n\
118\t\tbasis = $:basis\n\
119\t\tmolecule = $:molecule\n\
120\t\treference<CLHF>: (\n\
121\t\t\tbasis = $:basis\n\
122\t\t\tmolecule = $:molecule\n\
123\t\t)\n\
124\t)\n\
125)\n\
126molecule<Molecule>: (\n\
127\tunit = angstrom\n\
128\t{ atoms geometry } = {\n\
129\t\tO [ -0.505735\t0\t0 ]\n\
130\t\tH [ 0.252867\t0\t0.504284 ]\n\
131\t\tH [ 0.252867\t0\t-0.504284 ]\n\
132\t}\n\
133)\n\
134basis<GaussianBasisSet>: (\n\
135\tname = \"3-21G\"\n\
136\tmolecule = $:molecule\n\
137)\n";
138static string waterXyz = "3\n\tH2O: water molecule\nO\t0\t0\t0\nH\t0.758602\t0\t0.504284\nH\t0.758602\t0\t-0.504284\n";
139static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n";
140static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
141static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
142static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
143static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
144static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
145static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
146static string Tremolo_full = "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n";
147
148void ParserUnitTest::setUp() {
149 World::getInstance();
150
151 // we need hydrogens and oxygens in the following tests
152 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
153 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
154}
155
156void ParserUnitTest::tearDown() {
157 ChangeTracker::purgeInstance();
158 World::purgeInstance();
159}
160
161/************************************ tests ***********************************/
162
163void ParserUnitTest::rewriteAnXyzTest() {
164 cout << "Testing the XYZ parser." << endl;
165 XyzParser* testParser = new XyzParser();
166 stringstream input;
167 input << waterXyz;
168 testParser->load(&input);
169
170 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
171
172 string newWaterXyz = "";
173 stringstream output;
174 testParser->save(&output);
175 newWaterXyz = output.str();
176
177 CPPUNIT_ASSERT(waterXyz == newWaterXyz);
178}
179
180void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
181 cout << "Testing the tremolo parser." << endl;
182 TremoloParser* testParser = new TremoloParser();
183 stringstream input, output;
184
185 // Atomdata beginning with "# ATOMDATA"
186 input << Tremolo_Atomdata1;
187 testParser->load(&input);
188 testParser->save(&output);
189 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
190 input.clear();
191 output.clear();
192
193 // Atomdata beginning with "#ATOMDATA"
194 input << Tremolo_Atomdata2;
195 testParser->load(&input);
196 testParser->save(&output);
197 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
198 input.clear();
199 output.clear();
200
201 // Invalid key in Atomdata line
202 input << Tremolo_invalidkey;
203 testParser->load(&input);
204 //TODO: proove invalidity
205 input.clear();
206}
207
208void ParserUnitTest::readTremoloCoordinatesTest() {
209 TremoloParser* testParser = new TremoloParser();
210 stringstream input;
211
212 // One simple data line
213 input << Tremolo_Atomdata2;
214 testParser->load(&input);
215 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
216 input.clear();
217}
218
219void ParserUnitTest::readTremoloVelocityTest() {
220 TremoloParser* testParser = new TremoloParser();
221 stringstream input;
222
223 // One simple data line
224 input << Tremolo_velocity;
225 testParser->load(&input);
226 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
227 input.clear();
228}
229
230void ParserUnitTest::readTremoloNeighborInformationTest() {
231 TremoloParser* testParser = new TremoloParser();
232 stringstream input;
233
234 // Neighbor data
235 input << Tremolo_neighbours;
236 testParser->load(&input);
237
238 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
239 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
240 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
241 input.clear();
242}
243
244void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
245 TremoloParser* testParser = new TremoloParser();
246 stringstream input, output;
247
248 // Neighbor data
249 input << Tremolo_improper;
250 testParser->load(&input);
251 testParser->save(&output);
252 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
253 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
254 input.clear();
255 output.clear();
256}
257
258void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
259 TremoloParser* testParser = new TremoloParser();
260 stringstream input, output;
261
262 // Neighbor data
263 input << Tremolo_torsion;
264 testParser->load(&input);
265 testParser->save(&output);
266 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
267 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
268 input.clear();
269 output.clear();
270}
271
272void ParserUnitTest::writeTremoloTest() {
273 TremoloParser* testParser = new TremoloParser();
274 stringstream output;
275
276 // with the maximum number of fields and minimal information, default values are printed
277 atom* newAtom = World::getInstance().createAtom();
278 newAtom->setType(1);
279 testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
280 testParser->save(&output);
281 CPPUNIT_ASSERT(output.str() == Tremolo_full);
282
283 cout << "testing the tremolo parser is done" << endl;
284}
285
286void ParserUnitTest::readwritePcpTest() {
287 stringstream input(waterPcp);
288 PcpParser* testParser = new PcpParser();
289 testParser->load(&input);
290 input.clear();
291
292 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
293
294 string newWaterPcp = "";
295 stringstream output;
296 testParser->save(&output);
297
298 input << output;
299 PcpParser* testParser2 = new PcpParser();
300 testParser2->load(&input);
301
302 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
303
304 CPPUNIT_ASSERT(*testParser == *testParser2);
305}
306
307void ParserUnitTest::writeMpqcTest() {
308 // build up water molecule
309 atom *Walker = NULL;
310 Walker = World::getInstance().createAtom();
311 Walker->setType(8);
312 Walker->setPosition(Vector(0,0,0));
313 Walker = World::getInstance().createAtom();
314 Walker->setType(1);
315 Walker->setPosition(Vector(0.758602,0,0.504284));
316 Walker = World::getInstance().createAtom();
317 Walker->setType(1);
318 Walker->setPosition(Vector(0.758602,0,-0.504284));
319 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
320
321 // create two stringstreams, one stored, one created
322 stringstream input(waterMpqc);
323 MpqcParser* testParser = new MpqcParser();
324 stringstream output;
325 testParser->save(&output);
326
327 // compare both configs
328 string first = input.str();
329 string second = output.str();
330 CPPUNIT_ASSERT(first == second);
331}
Note: See TracBrowser for help on using the repository browser.