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

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
Last change on this file since b3d687 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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 "World.hpp"
27#include "Atom/atom.hpp"
28#include "Element/element.hpp"
29#include "Element/periodentafel.hpp"
30#include "CodePatterns/Log.hpp"
31#include "Descriptors/AtomTypeDescriptor.hpp"
32#include "Parser/ChangeTracker.hpp"
33#include "Parser/XyzParser.hpp"
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39using namespace std;
40
41// Registers the fixture into the 'registry'
42CPPUNIT_TEST_SUITE_REGISTRATION( ParserXyzUnitTest );
43
44static string waterXyz = "\
453\n\
46\tH2O: water molecule\n\
47O\t0\t0\t0\n\
48H\t0.758602\t0\t0.504284\n\
49H\t0.758602\t0\t-0.504284\n";
50static string waterMultiXyz = "\
513\n\
52\tH2O: water molecule, time step 0\n\
53O\t0\t0\t0\n\
54H\t0.758602\t0\t0.504284\n\
55H\t0.758602\t0\t-0.504284\n\
563\n\
57\tH2O: water molecule, time step 1\n\
58O\t0\t0\t0\n\
59H\t0.76\t0\t0.504284\n\
60H\t0.756\t0\t-0.504284\n";
61
62void ParserXyzUnitTest::setUp() {
63 World::getInstance();
64
65 parser = new FormatParser<xyz>();
66
67 setVerbosity(2);
68
69 // we need hydrogens and oxygens in the following tests
70 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
71 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
72}
73
74void ParserXyzUnitTest::tearDown()
75{
76 delete parser;
77 ChangeTracker::purgeInstance();
78 World::purgeInstance();
79}
80
81/************************************ tests ***********************************/
82
83void ParserXyzUnitTest::rewriteAnXyzTest() {
84 cout << "Testing the XYZ parser." << endl;
85 stringstream input;
86 input << waterXyz;
87 parser->load(&input);
88 input.clear();
89
90 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
91
92 // store and parse in again
93 {
94 stringstream output;
95 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
96 parser->save(&output, atoms);
97 input << output.str();
98 parser->load(&input);
99 }
100
101 // now twice as many
102 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
103
104 // check every atom
105 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
106 std::vector<atom *>::const_iterator firstiter = atoms.begin();
107 std::vector<atom *>::const_iterator seconditer = atoms.begin();
108 for (size_t i=0;i<3;i++)
109 ++seconditer;
110 for (;
111 seconditer != atoms.end();
112 ++firstiter,++seconditer) {
113 // check position and type (only stuff xyz stores)
114 CPPUNIT_ASSERT_EQUAL((*firstiter)->getPosition(),(*seconditer)->getPosition());
115 CPPUNIT_ASSERT_EQUAL((*firstiter)->getType(),(*seconditer)->getType());
116 }
117}
118
119void ParserXyzUnitTest::readMultiXyzTest() {
120 cout << "Testing the multi time step XYZ parser." << endl;
121 stringstream input;
122 input << waterMultiXyz;
123 parser->load(&input);
124 input.clear();
125
126 // 3 not 6 atoms!
127 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
128
129 // check for trajectory size
130 BOOST_FOREACH (atom *_atom, World::getInstance().getAllAtoms())
131 CPPUNIT_ASSERT_EQUAL((size_t) 2, _atom->getTrajectorySize());
132}
133
134void ParserXyzUnitTest::writeMultiXyzTest() {
135 stringstream input;
136 input << waterMultiXyz;
137 parser->load(&input);
138 input.clear();
139
140 // 3 not 6 atoms!
141 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
142
143 // store and parse in again
144 {
145 stringstream output;
146 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
147 parser->save(&output, atoms);
148 input << output.str();
149 parser->load(&input);
150 }
151
152 // now twice as many
153 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
154
155 // check for trajectory size of all 6! atoms
156 BOOST_FOREACH (atom *_atom, World::getInstance().getAllAtoms())
157 CPPUNIT_ASSERT_EQUAL((size_t) 2, _atom->getTrajectorySize());
158
159 // check every atom
160 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
161 std::vector<atom *>::const_iterator firstiter = atoms.begin();
162 std::vector<atom *>::const_iterator seconditer = atoms.begin();
163 for (size_t i=0;i<3;i++)
164 ++seconditer;
165 for (;
166 seconditer != atoms.end();
167 ++firstiter,++seconditer) {
168 CPPUNIT_ASSERT_EQUAL((*firstiter)->getType(),(*seconditer)->getType());
169 for (unsigned int step = 0; step < 2; ++step) {
170 // check position and type (only stuff xyz stores)
171 CPPUNIT_ASSERT_EQUAL(
172 (*firstiter)->getPositionAtStep(step),
173 (*seconditer)->getPositionAtStep(step));
174 }
175 }
176}
Note: See TracBrowser for help on using the repository browser.