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