source: src/Parser/unittests/ParserTremoloUnitTest.cpp@ 87d6bd

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 87d6bd was 708277, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Using fixed Observer in CodePatterns 1.2.6.

  • we now require CodePatterns 1.2.6.
  • Notifications now use subjectKilled() when the Observable they are associated with is destroyed. This allows Observers that are just sign on to a single channel safely sign off.
  • also, derived Observable classes must not remove their Channels and Notifications by themselves. This is done by the Observable base class. Otherwise, subjectKilled() is not called.
  • changed AtomObserver: Is directly connected to the atom class, AtomInserted and AtomRemoved called in its cstor and dstor. The World has nothing to do with it. However, we have to make sure AtomObserver is purged after World.
  • Fixed also some faulty uses of ObserverLog and we always insert into NotificationChannels with static_cast to Observable for clarity.
  • Property mode set to 100644
File size: 8.0 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * ParserTremoloUnitTest.cpp
25 *
26 * Created on: Mar 3, 2010
27 * Author: metzler
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "ParserTremoloUnitTest.hpp"
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "CodePatterns/Log.hpp"
42
43#include "Atom/atom.hpp"
44#include "Atom/AtomObserver.hpp"
45#include "Descriptors/AtomTypeDescriptor.hpp"
46#include "Element/element.hpp"
47#include "Element/periodentafel.hpp"
48#include "Parser/TremoloParser.hpp"
49#include "Parser/ChangeTracker.hpp"
50#include "World.hpp"
51#include "WorldTime.hpp"
52
53#ifdef HAVE_TESTRUNNER
54#include "UnitTestMain.hpp"
55#endif /*HAVE_TESTRUNNER*/
56
57using namespace std;
58
59// Registers the fixture into the 'registry'
60CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest );
61
62static string Tremolo_Atomdata1 = "\
63# ATOMDATA\tId\tname\ttype\tx=3\n\
64# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
65static string Tremolo_Atomdata2 = "\
66#\n\
67#ATOMDATA Id name type x=3\n\
68# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
691 hydrogen H 3.0 4.5 0.1\n\
70\n";
71static string Tremolo_invalidkey = "\
72#\n\
73#ATOMDATA Id name foo type x=3\n\
74# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
75\n\n";
76static string Tremolo_velocity = "\
77#\n\
78#ATOMDATA Id name type u=3\n\
79# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
801 hydrogen H 3.0 4.5 0.1\n\
81\n";
82static string Tremolo_neighbours = "#\n\
83#ATOMDATA Id type neighbors=2\n\
84# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
851 H 3 0\n\
862 H 3 0\n\
873 O 1 2\n";
88static string Tremolo_improper = "\
89#\n\
90#ATOMDATA Id type imprData\n\
91# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
928 H 9-10\n\
939 H 10-8,8-10\n\
9410 O -\n";
95static string Tremolo_torsion = "\
96#\n\
97#ATOMDATA Id type torsion\n\
98# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
998 H 9-10\n\
1009 H 10-8,8-10\n\
10110 O -\n";
102static string Tremolo_full = "\
103# ATOMDATA\tx=3\tu=3\tF=3\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\ttype\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n\
104# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
1050\t0\t0\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";
106
107void ParserTremoloUnitTest::setUp() {
108 World::getInstance();
109
110 setVerbosity(2);
111
112 parser = new FormatParser<tremolo>();
113
114 // we need hydrogens and oxygens in the following tests
115 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
116 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
117}
118
119void ParserTremoloUnitTest::tearDown()
120{
121 delete parser;
122 ChangeTracker::purgeInstance();
123 World::purgeInstance();
124 AtomObserver::purgeInstance();
125}
126
127/************************************ tests ***********************************/
128
129void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
130// cout << "Testing the tremolo parser." << endl;
131 stringstream input, output;
132
133 // Atomdata beginning with "# ATOMDATA"
134 {
135 input << Tremolo_Atomdata1;
136 parser->load(&input);
137 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
138 parser->save(&output, atoms);
139// std::cout << output.str() << std::endl;
140// std::cout << Tremolo_Atomdata1 << std::endl;
141 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
142 input.clear();
143 output.clear();
144 }
145
146 // Atomdata beginning with "#ATOMDATA"
147 {
148 input << Tremolo_Atomdata2;
149 parser->load(&input);
150 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
151 parser->save(&output, atoms);
152// std::cout << output.str() << std::endl;
153 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
154 input.clear();
155 output.clear();
156 }
157
158 // Invalid key in Atomdata line
159 input << Tremolo_invalidkey;
160 CPPUNIT_ASSERT_THROW( parser->load(&input), IllegalParserKeyException);
161 //TODO: prove invalidity
162 input.clear();
163}
164
165void ParserTremoloUnitTest::getsetAtomDataTest() {
166 stringstream input;
167 input << Tremolo_Atomdata1;
168 parser->load(&input);
169
170 CPPUNIT_ASSERT_EQUAL( std::string("Id name type x=3"), parser->getAtomData() );
171
172 // overwrite keys
173 const std::string fewkeys("Id type x=3 neighbors=2");
174 parser->resetAtomData(fewkeys);
175 CPPUNIT_ASSERT_EQUAL( fewkeys, parser->getAtomData() );
176
177 // add some keys
178 const std::string morekeys("charge");
179 parser->setAtomData(morekeys);
180 CPPUNIT_ASSERT_EQUAL( fewkeys+std::string(" ")+morekeys, parser->getAtomData() );
181
182 // add similar key
183 const std::string otherkey("neighbors=4");
184 parser->setAtomData(otherkey);
185 CPPUNIT_ASSERT( fewkeys+std::string(" ")+morekeys != parser->getAtomData() );
186}
187
188void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
189 stringstream input;
190
191 // One simple data line
192 input << Tremolo_Atomdata2;
193 parser->load(&input);
194 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
195 input.clear();
196}
197
198void ParserTremoloUnitTest::readTremoloVelocityTest() {
199 stringstream input;
200
201 // One simple data line
202 input << Tremolo_velocity;
203 parser->load(&input);
204 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
205 input.clear();
206}
207
208void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
209 stringstream input;
210
211 // Neighbor data
212 input << Tremolo_neighbours;
213 parser->load(&input);
214
215 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
216 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
217 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
218 input.clear();
219}
220
221void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
222 stringstream input, output;
223
224 // Neighbor data
225 {
226 input << Tremolo_improper;
227 parser->load(&input);
228 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
229 parser->save(&output, atoms);
230 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
231// std::cout << output.str() << std::endl;
232 CPPUNIT_ASSERT(output.str().find("3-1,1-3") != string::npos);
233 input.clear();
234 output.clear();
235 }
236}
237
238void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
239 stringstream input, output;
240
241 // Neighbor data
242 {
243 input << Tremolo_torsion;
244 parser->load(&input);
245 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
246 parser->save(&output, atoms);
247 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
248// std::cout << output.str() << std::endl;
249 CPPUNIT_ASSERT(output.str().find("3-1,1-3") != string::npos);
250 input.clear();
251 output.clear();
252 }
253}
254
255void ParserTremoloUnitTest::writeTremoloTest() {
256 stringstream output;
257
258 // with the maximum number of fields and minimal information, default values are printed
259 {
260 atom* newAtom = World::getInstance().createAtom();
261 newAtom->setType(1);
262 parser->setAtomData("x=3 u=3 F=3 stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
263 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
264 parser->save(&output, atoms);
265// std::cout << output.str() << std::endl;
266// std::cout << Tremolo_full << std::endl;
267 CPPUNIT_ASSERT(output.str() == Tremolo_full);
268 }
269
270// cout << "testing the tremolo parser is done" << endl;
271}
272
Note: See TracBrowser for help on using the repository browser.