source: src/Parser/unittests/ParserTremoloUnitTest.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 ccb487, checked in by Frederik Heber <heber@…>, 13 years ago

TremoloParser now always writes current domain as "# Box ..." into file.

  • 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 "Descriptors/AtomTypeDescriptor.hpp"
28#include "Element/element.hpp"
29#include "Element/periodentafel.hpp"
30#include "Parser/TremoloParser.hpp"
31#include "Parser/ChangeTracker.hpp"
32#include "World.hpp"
33#include "WorldTime.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( ParserTremoloUnitTest );
43
44static string Tremolo_Atomdata1 = "\
45# ATOMDATA\tId\tname\ttype\tx=3\n\
46# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
47static string Tremolo_Atomdata2 = "\
48#\n\
49#ATOMDATA Id name type x=3\n\
50# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
511 hydrogen H 3.0 4.5 0.1\n\
52\n";
53static string Tremolo_invalidkey = "\
54#\n\
55#ATOMDATA Id name foo type x=3\n\
56# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
57\n\n";
58static string Tremolo_velocity = "\
59#\n\
60#ATOMDATA Id name type u=3\n\
61# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
621 hydrogen H 3.0 4.5 0.1\n\
63\n";
64static string Tremolo_neighbours = "#\n\
65#ATOMDATA Id type neighbors=2\n\
66# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
671 H 3 0\n\
682 H 3 0\n\
693 O 1 2\n";
70static string Tremolo_improper = "\
71#\n\
72#ATOMDATA Id type imprData\n\
73# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
748 H 9-10\n\
759 H 10-8,8-10\n\
7610 O -\n";
77static string Tremolo_torsion = "\
78#\n\
79#ATOMDATA Id type torsion\n\
80# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
818 H 9-10\n\
829 H 10-8,8-10\n\
8310 O -\n";
84static string Tremolo_full = "\
85# 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\
86# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
870\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";
88
89void ParserTremoloUnitTest::setUp() {
90 World::getInstance();
91
92 parser = new FormatParser<tremolo>();
93
94 // we need hydrogens and oxygens in the following tests
95 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
96 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
97}
98
99void ParserTremoloUnitTest::tearDown()
100{
101 delete parser;
102 ChangeTracker::purgeInstance();
103 World::purgeInstance();
104}
105
106/************************************ tests ***********************************/
107
108void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
109 cout << "Testing the tremolo parser." << endl;
110 stringstream input, output;
111
112 // Atomdata beginning with "# ATOMDATA"
113 {
114 input << Tremolo_Atomdata1;
115 parser->load(&input);
116 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
117 parser->save(&output, atoms);
118// std::cout << output.str() << std::endl;
119// std::cout << Tremolo_Atomdata1 << std::endl;
120 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
121 input.clear();
122 output.clear();
123 }
124
125 // Atomdata beginning with "#ATOMDATA"
126 {
127 input << Tremolo_Atomdata2;
128 parser->load(&input);
129 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
130 parser->save(&output, atoms);
131 std::cout << output.str() << std::endl;
132 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
133 input.clear();
134 output.clear();
135 }
136
137 // Invalid key in Atomdata line
138 input << Tremolo_invalidkey;
139 parser->load(&input);
140 //TODO: prove invalidity
141 input.clear();
142}
143
144void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
145 stringstream input;
146
147 // One simple data line
148 input << Tremolo_Atomdata2;
149 parser->load(&input);
150 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
151 input.clear();
152}
153
154void ParserTremoloUnitTest::readTremoloVelocityTest() {
155 stringstream input;
156
157 // One simple data line
158 input << Tremolo_velocity;
159 parser->load(&input);
160 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
161 input.clear();
162}
163
164void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
165 stringstream input;
166
167 // Neighbor data
168 input << Tremolo_neighbours;
169 parser->load(&input);
170
171 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
172 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
173 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
174 input.clear();
175}
176
177void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
178 stringstream input, output;
179
180 // Neighbor data
181 {
182 input << Tremolo_improper;
183 parser->load(&input);
184 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
185 parser->save(&output, atoms);
186 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
187 std::cout << output.str() << std::endl;
188 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
189 input.clear();
190 output.clear();
191 }
192}
193
194void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
195 stringstream input, output;
196
197 // Neighbor data
198 {
199 input << Tremolo_torsion;
200 parser->load(&input);
201 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
202 parser->save(&output, atoms);
203 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
204 std::cout << output.str() << std::endl;
205 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
206 input.clear();
207 output.clear();
208 }
209}
210
211void ParserTremoloUnitTest::writeTremoloTest() {
212 stringstream output;
213
214 // with the maximum number of fields and minimal information, default values are printed
215 {
216 atom* newAtom = World::getInstance().createAtom();
217 newAtom->setType(1);
218 parser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
219 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
220 parser->save(&output, atoms);
221// std::cout << output.str() << std::endl;
222// std::cout << Tremolo_full << std::endl;
223 CPPUNIT_ASSERT(output.str() == Tremolo_full);
224 }
225
226 cout << "testing the tremolo parser is done" << endl;
227}
228
Note: See TracBrowser for help on using the repository browser.