source: src/Parser/unittests/ParserXyzUnitTest.cpp@ e0f8c8

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 v1.1.4
Last change on this file since e0f8c8 was 255829, checked in by Frederik Heber <heber@…>, 14 years ago

Removed Helpers.hpp, deleted Helpers.cpp and libMoleCuilderHelpers.la is history.

  • defs.cpp is now compiled into libmolecuilder.la.
  • ShapeUnitTest alone needs defs.cpp.
  • Most changes are removal of Helpers/helpers.hpp.
  • performCriticalExit() now inline function in Helpers/helpers.hpp.
  • also inclusion possible where performCriticalExit() is needed.
  • Helpers/helpers.hpp does not include defs.hpp anymore and this causes lots of missing Helpers/defs.hpp, CodePatterns/Log.hpp and alikes.
  • removed src/Helpers from configure.ac.
  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[9e4fd1]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
8/*
9 * ParserXyzUnitTest.cpp
10 *
11 * Created on: Mar 3, 2010
12 * Author: metzler
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "ParserXyzUnitTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "Parser/XyzParser.hpp"
27#include "World.hpp"
28#include "atom.hpp"
29#include "element.hpp"
30#include "periodentafel.hpp"
[255829]31#include "CodePatterns/Log.hpp"
[9e4fd1]32#include "Descriptors/AtomTypeDescriptor.hpp"
33
34#ifdef HAVE_TESTRUNNER
35#include "UnitTestMain.hpp"
36#endif /*HAVE_TESTRUNNER*/
37
38using namespace std;
39
40// Registers the fixture into the 'registry'
41CPPUNIT_TEST_SUITE_REGISTRATION( ParserXyzUnitTest );
42
[0180d6]43static string waterXyz = "\
443\n\
45\tH2O: water molecule\n\
46O\t0\t0\t0\n\
47H\t0.758602\t0\t0.504284\n\
48H\t0.758602\t0\t-0.504284\n";
49static string waterMultiXyz = "\
503\n\
51\tH2O: water molecule, time step 0\n\
52O\t0\t0\t0\n\
53H\t0.758602\t0\t0.504284\n\
54H\t0.758602\t0\t-0.504284\n\
553\n\
56\tH2O: water molecule, time step 1\n\
57O\t0\t0\t0\n\
58H\t0.76\t0\t0.504284\n\
59H\t0.756\t0\t-0.504284\n";
[9e4fd1]60
61void ParserXyzUnitTest::setUp() {
62 World::getInstance();
63
64 setVerbosity(2);
65
66 // we need hydrogens and oxygens in the following tests
67 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
68 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
69}
70
71void ParserXyzUnitTest::tearDown() {
72 ChangeTracker::purgeInstance();
73 World::purgeInstance();
74}
75
76/************************************ tests ***********************************/
77
78void ParserXyzUnitTest::rewriteAnXyzTest() {
79 cout << "Testing the XYZ parser." << endl;
80 XyzParser* testParser = new XyzParser();
81 stringstream input;
82 input << waterXyz;
83 testParser->load(&input);
84 input.clear();
85
86 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
87
88 // store and parse in again
89 {
90 stringstream output;
91 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
92 testParser->save(&output, atoms);
93 input << output.str();
94 testParser->load(&input);
95 }
96
97 // now twice as many
98 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
99
100 // check every atom
101 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
102 std::vector<atom *>::const_iterator firstiter = atoms.begin();
103 std::vector<atom *>::const_iterator seconditer = atoms.begin();
104 for (size_t i=0;i<3;i++)
105 ++seconditer;
106 for (;
107 seconditer != atoms.end();
108 ++firstiter,++seconditer) {
109 // check position and type (only stuff xyz stores)
110 CPPUNIT_ASSERT_EQUAL((*firstiter)->getPosition(),(*seconditer)->getPosition());
111 CPPUNIT_ASSERT_EQUAL((*firstiter)->getType(),(*seconditer)->getType());
112 }
113}
[0180d6]114
115void ParserXyzUnitTest::readMultiXyzTest() {
116 cout << "Testing the multi time step XYZ parser." << endl;
117 XyzParser* testParser = new XyzParser();
118 stringstream input;
119 input << waterMultiXyz;
120 testParser->load(&input);
121 input.clear();
122
123 // 3 not 6 atoms!
124 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
125
126 // check for trajectory size
127 BOOST_FOREACH (atom *_atom, World::getInstance().getAllAtoms())
128 CPPUNIT_ASSERT_EQUAL((size_t) 2, _atom->getTrajectorySize());
129}
130
131void ParserXyzUnitTest::writeMultiXyzTest() {
132 XyzParser* testParser = new XyzParser();
133 stringstream input;
134 input << waterMultiXyz;
135 testParser->load(&input);
136 input.clear();
137
138 // 3 not 6 atoms!
139 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
140
141 // store and parse in again
142 {
143 stringstream output;
144 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
145 testParser->save(&output, atoms);
146 input << output.str();
147 testParser->load(&input);
148 }
149
150 // now twice as many
151 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
152
153 // check for trajectory size of all 6! atoms
154 BOOST_FOREACH (atom *_atom, World::getInstance().getAllAtoms())
155 CPPUNIT_ASSERT_EQUAL((size_t) 2, _atom->getTrajectorySize());
156
157 // check every atom
158 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
159 std::vector<atom *>::const_iterator firstiter = atoms.begin();
160 std::vector<atom *>::const_iterator seconditer = atoms.begin();
161 for (size_t i=0;i<3;i++)
162 ++seconditer;
163 for (;
164 seconditer != atoms.end();
165 ++firstiter,++seconditer) {
166 CPPUNIT_ASSERT_EQUAL((*firstiter)->getType(),(*seconditer)->getType());
167 for (unsigned int step = 0; step < 2; ++step) {
168 // check position and type (only stuff xyz stores)
169 CPPUNIT_ASSERT_EQUAL(
170 (*firstiter)->getPositionAtStep(step),
171 (*seconditer)->getPositionAtStep(step));
172 }
173 }
174}
Note: See TracBrowser for help on using the repository browser.