source: src/unittests/ParserTremoloUnitTest.cpp@ fc5c3a

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

Extended FormatParser::save() to use vector<atom *> to save.

  • This is needed to make the save functions also work on selected atoms or molecules only.
  • Within ParserCommonUnitTest, ParserTremoloUnitTest we create the vector by calling World's getAllAtoms() (which would have been done before in the specialized save() functions).
  • new functions in FormatParserStorage:
    • saveSelectedAtoms().
    • saveSelectedMolecules().
    • saveWorld().
  • renamed ::get() and ::put() to ::load() and ::save() to have it more consistent with underlying FormatParser functions and also to avoid misinterpretation with all ::get...() functions.
  • Property mode set to 100644
File size: 6.1 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 "Parser/MpqcParser.hpp"
27#include "Parser/PdbParser.hpp"
28#include "Parser/PcpParser.hpp"
29#include "Parser/TremoloParser.hpp"
30#include "Parser/XyzParser.hpp"
31#include "World.hpp"
32#include "atom.hpp"
33#include "element.hpp"
34#include "periodentafel.hpp"
35#include "Descriptors/AtomTypeDescriptor.hpp"
36
37#ifdef HAVE_TESTRUNNER
38#include "UnitTestMain.hpp"
39#endif /*HAVE_TESTRUNNER*/
40
41using namespace std;
42
43// Registers the fixture into the 'registry'
44CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest );
45
46static string Tremolo_Atomdata1 = "# ATOMDATA\tId\tname\tType\tx=3\n";
47static string Tremolo_Atomdata2 = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
48static string Tremolo_invalidkey = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
49static string Tremolo_velocity = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
50static string Tremolo_neighbours = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
51static string Tremolo_improper = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
52static string Tremolo_torsion = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
53static string Tremolo_full = "# 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\n0\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";
54
55void ParserTremoloUnitTest::setUp() {
56 World::getInstance();
57
58 // we need hydrogens and oxygens in the following tests
59 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
60 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
61}
62
63void ParserTremoloUnitTest::tearDown() {
64 ChangeTracker::purgeInstance();
65 World::purgeInstance();
66}
67
68/************************************ tests ***********************************/
69
70void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
71 cout << "Testing the tremolo parser." << endl;
72 TremoloParser* testParser = new TremoloParser();
73 stringstream input, output;
74
75 // Atomdata beginning with "# ATOMDATA"
76 {
77 input << Tremolo_Atomdata1;
78 testParser->load(&input);
79 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
80 testParser->save(&output, atoms);
81 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
82 input.clear();
83 output.clear();
84 }
85
86 // Atomdata beginning with "#ATOMDATA"
87 {
88 input << Tremolo_Atomdata2;
89 testParser->load(&input);
90 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
91 testParser->save(&output, atoms);
92 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
93 input.clear();
94 output.clear();
95 }
96
97 // Invalid key in Atomdata line
98 input << Tremolo_invalidkey;
99 testParser->load(&input);
100 //TODO: prove invalidity
101 input.clear();
102}
103
104void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
105 TremoloParser* testParser = new TremoloParser();
106 stringstream input;
107
108 // One simple data line
109 input << Tremolo_Atomdata2;
110 testParser->load(&input);
111 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
112 input.clear();
113}
114
115void ParserTremoloUnitTest::readTremoloVelocityTest() {
116 TremoloParser* testParser = new TremoloParser();
117 stringstream input;
118
119 // One simple data line
120 input << Tremolo_velocity;
121 testParser->load(&input);
122 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
123 input.clear();
124}
125
126void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
127 TremoloParser* testParser = new TremoloParser();
128 stringstream input;
129
130 // Neighbor data
131 input << Tremolo_neighbours;
132 testParser->load(&input);
133
134 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
135 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
136 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
137 input.clear();
138}
139
140void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
141 TremoloParser* testParser = new TremoloParser();
142 stringstream input, output;
143
144 // Neighbor data
145 {
146 input << Tremolo_improper;
147 testParser->load(&input);
148 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
149 testParser->save(&output, atoms);
150 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
151 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
152 input.clear();
153 output.clear();
154 }
155}
156
157void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
158 TremoloParser* testParser = new TremoloParser();
159 stringstream input, output;
160
161 // Neighbor data
162 {
163 input << Tremolo_torsion;
164 testParser->load(&input);
165 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
166 testParser->save(&output, atoms);
167 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
168 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
169 input.clear();
170 output.clear();
171 }
172}
173
174void ParserTremoloUnitTest::writeTremoloTest() {
175 TremoloParser* testParser = new TremoloParser();
176 stringstream output;
177
178 // with the maximum number of fields and minimal information, default values are printed
179 {
180 atom* newAtom = World::getInstance().createAtom();
181 newAtom->setType(1);
182 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");
183 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
184 testParser->save(&output, atoms);
185 CPPUNIT_ASSERT(output.str() == Tremolo_full);
186 }
187
188 cout << "testing the tremolo parser is done" << endl;
189}
Note: See TracBrowser for help on using the repository browser.