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

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

Added tremolo's potential file parsing, reported by Daniel Dueck.

TremoloParser cannot interpret Type with HLA2 because it lacks mapping of the
value to an element. Hence, ...

  • new Action ParseTremoloPotentialsAction.
  • TremoloParser::knownTypes new map to contain: HLA2 -> H, ... map.
  • TremoloParser::createKnownTypesByIdentity() creates identity mapping.
  • TremoloParser::parseKnownTypes() parses potentials file.
  • Property mode set to 100644
File size: 6.4 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 = "\
47# ATOMDATA\tId\tname\tType\tx=3\n";
48static string Tremolo_Atomdata2 = "\
49#\n\
50#ATOMDATA Id name Type x=3\n\
511 hydrogen H 3.0 4.5 0.1\n\
52\n";
53static string Tremolo_invalidkey = "\
54#\n\
55#ATOMDATA Id name foo Type x=3\n\
56\n\n";
57static string Tremolo_velocity = "\
58#\n\
59#ATOMDATA Id name Type u=3\n\
601 hydrogen H 3.0 4.5 0.1\n\
61\n";
62static string Tremolo_neighbours = "#\n\
63#ATOMDATA Id Type neighbors=2\n\
641 H 3 0\n\
652 H 3 0\n\
663 O 1 2\n";
67static string Tremolo_improper = "\
68#\n\
69#ATOMDATA Id Type imprData\n\
708 H 9-10\n\
719 H 10-8,8-10\n\
7210 O -\n";
73static string Tremolo_torsion = "\
74#\n\
75#ATOMDATA Id Type torsion\n\
768 H 9-10\n\
779 H 10-8,8-10\n\
7810 O -\n";
79static string Tremolo_full = "\
80# 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\
810\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";
82
83void ParserTremoloUnitTest::setUp() {
84 World::getInstance();
85
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
91void ParserTremoloUnitTest::tearDown() {
92 ChangeTracker::purgeInstance();
93 World::purgeInstance();
94}
95
96/************************************ tests ***********************************/
97
98void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
99 cout << "Testing the tremolo parser." << endl;
100 TremoloParser* testParser = new TremoloParser();
101 stringstream input, output;
102
103 // Atomdata beginning with "# ATOMDATA"
104 {
105 input << Tremolo_Atomdata1;
106 testParser->load(&input);
107 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
108 testParser->save(&output, atoms);
109// std::cout << output.str() << std::endl;
110// std::cout << Tremolo_Atomdata1 << std::endl;
111 CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
112 input.clear();
113 output.clear();
114 }
115
116 // Atomdata beginning with "#ATOMDATA"
117 {
118 input << Tremolo_Atomdata2;
119 testParser->load(&input);
120 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
121 testParser->save(&output, atoms);
122 std::cout << output.str() << std::endl;
123 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
124 input.clear();
125 output.clear();
126 }
127
128 // Invalid key in Atomdata line
129 input << Tremolo_invalidkey;
130 testParser->load(&input);
131 //TODO: prove invalidity
132 input.clear();
133}
134
135void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
136 TremoloParser* testParser = new TremoloParser();
137 stringstream input;
138
139 // One simple data line
140 input << Tremolo_Atomdata2;
141 testParser->load(&input);
142 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
143 input.clear();
144}
145
146void ParserTremoloUnitTest::readTremoloVelocityTest() {
147 TremoloParser* testParser = new TremoloParser();
148 stringstream input;
149
150 // One simple data line
151 input << Tremolo_velocity;
152 testParser->load(&input);
153 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->AtomicVelocity[0] == 3.0);
154 input.clear();
155}
156
157void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
158 TremoloParser* testParser = new TremoloParser();
159 stringstream input;
160
161 // Neighbor data
162 input << Tremolo_neighbours;
163 testParser->load(&input);
164
165 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
166 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
167 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
168 input.clear();
169}
170
171void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
172 TremoloParser* testParser = new TremoloParser();
173 stringstream input, output;
174
175 // Neighbor data
176 {
177 input << Tremolo_improper;
178 testParser->load(&input);
179 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
180 testParser->save(&output, atoms);
181 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
182 std::cout << output.str() << std::endl;
183 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
184 input.clear();
185 output.clear();
186 }
187}
188
189void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
190 TremoloParser* testParser = new TremoloParser();
191 stringstream input, output;
192
193 // Neighbor data
194 {
195 input << Tremolo_torsion;
196 testParser->load(&input);
197 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
198 testParser->save(&output, atoms);
199 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
200 std::cout << output.str() << std::endl;
201 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
202 input.clear();
203 output.clear();
204 }
205}
206
207void ParserTremoloUnitTest::writeTremoloTest() {
208 TremoloParser* testParser = new TremoloParser();
209 stringstream output;
210
211 // with the maximum number of fields and minimal information, default values are printed
212 {
213 atom* newAtom = World::getInstance().createAtom();
214 newAtom->setType(1);
215 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");
216 std::vector<atom *> atoms = World::getInstance().getAllAtoms();
217 testParser->save(&output, atoms);
218 CPPUNIT_ASSERT(output.str() == Tremolo_full);
219 }
220
221 cout << "testing the tremolo parser is done" << endl;
222}
Note: See TracBrowser for help on using the repository browser.