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

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

Merge branch 'Adding_Psi3Parser' into stable

Conflicts:

src/Parser/FormatParser.hpp
src/Parser/unittests/ParserTremoloUnitTest.cpp

Issues:

  • Element and periodentafel have been moved to folder src/Element.
  • Property mode set to 100644
File size: 6.0 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/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";
46static string Tremolo_Atomdata2 = "\
47#\n\
48#ATOMDATA Id name type x=3\n\
491 hydrogen H 3.0 4.5 0.1\n\
50\n";
51static string Tremolo_invalidkey = "\
52#\n\
53#ATOMDATA Id name foo type x=3\n\
54\n\n";
55static string Tremolo_velocity = "\
56#\n\
57#ATOMDATA Id name type u=3\n\
581 hydrogen H 3.0 4.5 0.1\n\
59\n";
60static string Tremolo_neighbours = "#\n\
61#ATOMDATA Id type neighbors=2\n\
621 H 3 0\n\
632 H 3 0\n\
643 O 1 2\n";
65static string Tremolo_improper = "\
66#\n\
67#ATOMDATA Id type imprData\n\
688 H 9-10\n\
699 H 10-8,8-10\n\
7010 O -\n";
71static string Tremolo_torsion = "\
72#\n\
73#ATOMDATA Id type torsion\n\
748 H 9-10\n\
759 H 10-8,8-10\n\
7610 O -\n";
77static string Tremolo_full = "\
78# 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\
790\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";
80
81void ParserTremoloUnitTest::setUp() {
82 World::getInstance();
83
84 parser = new FormatParser<tremolo>();
85
86 // we need hydrogens and oxygens in the following tests
87 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
88 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
89}
90
91void ParserTremoloUnitTest::tearDown()
92{
93 delete parser;
94 ChangeTracker::purgeInstance();
95 World::purgeInstance();
96}
97
98/************************************ tests ***********************************/
99
100void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
101 cout << "Testing the tremolo parser." << endl;
102 stringstream input, output;
103
104 // Atomdata beginning with "# ATOMDATA"
105 {
106 input << Tremolo_Atomdata1;
107 parser->load(&input);
108 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
109 parser->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 parser->load(&input);
121 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
122 parser->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 parser->load(&input);
132 //TODO: prove invalidity
133 input.clear();
134}
135
136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
137 stringstream input;
138
139 // One simple data line
140 input << Tremolo_Atomdata2;
141 parser->load(&input);
142 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
143 input.clear();
144}
145
146void ParserTremoloUnitTest::readTremoloVelocityTest() {
147 stringstream input;
148
149 // One simple data line
150 input << Tremolo_velocity;
151 parser->load(&input);
152 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
153 input.clear();
154}
155
156void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
157 stringstream input;
158
159 // Neighbor data
160 input << Tremolo_neighbours;
161 parser->load(&input);
162
163 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
164 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
165 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
166 input.clear();
167}
168
169void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
170 stringstream input, output;
171
172 // Neighbor data
173 {
174 input << Tremolo_improper;
175 parser->load(&input);
176 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
177 parser->save(&output, atoms);
178 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
179 std::cout << output.str() << std::endl;
180 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
181 input.clear();
182 output.clear();
183 }
184}
185
186void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
187 stringstream input, output;
188
189 // Neighbor data
190 {
191 input << Tremolo_torsion;
192 parser->load(&input);
193 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
194 parser->save(&output, atoms);
195 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
196 std::cout << output.str() << std::endl;
197 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
198 input.clear();
199 output.clear();
200 }
201}
202
203void ParserTremoloUnitTest::writeTremoloTest() {
204 stringstream output;
205
206 // with the maximum number of fields and minimal information, default values are printed
207 {
208 atom* newAtom = World::getInstance().createAtom();
209 newAtom->setType(1);
210 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");
211 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
212 parser->save(&output, atoms);
213 CPPUNIT_ASSERT(output.str() == Tremolo_full);
214 }
215
216 cout << "testing the tremolo parser is done" << endl;
217}
218
Note: See TracBrowser for help on using the repository browser.