[ab4b55] | 1 | /*
|
---|
| 2 | * ParserUnitTest.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Mar 3, 2010
|
---|
| 5 | * Author: metzler
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[ab4b55] | 13 | #include "ParserUnitTest.hpp"
|
---|
| 14 |
|
---|
| 15 | #include <cppunit/CompilerOutputter.h>
|
---|
| 16 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 17 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 18 |
|
---|
[1b2d30] | 19 | #include "Parser/MpqcParser.hpp"
|
---|
| 20 | #include "Parser/PcpParser.hpp"
|
---|
[9131f3] | 21 | #include "Parser/TremoloParser.hpp"
|
---|
[1b2d30] | 22 | #include "Parser/XyzParser.hpp"
|
---|
[ab4b55] | 23 | #include "World.hpp"
|
---|
[b8d4a3] | 24 | #include "atom.hpp"
|
---|
[ab4b55] | 25 | #include "element.hpp"
|
---|
| 26 | #include "periodentafel.hpp"
|
---|
[b8d4a3] | 27 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
[ab4b55] | 28 |
|
---|
| 29 | #ifdef HAVE_TESTRUNNER
|
---|
| 30 | #include "UnitTestMain.hpp"
|
---|
| 31 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 32 |
|
---|
| 33 | using namespace std;
|
---|
| 34 |
|
---|
| 35 | // Registers the fixture into the 'registry'
|
---|
| 36 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
|
---|
| 37 |
|
---|
[1b2d30] | 38 | static string waterPcp = "# ParallelCarParinello - main configuration file - created with molecuilder\n\
|
---|
| 39 | \n\
|
---|
| 40 | mainname\tpcp\t# programm name (for runtime files)\n\
|
---|
| 41 | defaultpath\not specified\t# where to put files during runtime\n\
|
---|
| 42 | pseudopotpath\not specified\t# where to find pseudopotentials\n\
|
---|
| 43 | \n\
|
---|
| 44 | ProcPEGamma\t8\t# for parallel computing: share constants\n\
|
---|
| 45 | ProcPEPsi\t1\t# for parallel computing: share wave functions\n\
|
---|
| 46 | DoOutVis\t0\t# Output data for OpenDX\n\
|
---|
| 47 | DoOutMes\t1\t# Output data for measurements\n\
|
---|
| 48 | DoOutOrbitals\t0\t# Output all Orbitals\n\
|
---|
| 49 | DoOutCurr\t0\t# Ouput current density for OpenDx\n\
|
---|
| 50 | DoOutNICS\t0\t# Output Nucleus independent current shieldings\n\
|
---|
| 51 | DoPerturbation\t0\t# Do perturbation calculate and determine susceptibility and shielding\n\
|
---|
| 52 | DoFullCurrent\t0\t# Do full perturbation\n\
|
---|
| 53 | DoConstrainedMD\t0\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD\n\
|
---|
| 54 | Thermostat\tBerendsen\t2.5\t# Which Thermostat and its parameters to use in MD case.\n\
|
---|
| 55 | CommonWannier\t0\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center\n\
|
---|
| 56 | SawtoothStart\t0.01\t# Absolute value for smooth transition at cell border \n\
|
---|
| 57 | VectorPlane\t0\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot\n\
|
---|
| 58 | VectorCut\t0\t# Cut plane axis value\n\
|
---|
| 59 | AddGramSch\t1\t# Additional GramSchmidtOrtogonalization to be safe\n\
|
---|
| 60 | Seed\t1\t# initial value for random seed for Psi coefficients\n\
|
---|
| 61 | \n\
|
---|
| 62 | MaxOuterStep\t0\t# number of MolecularDynamics/Structure optimization steps\n\
|
---|
| 63 | Deltat\t0.01\t# time per MD step\n\
|
---|
| 64 | OutVisStep\t10\t# Output visual data every ...th step\n\
|
---|
| 65 | OutSrcStep\t5\t# Output \"restart\" data every ..th step\n\
|
---|
| 66 | TargetTemp\t0.000950045\t# Target temperature\n\
|
---|
| 67 | MaxPsiStep\t3\t# number of Minimisation steps per state (0 - default)\n\
|
---|
| 68 | EpsWannier\t1e-07\t# tolerance value for spread minimisation of orbitals\n\
|
---|
| 69 | # Values specifying when to stop\n\
|
---|
| 70 | MaxMinStep\t100\t# Maximum number of steps\n\
|
---|
| 71 | RelEpsTotalE\t1e-07\t# relative change in total energy\n\
|
---|
| 72 | RelEpsKineticE\t1e-05\t# relative change in kinetic energy\n\
|
---|
[2fd80b5] | 73 | MaxMinStopStep\t2\t# check every ..th steps\n\
|
---|
[1b2d30] | 74 | MaxMinGapStopStep\t1\t# check every ..th steps\n\
|
---|
| 75 | \n\
|
---|
| 76 | # Values specifying when to stop for INIT, otherwise same as above\n\
|
---|
| 77 | MaxInitMinStep\t100\t# Maximum number of steps\n\
|
---|
| 78 | InitRelEpsTotalE\t1e-05\t# relative change in total energy\n\
|
---|
| 79 | InitRelEpsKineticE\t0.0001\t# relative change in kinetic energy\n\
|
---|
[2fd80b5] | 80 | InitMaxMinStopStep\t2\t# check every ..th steps\n\
|
---|
[1b2d30] | 81 | InitMaxMinGapStopStep\t1\t# check every ..th steps\n\
|
---|
| 82 | \n\
|
---|
| 83 | BoxLength\t# (Length of a unit cell)\n\
|
---|
| 84 | 20\n\
|
---|
| 85 | 0\t20\n\
|
---|
| 86 | 0\t0\t20\n\
|
---|
| 87 | \n\
|
---|
| 88 | ECut\t128\t# energy cutoff for discretization in Hartrees\n\
|
---|
| 89 | MaxLevel\t5\t# number of different levels in the code, >=2\n\
|
---|
| 90 | Level0Factor\t2\t# factor by which node number increases from S to 0 level\n\
|
---|
| 91 | RiemannTensor\t0\t# (Use metric)\n\
|
---|
| 92 | PsiType\t0\t# 0 - doubly occupied, 1 - SpinUp,SpinDown\n\
|
---|
[2fd80b5] | 93 | MaxPsiDouble\t2\t# here: specifying both maximum number of SpinUp- and -Down-states\n\
|
---|
| 94 | PsiMaxNoUp\t2\t# here: specifying maximum number of SpinUp-states\n\
|
---|
| 95 | PsiMaxNoDown\t2\t# here: specifying maximum number of SpinDown-states\n\
|
---|
[1b2d30] | 96 | AddPsis\t0\t# Additional unoccupied Psis for bandgap determination\n\
|
---|
| 97 | \n\
|
---|
| 98 | RCut\t20\t# R-cut for the ewald summation\n\
|
---|
| 99 | StructOpt\t0\t# Do structure optimization beforehand\n\
|
---|
| 100 | IsAngstroem\t1\t# 0 - Bohr, 1 - Angstroem\n\
|
---|
| 101 | RelativeCoord\t0\t# whether ion coordinates are relative (1) or absolute (0)\n\
|
---|
| 102 | MaxTypes\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\
|
---|
| 106 | Ion_Type1\t2\t1\t1.0\t3\t3\t1.008\tHydrogen\tH\n\
|
---|
| 107 | Ion_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\
|
---|
| 109 | Ion_Type2_1\t0.000000000\t0.000000000\t0.000000000\t0 # molecule nr 0\n\
|
---|
| 110 | Ion_Type1_1\t0.758602\t0.000000000\t0.504284\t0 # molecule nr 1\n\
|
---|
| 111 | Ion_Type1_2\t0.758602\t0.000000000\t-0.504284\t0 # molecule nr 2\n";
|
---|
| 112 | static string waterMpqc ="% Created by MoleCuilder\n\
|
---|
| 113 | mpqc: (\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\
|
---|
| 126 | molecule<Molecule>: (\n\
|
---|
| 127 | \tunit = angstrom\n\
|
---|
| 128 | \t{ atoms geometry } = {\n\
|
---|
[2fd80b5] | 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\
|
---|
[1b2d30] | 132 | \t}\n\
|
---|
| 133 | )\n\
|
---|
| 134 | basis<GaussianBasisSet>: (\n\
|
---|
| 135 | \tname = \"3-21G\"\n\
|
---|
| 136 | \tmolecule = $:molecule\n\
|
---|
| 137 | )\n";
|
---|
[86cff86] | 138 | static 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";
|
---|
[1b2d30] | 139 | static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n";
|
---|
| 140 | static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
| 141 | static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
|
---|
| 142 | static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
| 143 | static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
|
---|
| 144 | static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
| 145 | static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
| 146 | static 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";
|
---|
[ab4b55] | 147 |
|
---|
| 148 | void ParserUnitTest::setUp() {
|
---|
[4eb4fe] | 149 | World::getInstance();
|
---|
[1b2d30] | 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);
|
---|
[ab4b55] | 154 | }
|
---|
| 155 |
|
---|
| 156 | void ParserUnitTest::tearDown() {
|
---|
[2f40c0e] | 157 | ChangeTracker::purgeInstance();
|
---|
[b8d4a3] | 158 | World::purgeInstance();
|
---|
[ab4b55] | 159 | }
|
---|
| 160 |
|
---|
| 161 | /************************************ tests ***********************************/
|
---|
| 162 |
|
---|
| 163 | void ParserUnitTest::rewriteAnXyzTest() {
|
---|
[9131f3] | 164 | cout << "Testing the XYZ parser." << endl;
|
---|
[ab4b55] | 165 | XyzParser* testParser = new XyzParser();
|
---|
| 166 | stringstream input;
|
---|
| 167 | input << waterXyz;
|
---|
| 168 | testParser->load(&input);
|
---|
| 169 |
|
---|
[4415da] | 170 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
[ab4b55] | 171 |
|
---|
| 172 | string newWaterXyz = "";
|
---|
| 173 | stringstream output;
|
---|
| 174 | testParser->save(&output);
|
---|
| 175 | newWaterXyz = output.str();
|
---|
| 176 |
|
---|
| 177 | CPPUNIT_ASSERT(waterXyz == newWaterXyz);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[b8d4a3] | 180 | void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
|
---|
[9131f3] | 181 | cout << "Testing the tremolo parser." << endl;
|
---|
| 182 | TremoloParser* testParser = new TremoloParser();
|
---|
[b8d4a3] | 183 | stringstream input, output;
|
---|
[4415da] | 184 |
|
---|
| 185 | // Atomdata beginning with "# ATOMDATA"
|
---|
[1b2d30] | 186 | input << Tremolo_Atomdata1;
|
---|
[9131f3] | 187 | testParser->load(&input);
|
---|
[b8d4a3] | 188 | testParser->save(&output);
|
---|
[1b2d30] | 189 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
|
---|
[4415da] | 190 | input.clear();
|
---|
[b8d4a3] | 191 | output.clear();
|
---|
[4415da] | 192 |
|
---|
| 193 | // Atomdata beginning with "#ATOMDATA"
|
---|
[1b2d30] | 194 | input << Tremolo_Atomdata2;
|
---|
[b8d4a3] | 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
|
---|
[1b2d30] | 202 | input << Tremolo_invalidkey;
|
---|
[4415da] | 203 | testParser->load(&input);
|
---|
[b8d4a3] | 204 | //TODO: proove invalidity
|
---|
[9131f3] | 205 | input.clear();
|
---|
[b8d4a3] | 206 | }
|
---|
| 207 |
|
---|
| 208 | void ParserUnitTest::readTremoloCoordinatesTest() {
|
---|
| 209 | TremoloParser* testParser = new TremoloParser();
|
---|
| 210 | stringstream input;
|
---|
[4415da] | 211 |
|
---|
| 212 | // One simple data line
|
---|
[1b2d30] | 213 | input << Tremolo_Atomdata2;
|
---|
[9131f3] | 214 | testParser->load(&input);
|
---|
[d74077] | 215 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
|
---|
[4415da] | 216 | input.clear();
|
---|
[b8d4a3] | 217 | }
|
---|
[4415da] | 218 |
|
---|
[b8d4a3] | 219 | void ParserUnitTest::readTremoloVelocityTest() {
|
---|
| 220 | TremoloParser* testParser = new TremoloParser();
|
---|
| 221 | stringstream input;
|
---|
| 222 |
|
---|
| 223 | // One simple data line
|
---|
[1b2d30] | 224 | input << Tremolo_velocity;
|
---|
[b8d4a3] | 225 | testParser->load(&input);
|
---|
[d74077] | 226 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
|
---|
[b8d4a3] | 227 | input.clear();
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | void ParserUnitTest::readTremoloNeighborInformationTest() {
|
---|
| 231 | TremoloParser* testParser = new TremoloParser();
|
---|
| 232 | stringstream input;
|
---|
| 233 |
|
---|
| 234 | // Neighbor data
|
---|
[1b2d30] | 235 | input << Tremolo_neighbours;
|
---|
[b8d4a3] | 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 |
|
---|
| 244 | void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
|
---|
| 245 | TremoloParser* testParser = new TremoloParser();
|
---|
| 246 | stringstream input, output;
|
---|
| 247 |
|
---|
| 248 | // Neighbor data
|
---|
[1b2d30] | 249 | input << Tremolo_improper;
|
---|
[4415da] | 250 | testParser->load(&input);
|
---|
[b8d4a3] | 251 | testParser->save(&output);
|
---|
| 252 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 253 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
[4415da] | 254 | input.clear();
|
---|
[b8d4a3] | 255 | output.clear();
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
|
---|
| 259 | TremoloParser* testParser = new TremoloParser();
|
---|
| 260 | stringstream input, output;
|
---|
| 261 |
|
---|
| 262 | // Neighbor data
|
---|
[1b2d30] | 263 | input << Tremolo_torsion;
|
---|
[b8d4a3] | 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 |
|
---|
| 272 | void 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();
|
---|
[d74077] | 278 | newAtom->setType(1);
|
---|
[b8d4a3] | 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);
|
---|
[1b2d30] | 281 | CPPUNIT_ASSERT(output.str() == Tremolo_full);
|
---|
[4415da] | 282 |
|
---|
[9131f3] | 283 | cout << "testing the tremolo parser is done" << endl;
|
---|
| 284 | }
|
---|
[1b2d30] | 285 |
|
---|
| 286 | void 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 |
|
---|
| 307 | void ParserUnitTest::writeMpqcTest() {
|
---|
| 308 | // build up water molecule
|
---|
| 309 | atom *Walker = NULL;
|
---|
| 310 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 311 | Walker->setType(8);
|
---|
| 312 | Walker->setPosition(Vector(0,0,0));
|
---|
[1b2d30] | 313 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 314 | Walker->setType(1);
|
---|
| 315 | Walker->setPosition(Vector(0.758602,0,0.504284));
|
---|
[1b2d30] | 316 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 317 | Walker->setType(1);
|
---|
| 318 | Walker->setPosition(Vector(0.758602,0,-0.504284));
|
---|
[1b2d30] | 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
|
---|
[2fd80b5] | 328 | string first = input.str();
|
---|
| 329 | string second = output.str();
|
---|
| 330 | CPPUNIT_ASSERT(first == second);
|
---|
[1b2d30] | 331 | }
|
---|