source: src/Parser/unittests/ParserTremoloUnitTest.cpp@ 006e1e

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 006e1e was 006e1e, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: ChangeTracker has not been observing AtomObserver so far.

  • This is introduced due to cleaning of observer structure.
  • FIX: Cleaned ChangeTracker declaration from false includes.
  • FIX: TextWindow.cpp lacked include World.
  • TESTFIX: All Parser...UnitTest needed to purge AtomObserver instance.
  • Property mode set to 100644
File size: 6.5 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 * ParserTremoloUnitTest.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 "ParserTremoloUnitTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "Atom/atom.hpp"
27#include "Atom/AtomObserver.hpp"
28#include "Descriptors/AtomTypeDescriptor.hpp"
29#include "Element/element.hpp"
30#include "Element/periodentafel.hpp"
31#include "Parser/TremoloParser.hpp"
32#include "Parser/ChangeTracker.hpp"
33#include "World.hpp"
34#include "WorldTime.hpp"
35
36#ifdef HAVE_TESTRUNNER
37#include "UnitTestMain.hpp"
38#endif /*HAVE_TESTRUNNER*/
39
40using namespace std;
41
42// Registers the fixture into the 'registry'
43CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest );
44
45static string Tremolo_Atomdata1 = "\
46# ATOMDATA\tId\tname\ttype\tx=3\n\
47# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
48static string Tremolo_Atomdata2 = "\
49#\n\
50#ATOMDATA Id name type x=3\n\
51# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
521 hydrogen H 3.0 4.5 0.1\n\
53\n";
54static string Tremolo_invalidkey = "\
55#\n\
56#ATOMDATA Id name foo type x=3\n\
57# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
58\n\n";
59static string Tremolo_velocity = "\
60#\n\
61#ATOMDATA Id name type u=3\n\
62# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
631 hydrogen H 3.0 4.5 0.1\n\
64\n";
65static string Tremolo_neighbours = "#\n\
66#ATOMDATA Id type neighbors=2\n\
67# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
681 H 3 0\n\
692 H 3 0\n\
703 O 1 2\n";
71static string Tremolo_improper = "\
72#\n\
73#ATOMDATA Id type imprData\n\
74# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
758 H 9-10\n\
769 H 10-8,8-10\n\
7710 O -\n";
78static string Tremolo_torsion = "\
79#\n\
80#ATOMDATA Id type torsion\n\
81# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
828 H 9-10\n\
839 H 10-8,8-10\n\
8410 O -\n";
85static string Tremolo_full = "\
86# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\ttype\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n\
87# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
880\t0\t0\t0\t0\t0\t0\t0\t1\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n";
89
90void ParserTremoloUnitTest::setUp() {
91 World::getInstance();
92
93 parser = new FormatParser<tremolo>();
94
95 // we need hydrogens and oxygens in the following tests
96 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
97 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
98}
99
100void ParserTremoloUnitTest::tearDown()
101{
102 delete parser;
103 ChangeTracker::purgeInstance();
104 AtomObserver::purgeInstance();
105 World::purgeInstance();
106}
107
108/************************************ tests ***********************************/
109
110void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
111 cout << "Testing the tremolo parser." << endl;
112 stringstream input, output;
113
114 // Atomdata beginning with "# ATOMDATA"
115 {
116 input << Tremolo_Atomdata1;
117 parser->load(&input);
118 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
119 parser->save(&output, atoms);
120// std::cout << output.str() << std::endl;
121// std::cout << Tremolo_Atomdata1 << std::endl;
122 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
123 input.clear();
124 output.clear();
125 }
126
127 // Atomdata beginning with "#ATOMDATA"
128 {
129 input << Tremolo_Atomdata2;
130 parser->load(&input);
131 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
132 parser->save(&output, atoms);
133 std::cout << output.str() << std::endl;
134 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
135 input.clear();
136 output.clear();
137 }
138
139 // Invalid key in Atomdata line
140 input << Tremolo_invalidkey;
141 parser->load(&input);
142 //TODO: prove invalidity
143 input.clear();
144}
145
146void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
147 stringstream input;
148
149 // One simple data line
150 input << Tremolo_Atomdata2;
151 parser->load(&input);
152 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
153 input.clear();
154}
155
156void ParserTremoloUnitTest::readTremoloVelocityTest() {
157 stringstream input;
158
159 // One simple data line
160 input << Tremolo_velocity;
161 parser->load(&input);
162 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
163 input.clear();
164}
165
166void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
167 stringstream input;
168
169 // Neighbor data
170 input << Tremolo_neighbours;
171 parser->load(&input);
172
173 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
174 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
175 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
176 input.clear();
177}
178
179void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
180 stringstream input, output;
181
182 // Neighbor data
183 {
184 input << Tremolo_improper;
185 parser->load(&input);
186 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
187 parser->save(&output, atoms);
188 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
189 std::cout << output.str() << std::endl;
190 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
191 input.clear();
192 output.clear();
193 }
194}
195
196void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
197 stringstream input, output;
198
199 // Neighbor data
200 {
201 input << Tremolo_torsion;
202 parser->load(&input);
203 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
204 parser->save(&output, atoms);
205 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
206 std::cout << output.str() << std::endl;
207 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
208 input.clear();
209 output.clear();
210 }
211}
212
213void ParserTremoloUnitTest::writeTremoloTest() {
214 stringstream output;
215
216 // with the maximum number of fields and minimal information, default values are printed
217 {
218 atom* newAtom = World::getInstance().createAtom();
219 newAtom->setType(1);
220 parser->setAtomData("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
221 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
222 parser->save(&output, atoms);
223// std::cout << output.str() << std::endl;
224// std::cout << Tremolo_full << std::endl;
225 CPPUNIT_ASSERT(output.str() == Tremolo_full);
226 }
227
228 cout << "testing the tremolo parser is done" << endl;
229}
230
Note: See TracBrowser for help on using the repository browser.