source: src/Parser/unittests/ParserTremoloUnitTest.cpp@ a636f8

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 a636f8 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
RevLine 
[4fbca9c]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[4fbca9c]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
[6f0841]26#include "Atom/atom.hpp"
[006e1e]27#include "Atom/AtomObserver.hpp"
[073a9e4]28#include "Descriptors/AtomTypeDescriptor.hpp"
[3bdb6d]29#include "Element/element.hpp"
30#include "Element/periodentafel.hpp"
[4fbca9c]31#include "Parser/TremoloParser.hpp"
[765f16]32#include "Parser/ChangeTracker.hpp"
[073a9e4]33#include "World.hpp"
34#include "WorldTime.hpp"
[4fbca9c]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
[4d4d33]45static string Tremolo_Atomdata1 = "\
[ccb487]46# ATOMDATA\tId\tname\ttype\tx=3\n\
47# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
[4d4d33]48static string Tremolo_Atomdata2 = "\
49#\n\
[305e7e]50#ATOMDATA Id name type x=3\n\
[ccb487]51# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]521 hydrogen H 3.0 4.5 0.1\n\
53\n";
54static string Tremolo_invalidkey = "\
55#\n\
[305e7e]56#ATOMDATA Id name foo type x=3\n\
[ccb487]57# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]58\n\n";
59static string Tremolo_velocity = "\
60#\n\
[305e7e]61#ATOMDATA Id name type u=3\n\
[ccb487]62# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]631 hydrogen H 3.0 4.5 0.1\n\
64\n";
65static string Tremolo_neighbours = "#\n\
[305e7e]66#ATOMDATA Id type neighbors=2\n\
[ccb487]67# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]681 H 3 0\n\
692 H 3 0\n\
703 O 1 2\n";
71static string Tremolo_improper = "\
72#\n\
[305e7e]73#ATOMDATA Id type imprData\n\
[ccb487]74# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]758 H 9-10\n\
769 H 10-8,8-10\n\
7710 O -\n";
78static string Tremolo_torsion = "\
79#\n\
[305e7e]80#ATOMDATA Id type torsion\n\
[ccb487]81# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]828 H 9-10\n\
839 H 10-8,8-10\n\
8410 O -\n";
85static string Tremolo_full = "\
[305e7e]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\
[ccb487]87# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]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";
[4fbca9c]89
90void ParserTremoloUnitTest::setUp() {
91 World::getInstance();
92
[765f16]93 parser = new FormatParser<tremolo>();
94
[4fbca9c]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
[765f16]100void ParserTremoloUnitTest::tearDown()
101{
102 delete parser;
[4fbca9c]103 ChangeTracker::purgeInstance();
[006e1e]104 AtomObserver::purgeInstance();
[4fbca9c]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"
[73916f]115 {
116 input << Tremolo_Atomdata1;
[765f16]117 parser->load(&input);
[73916f]118 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]119 parser->save(&output, atoms);
[4d4d33]120// std::cout << output.str() << std::endl;
121// std::cout << Tremolo_Atomdata1 << std::endl;
[73916f]122 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
123 input.clear();
124 output.clear();
125 }
[4fbca9c]126
127 // Atomdata beginning with "#ATOMDATA"
[73916f]128 {
129 input << Tremolo_Atomdata2;
[765f16]130 parser->load(&input);
[73916f]131 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]132 parser->save(&output, atoms);
[4d4d33]133 std::cout << output.str() << std::endl;
[73916f]134 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
135 input.clear();
136 output.clear();
137 }
[4fbca9c]138
139 // Invalid key in Atomdata line
140 input << Tremolo_invalidkey;
[765f16]141 parser->load(&input);
[73916f]142 //TODO: prove invalidity
[4fbca9c]143 input.clear();
144}
145
146void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
147 stringstream input;
148
149 // One simple data line
150 input << Tremolo_Atomdata2;
[765f16]151 parser->load(&input);
[4fbca9c]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;
[765f16]161 parser->load(&input);
[bce72c]162 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
[4fbca9c]163 input.clear();
164}
165
166void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
167 stringstream input;
168
169 // Neighbor data
170 input << Tremolo_neighbours;
[765f16]171 parser->load(&input);
[4fbca9c]172
173 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
174 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
[073a9e4]175 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
[4fbca9c]176 input.clear();
177}
178
179void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
180 stringstream input, output;
181
182 // Neighbor data
[73916f]183 {
184 input << Tremolo_improper;
[765f16]185 parser->load(&input);
[73916f]186 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]187 parser->save(&output, atoms);
[73916f]188 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[4d4d33]189 std::cout << output.str() << std::endl;
[73916f]190 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
191 input.clear();
192 output.clear();
193 }
[4fbca9c]194}
195
196void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
197 stringstream input, output;
198
199 // Neighbor data
[73916f]200 {
201 input << Tremolo_torsion;
[765f16]202 parser->load(&input);
[73916f]203 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]204 parser->save(&output, atoms);
[73916f]205 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[4d4d33]206 std::cout << output.str() << std::endl;
[73916f]207 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
208 input.clear();
209 output.clear();
210 }
[4fbca9c]211}
212
213void ParserTremoloUnitTest::writeTremoloTest() {
214 stringstream output;
215
216 // with the maximum number of fields and minimal information, default values are printed
[73916f]217 {
218 atom* newAtom = World::getInstance().createAtom();
219 newAtom->setType(1);
[23fd43]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");
[73916f]221 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]222 parser->save(&output, atoms);
[ccb487]223// std::cout << output.str() << std::endl;
224// std::cout << Tremolo_full << std::endl;
[73916f]225 CPPUNIT_ASSERT(output.str() == Tremolo_full);
226 }
[4fbca9c]227
228 cout << "testing the tremolo parser is done" << endl;
229}
[765f16]230
Note: See TracBrowser for help on using the repository browser.