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

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 d470a6 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
RevLine 
[4fbca9c]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
[073a9e4]26#include "atom.hpp"
27#include "Descriptors/AtomTypeDescriptor.hpp"
[3bdb6d]28#include "Element/element.hpp"
29#include "Element/periodentafel.hpp"
[4fbca9c]30#include "Parser/TremoloParser.hpp"
[765f16]31#include "Parser/ChangeTracker.hpp"
[073a9e4]32#include "World.hpp"
33#include "WorldTime.hpp"
[4fbca9c]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
[4d4d33]44static string Tremolo_Atomdata1 = "\
[305e7e]45# ATOMDATA\tId\tname\ttype\tx=3\n";
[4d4d33]46static string Tremolo_Atomdata2 = "\
47#\n\
[305e7e]48#ATOMDATA Id name type x=3\n\
[4d4d33]491 hydrogen H 3.0 4.5 0.1\n\
50\n";
51static string Tremolo_invalidkey = "\
52#\n\
[305e7e]53#ATOMDATA Id name foo type x=3\n\
[4d4d33]54\n\n";
55static string Tremolo_velocity = "\
56#\n\
[305e7e]57#ATOMDATA Id name type u=3\n\
[4d4d33]581 hydrogen H 3.0 4.5 0.1\n\
59\n";
60static string Tremolo_neighbours = "#\n\
[305e7e]61#ATOMDATA Id type neighbors=2\n\
[4d4d33]621 H 3 0\n\
632 H 3 0\n\
643 O 1 2\n";
65static string Tremolo_improper = "\
66#\n\
[305e7e]67#ATOMDATA Id type imprData\n\
[4d4d33]688 H 9-10\n\
699 H 10-8,8-10\n\
7010 O -\n";
71static string Tremolo_torsion = "\
72#\n\
[305e7e]73#ATOMDATA Id type torsion\n\
[4d4d33]748 H 9-10\n\
759 H 10-8,8-10\n\
7610 O -\n";
77static string Tremolo_full = "\
[305e7e]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\
[4d4d33]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";
[4fbca9c]80
81void ParserTremoloUnitTest::setUp() {
82 World::getInstance();
83
[765f16]84 parser = new FormatParser<tremolo>();
85
[4fbca9c]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
[765f16]91void ParserTremoloUnitTest::tearDown()
92{
93 delete parser;
[4fbca9c]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"
[73916f]105 {
106 input << Tremolo_Atomdata1;
[765f16]107 parser->load(&input);
[73916f]108 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]109 parser->save(&output, atoms);
[4d4d33]110// std::cout << output.str() << std::endl;
111// std::cout << Tremolo_Atomdata1 << std::endl;
[73916f]112 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
113 input.clear();
114 output.clear();
115 }
[4fbca9c]116
117 // Atomdata beginning with "#ATOMDATA"
[73916f]118 {
119 input << Tremolo_Atomdata2;
[765f16]120 parser->load(&input);
[73916f]121 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]122 parser->save(&output, atoms);
[4d4d33]123 std::cout << output.str() << std::endl;
[73916f]124 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
125 input.clear();
126 output.clear();
127 }
[4fbca9c]128
129 // Invalid key in Atomdata line
130 input << Tremolo_invalidkey;
[765f16]131 parser->load(&input);
[73916f]132 //TODO: prove invalidity
[4fbca9c]133 input.clear();
134}
135
136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
137 stringstream input;
138
139 // One simple data line
140 input << Tremolo_Atomdata2;
[765f16]141 parser->load(&input);
[4fbca9c]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;
[765f16]151 parser->load(&input);
[bce72c]152 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
[4fbca9c]153 input.clear();
154}
155
156void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
157 stringstream input;
158
159 // Neighbor data
160 input << Tremolo_neighbours;
[765f16]161 parser->load(&input);
[4fbca9c]162
163 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
164 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
[073a9e4]165 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
[4fbca9c]166 input.clear();
167}
168
169void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
170 stringstream input, output;
171
172 // Neighbor data
[73916f]173 {
174 input << Tremolo_improper;
[765f16]175 parser->load(&input);
[73916f]176 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]177 parser->save(&output, atoms);
[73916f]178 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[4d4d33]179 std::cout << output.str() << std::endl;
[73916f]180 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
181 input.clear();
182 output.clear();
183 }
[4fbca9c]184}
185
186void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
187 stringstream input, output;
188
189 // Neighbor data
[73916f]190 {
191 input << Tremolo_torsion;
[765f16]192 parser->load(&input);
[73916f]193 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]194 parser->save(&output, atoms);
[73916f]195 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[4d4d33]196 std::cout << output.str() << std::endl;
[73916f]197 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
198 input.clear();
199 output.clear();
200 }
[4fbca9c]201}
202
203void ParserTremoloUnitTest::writeTremoloTest() {
204 stringstream output;
205
206 // with the maximum number of fields and minimal information, default values are printed
[73916f]207 {
208 atom* newAtom = World::getInstance().createAtom();
209 newAtom->setType(1);
[765f16]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");
[73916f]211 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]212 parser->save(&output, atoms);
[73916f]213 CPPUNIT_ASSERT(output.str() == Tremolo_full);
214 }
[4fbca9c]215
216 cout << "testing the tremolo parser is done" << endl;
217}
[765f16]218
Note: See TracBrowser for help on using the repository browser.