source: src/unittests/ParserTremoloUnitTest.cpp@ 4fbca9c

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

PdbParser::save() fully working.

  • Property mode set to 100644
File size: 5.7 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 input << Tremolo_Atomdata1;
77 testParser->load(&input);
78 testParser->save(&output);
79 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
80 input.clear();
81 output.clear();
82
83 // Atomdata beginning with "#ATOMDATA"
84 input << Tremolo_Atomdata2;
85 testParser->load(&input);
86 testParser->save(&output);
87 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
88 input.clear();
89 output.clear();
90
91 // Invalid key in Atomdata line
92 input << Tremolo_invalidkey;
93 testParser->load(&input);
94 //TODO: proove invalidity
95 input.clear();
96}
97
98void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
99 TremoloParser* testParser = new TremoloParser();
100 stringstream input;
101
102 // One simple data line
103 input << Tremolo_Atomdata2;
104 testParser->load(&input);
105 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
106 input.clear();
107}
108
109void ParserTremoloUnitTest::readTremoloVelocityTest() {
110 TremoloParser* testParser = new TremoloParser();
111 stringstream input;
112
113 // One simple data line
114 input << Tremolo_velocity;
115 testParser->load(&input);
116 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
117 input.clear();
118}
119
120void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
121 TremoloParser* testParser = new TremoloParser();
122 stringstream input;
123
124 // Neighbor data
125 input << Tremolo_neighbours;
126 testParser->load(&input);
127
128 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
129 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
130 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
131 input.clear();
132}
133
134void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
135 TremoloParser* testParser = new TremoloParser();
136 stringstream input, output;
137
138 // Neighbor data
139 input << Tremolo_improper;
140 testParser->load(&input);
141 testParser->save(&output);
142 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
143 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
144 input.clear();
145 output.clear();
146}
147
148void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
149 TremoloParser* testParser = new TremoloParser();
150 stringstream input, output;
151
152 // Neighbor data
153 input << Tremolo_torsion;
154 testParser->load(&input);
155 testParser->save(&output);
156 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
157 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
158 input.clear();
159 output.clear();
160}
161
162void ParserTremoloUnitTest::writeTremoloTest() {
163 TremoloParser* testParser = new TremoloParser();
164 stringstream output;
165
166 // with the maximum number of fields and minimal information, default values are printed
167 atom* newAtom = World::getInstance().createAtom();
168 newAtom->setType(1);
169 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");
170 testParser->save(&output);
171 CPPUNIT_ASSERT(output.str() == Tremolo_full);
172
173 cout << "testing the tremolo parser is done" << endl;
174}
Note: See TracBrowser for help on using the repository browser.