source: src/ConfigFileBuffer.cpp@ 03c77c

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

bonds::previous and ::next removed, lists.hpp deleted.

  • the last of the concatenated lists has fallen to STL lists and vectors.
  • greatest impact is on fragmentation functions.
  • rewritten UniqueFragments::BondsPerSPList to vector<list<bond*> >.
  • removed include of lists.hpp.
  • removed lists.hpp from Makefile.am.
  • 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 * ConfigFileBuffer.cpp
10 *
11 * Created on: 12.06.2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "ConfigFileBuffer.hpp"
23#include "Helpers/helpers.hpp"
24#include "CodePatterns/Verbose.hpp"
25#include "CodePatterns/Log.hpp"
26#include "World.hpp"
27
28/******************************** Functions for class ConfigFileBuffer **********************/
29
30/** Structure containing compare function for Ion_Type sorting.
31 */
32struct IonTypeCompare {
33 bool operator()(const char* s1, const char *s2) const {
34 char number1[8];
35 char number2[8];
36 const char *dummy1, *dummy2;
37 //Log() << Verbose(0) << s1 << " " << s2 << endl;
38 dummy1 = strchr(s1, '_')+sizeof(char)*5; // go just after "Ion_Type"
39 dummy2 = strchr(dummy1, '_');
40 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
41 number1[dummy2-dummy1]='\0';
42 dummy1 = strchr(s2, '_')+sizeof(char)*5; // go just after "Ion_Type"
43 dummy2 = strchr(dummy1, '_');
44 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
45 number2[dummy2-dummy1]='\0';
46 if (atoi(number1) != atoi(number2))
47 return (atoi(number1) < atoi(number2));
48 else {
49 dummy1 = strchr(s1, '_')+sizeof(char);
50 dummy1 = strchr(dummy1, '_')+sizeof(char);
51 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
52 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
53 number1[dummy2-dummy1]='\0';
54 dummy1 = strchr(s2, '_')+sizeof(char);
55 dummy1 = strchr(dummy1, '_')+sizeof(char);
56 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
57 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
58 number2[dummy2-dummy1]='\0';
59 return (atoi(number1) < atoi(number2));
60 }
61 }
62};
63
64/** Constructor for ConfigFileBuffer class.
65 */
66ConfigFileBuffer::ConfigFileBuffer() :
67 buffer(NULL),
68 LineMapping(NULL),
69 CurrentLine(0),
70 NoLines(0)
71{
72};
73
74/** Constructor for ConfigFileBuffer class with filename to be parsed.
75 * \param *filename file name
76 */
77ConfigFileBuffer::ConfigFileBuffer(const char * const filename) :
78 buffer(NULL),
79 LineMapping(NULL),
80 CurrentLine(0),
81 NoLines(0)
82{
83 InitFileBuffer(filename);
84}
85
86void ConfigFileBuffer::InitFileBuffer(const char * const filename)
87{
88 ifstream *file= new ifstream(filename);
89 InitFileBuffer(file);
90}
91
92void ConfigFileBuffer::InitFileBuffer(istream *file)
93{
94 char line[MAXSTRINGSIZE];
95
96 RemoveMapping();
97
98 // prescan number of lines
99 if (file->fail()) {
100 DoeLog(1) && (eLog()<< Verbose(1) << "config file missing!" << endl);
101 return;
102 }
103 NoLines = 0; // we're overcounting by one
104 long file_position = file->tellg(); // mark current position
105 do {
106 file->getline(line, MAXSTRINGSIZE-1);
107 NoLines++;
108 } while (!file->eof());
109 file->clear();
110 file->seekg(file_position, ios::beg);
111 DoLog(1) && (Log() << Verbose(1) << NoLines-1 << " lines were recognized." << endl);
112
113 // allocate buffer's 1st dimension
114 if (buffer != NULL) {
115 DoeLog(1) && (eLog()<< Verbose(1) << "FileBuffer->buffer is not NULL!" << endl);
116 return;
117 } else
118 buffer = new char *[NoLines];
119
120 // scan each line and put into buffer
121 int lines=0;
122 int i;
123 do {
124 buffer[lines] = new char[MAXSTRINGSIZE];
125 file->getline(buffer[lines], MAXSTRINGSIZE-1);
126 i = strlen(buffer[lines]);
127 buffer[lines][i] = '\n';
128 buffer[lines][i+1] = '\0';
129 lines++;
130 } while((!file->eof()) && (lines < NoLines));
131 DoLog(1) && (Log() << Verbose(1) << lines-1 << " lines were read into the buffer." << endl);
132 file->clear();
133 file->seekg(file_position, ios::beg);
134
135 InitMapping();
136}
137
138/** Destructor for ConfigFileBuffer class.
139 */
140ConfigFileBuffer::~ConfigFileBuffer()
141{
142 RemoveBuffer();
143 RemoveMapping();
144}
145
146
147/** Create trivial mapping.
148 */
149void ConfigFileBuffer::InitMapping()
150{
151 LineMapping = new int[NoLines];
152 for (int i=0;i<NoLines;i++)
153 LineMapping[i] = i;
154 MappingAllocated = true;
155}
156
157/** Remove allocated mapping.
158 */
159void ConfigFileBuffer::RemoveMapping()
160{
161 delete[](LineMapping);
162 MappingAllocated = false;
163}
164
165/** Remove allocated mapping.
166 */
167void ConfigFileBuffer::RemoveBuffer()
168{
169 for(int i=0;i<NoLines;++i)
170 delete[](buffer[i]);
171 delete[](buffer);
172}
173
174
175/** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
176 * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
177 * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
178 * points to first Ion_Type entry.
179 * \param *FileBuffer pointer to buffer structure
180 * \param NoAtoms of subsequent lines to look at
181 */
182void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
183{
184 map<const char *, int, IonTypeCompare> IonTypeLineMap;
185 if (!MappingAllocated) {
186 InitMapping();
187 }
188
189 // put all into hashed map
190 for (int i=0; i<NoAtoms; ++i) {
191 IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
192 }
193
194 // fill map
195 int nr=0;
196 for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
197 if (CurrentLine+nr < NoLines)
198 LineMapping[CurrentLine+(nr++)] = runner->second;
199 else {
200 DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl);
201 performCriticalExit();
202 }
203 }
204}
Note: See TracBrowser for help on using the repository browser.