source: src/unittests/ParserUnitTest.cpp@ 55240c4

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 55240c4 was 1b2d30, checked in by Frederik Heber <heber@…>, 15 years ago

Extended PcpParser, completed MpqcParser.

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