source: src/Parser/FormatParserStorage.cpp@ bb6193

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

Added PdbParser with save capability.

  • load does not yet work.
  • added test part to Simple_configuration/2 (new file test.pdb)
  • Property mode set to 100644
File size: 7.5 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/** \file FormatParserStorage.cpp
9 *
10 * date: Jun, 22 2010
11 * author: heber
12 *
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include <iostream>
23#include <fstream>
24
25#include "Parser/FormatParserStorage.hpp"
26
27#include "Parser/FormatParser.hpp"
28#include "Parser/MpqcParser.hpp"
29#include "Parser/PcpParser.hpp"
30#include "Parser/PdbParser.hpp"
31#include "Parser/TremoloParser.hpp"
32#include "Parser/XyzParser.hpp"
33
34#include "Helpers/Log.hpp"
35#include "Helpers/Verbose.hpp"
36
37#include "Helpers/Assert.hpp"
38
39#include "Patterns/Singleton_impl.hpp"
40
41/** Increment operator for the enumeration ParserTypes to allow loops.
42 * \param &type value
43 * \return value incremented by one
44 */
45ParserTypes &operator++(ParserTypes &type)
46{
47 return type = ParserTypes(type+1);
48}
49
50/** Constructor of class FormatParserStorage.
51 */
52FormatParserStorage::FormatParserStorage()
53{
54 ParserList.resize(ParserTypes_end, NULL);
55 ParserStream.resize(ParserTypes_end, NULL);
56 ParserPresent.resize(ParserTypes_end, false);
57 ParserSuffix.resize(ParserTypes_end, "");
58
59 ParserNames[mpqc] = "mpqc";
60 ParserNames[pcp] = "pcp";
61 ParserNames[pdb] = "pdb";
62 ParserNames[tremolo] = "tremolo";
63 ParserNames[xyz] = "xyz";
64
65 for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it)
66 ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) );
67
68 ParserSuffix[mpqc] = "in";
69 ParserSuffix[pcp] = "conf";
70 ParserSuffix[pdb] = "pdb";
71 ParserSuffix[tremolo] = "data";
72 ParserSuffix[xyz] = "xyz";
73
74 ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc;
75 ParserAddFunction[pcp] = &FormatParserStorage::addPcp;
76 ParserAddFunction[pdb] = &FormatParserStorage::addPdb;
77 ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo;
78 ParserAddFunction[xyz] = &FormatParserStorage::addXyz;
79}
80
81/** Destructor of class FormatParserStorage.
82 * Free all stored FormatParsers.
83 * Save on Exit.
84 */
85FormatParserStorage::~FormatParserStorage()
86{
87 for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
88 if (ParserPresent[iter]) {
89 if (ParserStream[iter]->is_open())
90 ParserStream[iter]->close();
91 delete ParserStream[iter];
92 delete ParserList[iter];
93 }
94}
95
96/** Sets the filename of all current parsers in storage to prefix.suffix.
97 * \param &prefix prefix to use.
98 */
99void FormatParserStorage::SetOutputPrefixForAll(std::string &_prefix)
100{
101 prefix=_prefix;
102};
103
104
105void FormatParserStorage::SaveAll()
106{
107 std::string filename;
108 for (ParserTypes iter = ParserTypes_begin; iter < ParserTypes_end; ++iter)
109 if (ParserPresent[iter]) {
110 filename = prefix;
111 filename += ".";
112 filename += ParserSuffix[iter];
113 ParserStream[iter] = new std::ofstream(filename.c_str());
114 ParserList[iter]->setOstream((std::ostream *)ParserStream[iter]);
115 }
116}
117
118
119/** Adds an MpqcParser to the storage.
120 */
121void FormatParserStorage::addMpqc()
122{
123 if (!ParserPresent[mpqc]) {
124 ParserList[mpqc] = dynamic_cast<FormatParser *>(new MpqcParser);
125 ParserPresent[mpqc] = true;
126 }
127 else
128 DoeLog(1) && (eLog() << Verbose(1) << "Parser mpqc is already present." << endl);
129}
130
131
132/** Adds an PcpParser to the storage.
133 */
134void FormatParserStorage::addPcp()
135{
136 if (!ParserPresent[pcp]) {
137 ParserList[pcp] = new PcpParser();
138 ParserPresent[pcp] = true;
139 } else
140 DoeLog(1) && (eLog() << Verbose(1) << "Parser pcp is already present." << endl);
141}
142
143
144/** Adds an PdbParser to the storage.
145 */
146void FormatParserStorage::addPdb()
147{
148 if (!ParserPresent[pdb]) {
149 ParserList[pdb] = new PdbParser();
150 ParserPresent[pdb] = true;
151 } else
152 DoeLog(1) && (eLog() << Verbose(1) << "Parser pdb is already present." << endl);
153}
154
155
156/** Adds an TremoloParser to the storage.
157 */
158void FormatParserStorage::addTremolo()
159{
160 if (!ParserPresent[tremolo]) {
161 ParserList[tremolo] = new TremoloParser();
162 ParserPresent[tremolo] = true;
163 } else
164 DoeLog(1) && (eLog() << Verbose(1) << "Parser tremolo is already present." << endl);
165}
166
167
168/** Adds an XyzParser to the storage.
169 */
170void FormatParserStorage::addXyz()
171{
172 if (!ParserPresent[xyz]) {
173 ParserList[xyz] = new XyzParser();
174 ParserPresent[xyz] = true;
175 } else
176 DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl);
177}
178
179ParserTypes FormatParserStorage::getType(std::string type)
180{
181 if (ParserLookupNames.find(type) == ParserLookupNames.end()) {
182 DoeLog(1) && (eLog() << Verbose(1) << "Unknown type " << type << "." << endl);
183 return ParserTypes_end;
184 } else
185 return ParserLookupNames[type];
186}
187
188bool FormatParserStorage::add(ParserTypes ptype)
189{
190 if (ptype != ParserTypes_end) {
191 if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) {
192 DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);
193 (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ...
194 return true;
195 } else {
196 DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);
197 return false;
198 }
199 } else {
200 return false;
201 }
202}
203
204bool FormatParserStorage::add(std::string type)
205{
206 return add(getType(type));
207}
208
209
210/** Parses an istream depending on its suffix
211 * \param &input input stream
212 * \param suffix
213 * \return true - parsing ok, false - suffix unknown
214 */
215bool FormatParserStorage::get(std::istream &input, std::string suffix)
216{
217 if (suffix == ParserSuffix[mpqc]) {
218 getMpqc().load(&input);
219 } else if (suffix == ParserSuffix[pcp]) {
220 getPcp().load(&input);
221 } else if (suffix == ParserSuffix[pdb]) {
222 getPdb().load(&input);
223 } else if (suffix == ParserSuffix[tremolo]) {
224 getTremolo().load(&input);
225 } else if (suffix == ParserSuffix[xyz]) {
226 getXyz().load(&input);
227 } else {
228 DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::get()." << endl);
229 return false;
230 }
231 return true;
232}
233
234/** Returns reference to the output MpqcParser, adds if not present.
235 * \return reference to the output MpqcParser
236 */
237MpqcParser &FormatParserStorage::getMpqc()
238{
239 if (!ParserPresent[mpqc])
240 addMpqc();
241 return dynamic_cast<MpqcParser &>(*ParserList[mpqc]);
242}
243
244/** Returns reference to the output PcpParser, adds if not present.
245 * \return reference to the output PcpParser
246 */
247PcpParser &FormatParserStorage::getPcp()
248{
249 if (!ParserPresent[pcp])
250 addPcp();
251 return dynamic_cast<PcpParser &>(*ParserList[pcp]);
252}
253
254/** Returns reference to the output PdbParser, adds if not present.
255 * \return reference to the output PdbParser
256 */
257PdbParser &FormatParserStorage::getPdb()
258{
259 if (!ParserPresent[pdb])
260 addPdb();
261 return dynamic_cast<PdbParser &>(*ParserList[pdb]);
262}
263
264/** Returns reference to the output TremoloParser, adds if not present.
265 * \return reference to the output TremoloParser
266 */
267TremoloParser &FormatParserStorage::getTremolo()
268{
269 if (!ParserPresent[tremolo])
270 addTremolo();
271 return dynamic_cast<TremoloParser &>(*ParserList[tremolo]);
272}
273
274/** Returns reference to the output XyzParser, adds if not present.
275 * \return reference to the output XyzParser
276 */
277XyzParser &FormatParserStorage::getXyz()
278{
279 if (!ParserPresent[xyz])
280 addXyz();
281 return dynamic_cast<XyzParser &>(*ParserList[xyz]);
282}
283
284
285
286CONSTRUCT_SINGLETON(FormatParserStorage)
Note: See TracBrowser for help on using the repository browser.