source: src/Parser/unittests/ParserTremoloUnitTest.cpp@ 69b30a

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 69b30a was 05e2ed, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: TremoloParser did not load/save imprData or torsion correctly.

  • this error was introduced when incorporating local-global-maps and conversions where this was not correctly done for the improper and torsion string:
    • conversion from local to global on load was present but went over all atoms, not just newly parsed ones. adapt.. now gets atom vector as param.
    • save did no global-local conversion. For this we generalized adaptIdDependentDataString() to get a function pointer converting ids.
  • TEST: We added a new regression test on this matter where a .data file with impropers is loaded and stored.
  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[4fbca9c]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[4fbca9c]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
[5a667d]41#include "CodePatterns/Log.hpp"
42
[6f0841]43#include "Atom/atom.hpp"
[006e1e]44#include "Atom/AtomObserver.hpp"
[073a9e4]45#include "Descriptors/AtomTypeDescriptor.hpp"
[3bdb6d]46#include "Element/element.hpp"
47#include "Element/periodentafel.hpp"
[4fbca9c]48#include "Parser/TremoloParser.hpp"
[765f16]49#include "Parser/ChangeTracker.hpp"
[073a9e4]50#include "World.hpp"
51#include "WorldTime.hpp"
[4fbca9c]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
[4d4d33]62static string Tremolo_Atomdata1 = "\
[ccb487]63# ATOMDATA\tId\tname\ttype\tx=3\n\
64# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n";
[4d4d33]65static string Tremolo_Atomdata2 = "\
66#\n\
[305e7e]67#ATOMDATA Id name type x=3\n\
[ccb487]68# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]691 hydrogen H 3.0 4.5 0.1\n\
70\n";
71static string Tremolo_invalidkey = "\
72#\n\
[305e7e]73#ATOMDATA Id name foo type x=3\n\
[ccb487]74# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]75\n\n";
76static string Tremolo_velocity = "\
77#\n\
[305e7e]78#ATOMDATA Id name type u=3\n\
[ccb487]79# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]801 hydrogen H 3.0 4.5 0.1\n\
81\n";
82static string Tremolo_neighbours = "#\n\
[305e7e]83#ATOMDATA Id type neighbors=2\n\
[ccb487]84# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]851 H 3 0\n\
862 H 3 0\n\
873 O 1 2\n";
88static string Tremolo_improper = "\
89#\n\
[305e7e]90#ATOMDATA Id type imprData\n\
[ccb487]91# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]928 H 9-10\n\
939 H 10-8,8-10\n\
9410 O -\n";
95static string Tremolo_torsion = "\
96#\n\
[305e7e]97#ATOMDATA Id type torsion\n\
[ccb487]98# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[4d4d33]998 H 9-10\n\
1009 H 10-8,8-10\n\
10110 O -\n";
102static string Tremolo_full = "\
[e6e4a0]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\
[ccb487]104# Box\t20\t0\t0\t0\t20\t0\t0\t0\t20\n\
[e6e4a0]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";
[4fbca9c]106
107void ParserTremoloUnitTest::setUp() {
108 World::getInstance();
109
[05e2ed]110 setVerbosity(2);
[5a667d]111
[765f16]112 parser = new FormatParser<tremolo>();
113
[4fbca9c]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
[765f16]119void ParserTremoloUnitTest::tearDown()
120{
121 delete parser;
[4fbca9c]122 ChangeTracker::purgeInstance();
[006e1e]123 AtomObserver::purgeInstance();
[4fbca9c]124 World::purgeInstance();
125}
126
127/************************************ tests ***********************************/
128
129void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
[05e2ed]130// cout << "Testing the tremolo parser." << endl;
[4fbca9c]131 stringstream input, output;
132
133 // Atomdata beginning with "# ATOMDATA"
[73916f]134 {
135 input << Tremolo_Atomdata1;
[765f16]136 parser->load(&input);
[73916f]137 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]138 parser->save(&output, atoms);
[4d4d33]139// std::cout << output.str() << std::endl;
140// std::cout << Tremolo_Atomdata1 << std::endl;
[73916f]141 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
142 input.clear();
143 output.clear();
144 }
[4fbca9c]145
146 // Atomdata beginning with "#ATOMDATA"
[73916f]147 {
148 input << Tremolo_Atomdata2;
[765f16]149 parser->load(&input);
[73916f]150 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]151 parser->save(&output, atoms);
[05e2ed]152// std::cout << output.str() << std::endl;
[73916f]153 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
154 input.clear();
155 output.clear();
156 }
[4fbca9c]157
158 // Invalid key in Atomdata line
159 input << Tremolo_invalidkey;
[5a667d]160 CPPUNIT_ASSERT_THROW( parser->load(&input), IllegalParserKeyException);
[73916f]161 //TODO: prove invalidity
[4fbca9c]162 input.clear();
163}
164
[ca331c]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
[4fbca9c]188void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
189 stringstream input;
190
191 // One simple data line
192 input << Tremolo_Atomdata2;
[765f16]193 parser->load(&input);
[4fbca9c]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;
[765f16]203 parser->load(&input);
[bce72c]204 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
[4fbca9c]205 input.clear();
206}
207
208void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
209 stringstream input;
210
211 // Neighbor data
212 input << Tremolo_neighbours;
[765f16]213 parser->load(&input);
[4fbca9c]214
215 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
216 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
[073a9e4]217 IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
[4fbca9c]218 input.clear();
219}
220
221void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
222 stringstream input, output;
223
224 // Neighbor data
[73916f]225 {
226 input << Tremolo_improper;
[765f16]227 parser->load(&input);
[73916f]228 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]229 parser->save(&output, atoms);
[73916f]230 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[05e2ed]231// std::cout << output.str() << std::endl;
232 CPPUNIT_ASSERT(output.str().find("3-1,1-3") != string::npos);
[73916f]233 input.clear();
234 output.clear();
235 }
[4fbca9c]236}
237
238void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
239 stringstream input, output;
240
241 // Neighbor data
[73916f]242 {
243 input << Tremolo_torsion;
[765f16]244 parser->load(&input);
[73916f]245 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]246 parser->save(&output, atoms);
[73916f]247 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
[05e2ed]248// std::cout << output.str() << std::endl;
249 CPPUNIT_ASSERT(output.str().find("3-1,1-3") != string::npos);
[73916f]250 input.clear();
251 output.clear();
252 }
[4fbca9c]253}
254
255void ParserTremoloUnitTest::writeTremoloTest() {
256 stringstream output;
257
258 // with the maximum number of fields and minimal information, default values are printed
[73916f]259 {
260 atom* newAtom = World::getInstance().createAtom();
261 newAtom->setType(1);
[e6e4a0]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");
[73916f]263 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
[765f16]264 parser->save(&output, atoms);
[ccb487]265// std::cout << output.str() << std::endl;
266// std::cout << Tremolo_full << std::endl;
[73916f]267 CPPUNIT_ASSERT(output.str() == Tremolo_full);
268 }
[4fbca9c]269
[05e2ed]270// cout << "testing the tremolo parser is done" << endl;
[4fbca9c]271}
[765f16]272
Note: See TracBrowser for help on using the repository browser.