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