source: src/Parser/unittests/ParserTremoloUnitTest.cpp@ 305e7e

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 305e7e was 305e7e, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: Type is actually spelled type with TREMOLO.

  • 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 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.hpp"
27#include "Descriptors/AtomTypeDescriptor.hpp"
28#include "element.hpp"
29#include "Parser/MpqcParser.hpp"
30#include "Parser/PdbParser.hpp"
31#include "Parser/PcpParser.hpp"
32#include "Parser/TremoloParser.hpp"
33#include "Parser/XyzParser.hpp"
34#include "periodentafel.hpp"
35#include "World.hpp"
36#include "WorldTime.hpp"
37
38#ifdef HAVE_TESTRUNNER
39#include "UnitTestMain.hpp"
40#endif /*HAVE_TESTRUNNER*/
41
42using namespace std;
43
44// Registers the fixture into the 'registry'
45CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest );
46
47static string Tremolo_Atomdata1 = "\
48# ATOMDATA\tId\tname\ttype\tx=3\n";
49static string Tremolo_Atomdata2 = "\
50#\n\
51#ATOMDATA Id name type x=3\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\n\n";
58static string Tremolo_velocity = "\
59#\n\
60#ATOMDATA Id name type u=3\n\
611 hydrogen H 3.0 4.5 0.1\n\
62\n";
63static string Tremolo_neighbours = "#\n\
64#ATOMDATA Id type neighbors=2\n\
651 H 3 0\n\
662 H 3 0\n\
673 O 1 2\n";
68static string Tremolo_improper = "\
69#\n\
70#ATOMDATA Id type imprData\n\
718 H 9-10\n\
729 H 10-8,8-10\n\
7310 O -\n";
74static string Tremolo_torsion = "\
75#\n\
76#ATOMDATA Id type torsion\n\
778 H 9-10\n\
789 H 10-8,8-10\n\
7910 O -\n";
80static string Tremolo_full = "\
81# 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\
820\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";
83
84void ParserTremoloUnitTest::setUp() {
85 World::getInstance();
86
87 // we need hydrogens and oxygens in the following tests
88 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
89 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
90}
91
92void ParserTremoloUnitTest::tearDown() {
93 ChangeTracker::purgeInstance();
94 World::purgeInstance();
95}
96
97/************************************ tests ***********************************/
98
99void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
100 cout << "Testing the tremolo parser." << endl;
101 TremoloParser* testParser = new TremoloParser();
102 stringstream input, output;
103
104 // Atomdata beginning with "# ATOMDATA"
105 {
106 input << Tremolo_Atomdata1;
107 testParser->load(&input);
108 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
109 testParser->save(&output, atoms);
110// std::cout << output.str() << std::endl;
111// std::cout << Tremolo_Atomdata1 << std::endl;
112 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
113 input.clear();
114 output.clear();
115 }
116
117 // Atomdata beginning with "#ATOMDATA"
118 {
119 input << Tremolo_Atomdata2;
120 testParser->load(&input);
121 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
122 testParser->save(&output, atoms);
123 std::cout << output.str() << std::endl;
124 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
125 input.clear();
126 output.clear();
127 }
128
129 // Invalid key in Atomdata line
130 input << Tremolo_invalidkey;
131 testParser->load(&input);
132 //TODO: prove invalidity
133 input.clear();
134}
135
136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
137 TremoloParser* testParser = new TremoloParser();
138 stringstream input;
139
140 // One simple data line
141 input << Tremolo_Atomdata2;
142 testParser->load(&input);
143 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
144 input.clear();
145}
146
147void ParserTremoloUnitTest::readTremoloVelocityTest() {
148 TremoloParser* testParser = new TremoloParser();
149 stringstream input;
150
151 // One simple data line
152 input << Tremolo_velocity;
153 testParser->load(&input);
154 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
155 input.clear();
156}
157
158void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
159 TremoloParser* testParser = new TremoloParser();
160 stringstream input;
161
162 // Neighbor data
163 input << Tremolo_neighbours;
164 testParser->load(&input);
165
166 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
167 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
168 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
169 input.clear();
170}
171
172void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
173 TremoloParser* testParser = new TremoloParser();
174 stringstream input, output;
175
176 // Neighbor data
177 {
178 input << Tremolo_improper;
179 testParser->load(&input);
180 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
181 testParser->save(&output, atoms);
182 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
183 std::cout << output.str() << std::endl;
184 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
185 input.clear();
186 output.clear();
187 }
188}
189
190void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
191 TremoloParser* testParser = new TremoloParser();
192 stringstream input, output;
193
194 // Neighbor data
195 {
196 input << Tremolo_torsion;
197 testParser->load(&input);
198 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
199 testParser->save(&output, atoms);
200 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
201 std::cout << output.str() << std::endl;
202 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
203 input.clear();
204 output.clear();
205 }
206}
207
208void ParserTremoloUnitTest::writeTremoloTest() {
209 TremoloParser* testParser = new TremoloParser();
210 stringstream output;
211
212 // with the maximum number of fields and minimal information, default values are printed
213 {
214 atom* newAtom = World::getInstance().createAtom();
215 newAtom->setType(1);
216 testParser->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");
217 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
218 testParser->save(&output, atoms);
219 CPPUNIT_ASSERT(output.str() == Tremolo_full);
220 }
221
222 cout << "testing the tremolo parser is done" << endl;
223}
Note: See TracBrowser for help on using the repository browser.