| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [ab4b55] | 8 | /* | 
|---|
| [9e4fd1] | 9 | * ParserPcpUnitTest.cpp | 
|---|
| [ab4b55] | 10 | * | 
|---|
|  | 11 | *  Created on: Mar 3, 2010 | 
|---|
|  | 12 | *      Author: metzler | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [9e4fd1] | 20 | #include "ParserPcpUnitTest.hpp" | 
|---|
| [ab4b55] | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [1b2d30] | 26 | #include "Parser/PcpParser.hpp" | 
|---|
| [ab4b55] | 27 | #include "World.hpp" | 
|---|
| [b8d4a3] | 28 | #include "atom.hpp" | 
|---|
| [ab4b55] | 29 | #include "element.hpp" | 
|---|
|  | 30 | #include "periodentafel.hpp" | 
|---|
| [b8d4a3] | 31 | #include "Descriptors/AtomTypeDescriptor.hpp" | 
|---|
| [ab4b55] | 32 |  | 
|---|
|  | 33 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 34 | #include "UnitTestMain.hpp" | 
|---|
|  | 35 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 36 |  | 
|---|
|  | 37 | using namespace std; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | // Registers the fixture into the 'registry' | 
|---|
| [9e4fd1] | 40 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserPcpUnitTest ); | 
|---|
| [ab4b55] | 41 |  | 
|---|
| [1b2d30] | 42 | static string waterPcp = "# ParallelCarParinello - main configuration file - created with molecuilder\n\ | 
|---|
|  | 43 | \n\ | 
|---|
|  | 44 | mainname\tpcp\t# programm name (for runtime files)\n\ | 
|---|
|  | 45 | defaultpath\not specified\t# where to put files during runtime\n\ | 
|---|
|  | 46 | pseudopotpath\not specified\t# where to find pseudopotentials\n\ | 
|---|
|  | 47 | \n\ | 
|---|
|  | 48 | ProcPEGamma\t8\t# for parallel computing: share constants\n\ | 
|---|
|  | 49 | ProcPEPsi\t1\t# for parallel computing: share wave functions\n\ | 
|---|
|  | 50 | DoOutVis\t0\t# Output data for OpenDX\n\ | 
|---|
|  | 51 | DoOutMes\t1\t# Output data for measurements\n\ | 
|---|
|  | 52 | DoOutOrbitals\t0\t# Output all Orbitals\n\ | 
|---|
|  | 53 | DoOutCurr\t0\t# Ouput current density for OpenDx\n\ | 
|---|
|  | 54 | DoOutNICS\t0\t# Output Nucleus independent current shieldings\n\ | 
|---|
|  | 55 | DoPerturbation\t0\t# Do perturbation calculate and determine susceptibility and shielding\n\ | 
|---|
|  | 56 | DoFullCurrent\t0\t# Do full perturbation\n\ | 
|---|
|  | 57 | DoConstrainedMD\t0\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD\n\ | 
|---|
|  | 58 | Thermostat\tBerendsen\t2.5\t# Which Thermostat and its parameters to use in MD case.\n\ | 
|---|
| [9e4fd1] | 59 | PcpWannier\t0\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center\n\ | 
|---|
| [1b2d30] | 60 | SawtoothStart\t0.01\t# Absolute value for smooth transition at cell border \n\ | 
|---|
|  | 61 | VectorPlane\t0\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot\n\ | 
|---|
|  | 62 | VectorCut\t0\t# Cut plane axis value\n\ | 
|---|
|  | 63 | AddGramSch\t1\t# Additional GramSchmidtOrtogonalization to be safe\n\ | 
|---|
|  | 64 | Seed\t1\t# initial value for random seed for Psi coefficients\n\ | 
|---|
|  | 65 | \n\ | 
|---|
|  | 66 | MaxOuterStep\t0\t# number of MolecularDynamics/Structure optimization steps\n\ | 
|---|
|  | 67 | Deltat\t0.01\t# time per MD step\n\ | 
|---|
|  | 68 | OutVisStep\t10\t# Output visual data every ...th step\n\ | 
|---|
|  | 69 | OutSrcStep\t5\t# Output \"restart\" data every ..th step\n\ | 
|---|
|  | 70 | TargetTemp\t0.000950045\t# Target temperature\n\ | 
|---|
|  | 71 | MaxPsiStep\t3\t# number of Minimisation steps per state (0 - default)\n\ | 
|---|
|  | 72 | EpsWannier\t1e-07\t# tolerance value for spread minimisation of orbitals\n\ | 
|---|
|  | 73 | # Values specifying when to stop\n\ | 
|---|
|  | 74 | MaxMinStep\t100\t# Maximum number of steps\n\ | 
|---|
|  | 75 | RelEpsTotalE\t1e-07\t# relative change in total energy\n\ | 
|---|
|  | 76 | RelEpsKineticE\t1e-05\t# relative change in kinetic energy\n\ | 
|---|
| [2fd80b5] | 77 | MaxMinStopStep\t2\t# check every ..th steps\n\ | 
|---|
| [1b2d30] | 78 | MaxMinGapStopStep\t1\t# check every ..th steps\n\ | 
|---|
|  | 79 | \n\ | 
|---|
|  | 80 | # Values specifying when to stop for INIT, otherwise same as above\n\ | 
|---|
|  | 81 | MaxInitMinStep\t100\t# Maximum number of steps\n\ | 
|---|
|  | 82 | InitRelEpsTotalE\t1e-05\t# relative change in total energy\n\ | 
|---|
|  | 83 | InitRelEpsKineticE\t0.0001\t# relative change in kinetic energy\n\ | 
|---|
| [2fd80b5] | 84 | InitMaxMinStopStep\t2\t# check every ..th steps\n\ | 
|---|
| [1b2d30] | 85 | InitMaxMinGapStopStep\t1\t# check every ..th steps\n\ | 
|---|
|  | 86 | \n\ | 
|---|
|  | 87 | BoxLength\t# (Length of a unit cell)\n\ | 
|---|
|  | 88 | 20\n\ | 
|---|
|  | 89 | 0\t20\n\ | 
|---|
|  | 90 | 0\t0\t20\n\ | 
|---|
|  | 91 | \n\ | 
|---|
|  | 92 | ECut\t128\t# energy cutoff for discretization in Hartrees\n\ | 
|---|
|  | 93 | MaxLevel\t5\t# number of different levels in the code, >=2\n\ | 
|---|
|  | 94 | Level0Factor\t2\t# factor by which node number increases from S to 0 level\n\ | 
|---|
|  | 95 | RiemannTensor\t0\t# (Use metric)\n\ | 
|---|
|  | 96 | PsiType\t0\t# 0 - doubly occupied, 1 - SpinUp,SpinDown\n\ | 
|---|
| [2fd80b5] | 97 | MaxPsiDouble\t2\t# here: specifying both maximum number of SpinUp- and -Down-states\n\ | 
|---|
|  | 98 | PsiMaxNoUp\t2\t# here: specifying maximum number of SpinUp-states\n\ | 
|---|
|  | 99 | PsiMaxNoDown\t2\t# here: specifying maximum number of SpinDown-states\n\ | 
|---|
| [1b2d30] | 100 | AddPsis\t0\t# Additional unoccupied Psis for bandgap determination\n\ | 
|---|
|  | 101 | \n\ | 
|---|
|  | 102 | RCut\t20\t# R-cut for the ewald summation\n\ | 
|---|
|  | 103 | StructOpt\t0\t# Do structure optimization beforehand\n\ | 
|---|
|  | 104 | IsAngstroem\t1\t# 0 - Bohr, 1 - Angstroem\n\ | 
|---|
|  | 105 | RelativeCoord\t0\t# whether ion coordinates are relative (1) or absolute (0)\n\ | 
|---|
|  | 106 | MaxTypes\t2\t# maximum number of different ion types\n\ | 
|---|
|  | 107 | \n\ | 
|---|
|  | 108 | # Ion type data (PP = PseudoPotential, Z = atomic number)\n\ | 
|---|
|  | 109 | #Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol\n\ | 
|---|
|  | 110 | Ion_Type1\t2\t1\t1.0\t3\t3\t1.008\tHydrogen\tH\n\ | 
|---|
|  | 111 | Ion_Type2\t1\t8\t1.0\t3\t3\t15.999\tOxygen\tO\n\ | 
|---|
|  | 112 | #Ion_TypeNr._Nr.R[0]\tR[1]\tR[2]\tMoveType (0 MoveIon, 1 FixedIon)\n\ | 
|---|
| [6a465e] | 113 | Ion_Type2_1\t1.000000000\t0.000000000\t0.000000000\t0 # molecule nr 0\n\ | 
|---|
| [1b2d30] | 114 | Ion_Type1_1\t0.758602\t0.000000000\t0.504284\t0 # molecule nr 1\n\ | 
|---|
|  | 115 | Ion_Type1_2\t0.758602\t0.000000000\t-0.504284\t0 # molecule nr 2\n"; | 
|---|
| [4fbca9c] | 116 |  | 
|---|
| [9e4fd1] | 117 | void ParserPcpUnitTest::setUp() { | 
|---|
| [4eb4fe] | 118 | World::getInstance(); | 
|---|
| [1b2d30] | 119 |  | 
|---|
| [4fbca9c] | 120 | setVerbosity(2); | 
|---|
|  | 121 |  | 
|---|
| [1b2d30] | 122 | // we need hydrogens and oxygens in the following tests | 
|---|
|  | 123 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL); | 
|---|
|  | 124 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL); | 
|---|
| [ab4b55] | 125 | } | 
|---|
|  | 126 |  | 
|---|
| [9e4fd1] | 127 | void ParserPcpUnitTest::tearDown() { | 
|---|
| [2f40c0e] | 128 | ChangeTracker::purgeInstance(); | 
|---|
| [b8d4a3] | 129 | World::purgeInstance(); | 
|---|
| [ab4b55] | 130 | } | 
|---|
|  | 131 |  | 
|---|
|  | 132 | /************************************ tests ***********************************/ | 
|---|
|  | 133 |  | 
|---|
| [9e4fd1] | 134 | void ParserPcpUnitTest::readwritePcpTest() { | 
|---|
| [4fbca9c] | 135 | stringstream input(waterPcp); | 
|---|
|  | 136 | PcpParser* testParser = new PcpParser(); | 
|---|
| [b8d4a3] | 137 | testParser->load(&input); | 
|---|
|  | 138 | input.clear(); | 
|---|
|  | 139 |  | 
|---|
|  | 140 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
|  | 141 |  | 
|---|
| [4fbca9c] | 142 | // check that equality function is ok | 
|---|
|  | 143 | CPPUNIT_ASSERT(*testParser == *testParser); | 
|---|
| [b8d4a3] | 144 |  | 
|---|
| [4fbca9c] | 145 | stringstream output; | 
|---|
| [73916f] | 146 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 147 | testParser->save(&output, atoms); | 
|---|
| [b8d4a3] | 148 |  | 
|---|
| [4fbca9c] | 149 | input << output.str(); | 
|---|
|  | 150 | PcpParser* testParser2 = new PcpParser(); | 
|---|
|  | 151 | testParser2->load(&input); | 
|---|
| [b8d4a3] | 152 |  | 
|---|
| [4fbca9c] | 153 | CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms()); | 
|---|
| [4415da] | 154 |  | 
|---|
| [4fbca9c] | 155 | CPPUNIT_ASSERT(*testParser == *testParser2); | 
|---|
| [9131f3] | 156 | } | 
|---|