source: src/parser.cpp@ f731ae

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 Candidate_v1.7.0 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 f731ae was f731ae, checked in by Frederik Heber <heber@…>, 17 years ago

ColumnCounter -> *ColumnCounter

columns of the MatrixContainer class may now be variable over each matrix. This was changed globally to allow for varying column numbers of the new class HessianMatrix.

  • Property mode set to 100644
File size: 40.0 KB
Line 
1/** \file parsing.cpp
2 *
3 * Declarations of various class functions for the parsing of value files.
4 *
5 */
6
7// ======================================= INCLUDES ==========================================
8
9#include "helpers.hpp"
10#include "parser.hpp"
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17// ======================================= FUNCTIONS ==========================================
18
19/** Test if given filename can be opened.
20 * \param filename name of file
21 * \param test true - no error message, false - print error
22 * \return given file exists
23 */
24bool FilePresent(const char *filename, bool test)
25{
26 ifstream input;
27
28 input.open(filename, ios::in);
29 if (input == NULL) {
30 if (!test)
31 cout << endl << "Unable to open " << filename << ", is the directory correct?" << endl;
32 return false;
33 }
34 input.close();
35 return true;
36};
37
38/** Test the given parameters.
39 * \param argc argument count
40 * \param **argv arguments array
41 * \return given inputdir is valid
42 */
43bool TestParams(int argc, char **argv)
44{
45 ifstream input;
46 stringstream line;
47
48 line << argv[1] << FRAGMENTPREFIX << KEYSETFILE;
49 return FilePresent(line.str().c_str(), false);
50};
51
52// ======================================= CLASS MatrixContainer =============================
53
54/** Constructor of MatrixContainer class.
55 */
56MatrixContainer::MatrixContainer() {
57 Indices = NULL;
58 Header = (char *) Malloc(sizeof(char)*1023, "MatrixContainer::MatrixContainer: *Header");
59 Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
60 RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter");
61 ColumnCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *ColumnCounter");
62 Matrix[0] = NULL;
63 RowCounter[0] = -1;
64 MatrixCounter = 0;
65 ColumnCounter[0] = -1;
66};
67
68/** Destructor of MatrixContainer class.
69 */
70MatrixContainer::~MatrixContainer() {
71 if (Matrix != NULL) {
72 for(int i=MatrixCounter;i--;) {
73 if ((ColumnCounter != NULL) && (RowCounter != NULL)) {
74 for(int j=RowCounter[i]+1;j--;)
75 Free((void **)&Matrix[i][j], "MatrixContainer::~MatrixContainer: *Matrix[][]");
76 Free((void **)&Matrix[i], "MatrixContainer::~MatrixContainer: **Matrix[]");
77 }
78 }
79 if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
80 for(int j=RowCounter[MatrixCounter]+1;j--;)
81 Free((void **)&Matrix[MatrixCounter][j], "MatrixContainer::~MatrixContainer: *Matrix[MatrixCounter][]");
82 if (MatrixCounter != 0)
83 Free((void **)&Matrix[MatrixCounter], "MatrixContainer::~MatrixContainer: **Matrix[MatrixCounter]");
84 Free((void **)&Matrix, "MatrixContainer::~MatrixContainer: ***Matrix");
85 }
86 if (Indices != NULL)
87 for(int i=MatrixCounter+1;i--;) {
88 Free((void **)&Indices[i], "MatrixContainer::~MatrixContainer: *Indices[]");
89 }
90 Free((void **)&Indices, "MatrixContainer::~MatrixContainer: **Indices");
91
92 Free((void **)&Header, "MatrixContainer::~MatrixContainer: *Header");
93 Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
94 Free((void **)&ColumnCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
95};
96
97/** Either copies index matrix from another MatrixContainer or initialises with trivial mapping if NULL.
98 * This either copies the index matrix or just maps 1 to 1, 2 to 2 and so on for all fragments.
99 * \param *Matrix pointer to other MatrixContainer
100 * \return true - copy/initialisation sucessful, false - dimension false for copying
101 */
102bool MatrixContainer::InitialiseIndices(class MatrixContainer *Matrix)
103{
104 cout << "Initialising indices";
105 if (Matrix == NULL) {
106 cout << " with trivial mapping." << endl;
107 Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
108 for(int i=MatrixCounter+1;i--;) {
109 Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
110 for(int j=RowCounter[i];j--;)
111 Indices[i][j] = j;
112 }
113 } else {
114 cout << " from other MatrixContainer." << endl;
115 if (MatrixCounter != Matrix->MatrixCounter)
116 return false;
117 Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
118 for(int i=MatrixCounter+1;i--;) {
119 if (RowCounter[i] != Matrix->RowCounter[i])
120 return false;
121 Indices[i] = (int *) Malloc(sizeof(int)*Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
122 for(int j=Matrix->RowCounter[i];j--;)
123 Indices[i][j] = Matrix->Indices[i][j];
124 }
125 }
126 return true;
127};
128
129/** Parsing a number of matrices.
130 * -# open the matrix file
131 * -# skip some lines (\a skiplines)
132 * -# scan header lines for number of columns
133 * -# scan lines for number of rows
134 * -# allocate matrix
135 * -# loop over found column and row counts and parse in each entry
136 * \param *name directory with files
137 * \param skiplines number of inital lines to skip
138 * \param skiplines number of inital columns to skip
139 * \param MatrixNr index number in Matrix array to parse into
140 * \return parsing successful
141 */
142bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr)
143{
144 ifstream input;
145 stringstream line;
146 string token;
147 char filename[1023];
148
149 input.open(name, ios::in);
150 //cout << "Opening " << name << " ... " << input << endl;
151 if (input == NULL) {
152 cerr << endl << "Unable to open " << name << ", is the directory correct?" << endl;
153 return false;
154 }
155
156 // skip some initial lines
157 for (int m=skiplines+1;m--;)
158 input.getline(Header, 1023);
159
160 // scan header for number of columns
161 line.str(Header);
162 for(int k=skipcolumns;k--;)
163 line >> Header;
164 //cout << line.str() << endl;
165 ColumnCounter[MatrixNr]=0;
166 while ( getline(line,token, '\t') ) {
167 if (token.length() > 0)
168 ColumnCounter[MatrixNr]++;
169 }
170 //cout << line.str() << endl;
171 cout << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;
172 if (ColumnCounter[MatrixNr] == 0)
173 cerr << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
174
175 // scan rest for number of rows/lines
176 RowCounter[MatrixNr]=-1; // counts one line too much
177 while (!input.eof()) {
178 input.getline(filename, 1023);
179 //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
180 RowCounter[MatrixNr]++; // then line was not last MeanForce
181 if (strncmp(filename,"MeanForce", 9) == 0) {
182 break;
183 }
184 }
185 cout << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
186 if (RowCounter[MatrixNr] == 0)
187 cerr << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
188
189 // allocate matrix if it's not zero dimension in one direction
190 if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) {
191 Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
192
193 // parse in each entry for this matrix
194 input.clear();
195 input.seekg(ios::beg);
196 for (int m=skiplines+1;m--;)
197 input.getline(Header, 1023); // skip header
198 line.str(Header);
199 for(int k=skipcolumns;k--;) // skip columns in header too
200 line >> filename;
201 strncpy(Header, line.str().c_str(), 1023);
202 for(int j=0;j<RowCounter[MatrixNr];j++) {
203 Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
204 input.getline(filename, 1023);
205 stringstream lines(filename);
206 //cout << "Matrix at level " << j << ":";// << filename << endl;
207 for(int k=skipcolumns;k--;)
208 lines >> filename;
209 for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
210 lines >> Matrix[MatrixNr][j][k];
211 //cout << " " << setprecision(2) << Matrix[MatrixNr][j][k];;
212 }
213 //cout << endl;
214 Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseFragmentMatrix: *Matrix[RowCounter[MatrixNr]][]");
215 for(int j=ColumnCounter[MatrixNr];j--;)
216 Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
217 }
218 } else {
219 cerr << "ERROR: Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl;
220 }
221 input.close();
222 return true;
223};
224
225/** Parsing a number of matrices.
226 * -# First, count the number of matrices by counting lines in KEYSETFILE
227 * -# Then,
228 * -# construct the fragment number
229 * -# open the matrix file
230 * -# skip some lines (\a skiplines)
231 * -# scan header lines for number of columns
232 * -# scan lines for number of rows
233 * -# allocate matrix
234 * -# loop over found column and row counts and parse in each entry
235 * -# Finally, allocate one additional matrix (\a MatrixCounter) containing combined or temporary values
236 * \param *name directory with files
237 * \param *prefix prefix of each matrix file
238 * \param *suffix suffix of each matrix file
239 * \param skiplines number of inital lines to skip
240 * \param skiplines number of inital columns to skip
241 * \return parsing successful
242 */
243bool MatrixContainer::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
244{
245 char filename[1023];
246 ifstream input;
247 char *FragmentNumber = NULL;
248 stringstream file;
249 string token;
250
251 // count the number of matrices
252 MatrixCounter = -1; // we count one too much
253 file << name << FRAGMENTPREFIX << KEYSETFILE;
254 input.open(file.str().c_str(), ios::in);
255 if (input == NULL) {
256 cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
257 return false;
258 }
259 while (!input.eof()) {
260 input.getline(filename, 1023);
261 stringstream zeile(filename);
262 MatrixCounter++;
263 }
264 input.close();
265 cout << "Determined " << MatrixCounter << " fragments." << endl;
266
267 cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl;
268 Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
269 RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
270 ColumnCounter = (int *) ReAlloc(ColumnCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
271 for(int i=MatrixCounter+1;i--;) {
272 Matrix[i] = NULL;
273 RowCounter[i] = -1;
274 ColumnCounter[i] = -1;
275 }
276 for(int i=0; i < MatrixCounter;i++) {
277 // open matrix file
278 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
279 file.str(" ");
280 file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix;
281 if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i))
282 return false;
283 Free((void **)&FragmentNumber, "MatrixContainer::ParseFragmentMatrix: *FragmentNumber");
284 }
285 return true;
286};
287
288/** Allocates and resets the memory for a number \a MCounter of matrices.
289 * \param *GivenHeader Header line
290 * \param MCounter number of matrices
291 * \param *RCounter number of rows for each matrix
292 * \param *CCounter number of columns for each matrices
293 * \return Allocation successful
294 */
295bool MatrixContainer::AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int *CCounter)
296{
297 Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseFragmentMatrix: *EnergyHeader");
298 strncpy(Header, GivenHeader, 1023);
299
300 MatrixCounter = MCounter;
301 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
302 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
303 ColumnCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
304 for(int i=MatrixCounter+1;i--;) {
305 RowCounter[i] = RCounter[i];
306 ColumnCounter[i] = CCounter[i];
307 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
308 for(int j=RowCounter[i]+1;j--;) {
309 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter[i], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
310 for(int k=ColumnCounter[i];k--;)
311 Matrix[i][j][k] = 0.;
312 }
313 }
314 return true;
315};
316
317/** Resets all values in MatrixContainer::Matrix.
318 * \return true if successful
319 */
320bool MatrixContainer::ResetMatrix()
321{
322 for(int i=MatrixCounter+1;i--;)
323 for(int j=RowCounter[i]+1;j--;)
324 for(int k=ColumnCounter[i];k--;)
325 Matrix[i][j][k] = 0.;
326 return true;
327};
328
329/** Scans all elements of MatrixContainer::Matrix for greatest absolute value.
330 * \return greatest value of MatrixContainer::Matrix
331 */
332double MatrixContainer::FindMaxValue()
333{
334 double max = Matrix[0][0][0];
335 for(int i=MatrixCounter+1;i--;)
336 for(int j=RowCounter[i]+1;j--;)
337 for(int k=ColumnCounter[i];k--;)
338 if (fabs(Matrix[i][j][k]) > max)
339 max = fabs(Matrix[i][j][k]);
340 if (fabs(max) < MYEPSILON)
341 max += MYEPSILON;
342 return max;
343};
344
345/** Scans all elements of MatrixContainer::Matrix for smallest absolute value.
346 * \return smallest value of MatrixContainer::Matrix
347 */
348double MatrixContainer::FindMinValue()
349{
350 double min = Matrix[0][0][0];
351 for(int i=MatrixCounter+1;i--;)
352 for(int j=RowCounter[i]+1;j--;)
353 for(int k=ColumnCounter[i];k--;)
354 if (fabs(Matrix[i][j][k]) < min)
355 min = fabs(Matrix[i][j][k]);
356 if (fabs(min) < MYEPSILON)
357 min += MYEPSILON;
358 return min;
359};
360
361/** Sets all values in the last of MatrixContainer::Matrix to \a value.
362 * \param value reset value
363 * \param skipcolumns skip initial columns
364 * \return true if successful
365 */
366bool MatrixContainer::SetLastMatrix(double value, int skipcolumns)
367{
368 for(int j=RowCounter[MatrixCounter]+1;j--;)
369 for(int k=skipcolumns;k<ColumnCounter[MatrixCounter];k++)
370 Matrix[MatrixCounter][j][k] = value;
371 return true;
372};
373
374/** Sets all values in the last of MatrixContainer::Matrix to \a value.
375 * \param **values matrix with each value (must have at least same dimensions!)
376 * \param skipcolumns skip initial columns
377 * \return true if successful
378 */
379bool MatrixContainer::SetLastMatrix(double **values, int skipcolumns)
380{
381 for(int j=RowCounter[MatrixCounter]+1;j--;)
382 for(int k=skipcolumns;k<ColumnCounter[MatrixCounter];k++)
383 Matrix[MatrixCounter][j][k] = values[j][k];
384 return true;
385};
386
387/** Sums the energy with each factor and put into last element of \a ***Energies.
388 * Sums over "E"-terms to create the "F"-terms
389 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
390 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
391 * \param Order bond order
392 * \return true if summing was successful
393 */
394bool MatrixContainer::SumSubManyBodyTerms(class MatrixContainer &MatrixValues, class KeySetsContainer &KeySet, int Order)
395{
396 // go through each order
397 for (int CurrentFragment=0;CurrentFragment<KeySet.FragmentsPerOrder[Order];CurrentFragment++) {
398 //cout << "Current Fragment is " << CurrentFragment << "/" << KeySet.OrderSet[Order][CurrentFragment] << "." << endl;
399 // then go per order through each suborder and pick together all the terms that contain this fragment
400 for(int SubOrder=0;SubOrder<=Order;SubOrder++) { // go through all suborders up to the desired order
401 for (int j=0;j<KeySet.FragmentsPerOrder[SubOrder];j++) { // go through all possible fragments of size suborder
402 if (KeySet.Contains(KeySet.OrderSet[Order][CurrentFragment], KeySet.OrderSet[SubOrder][j])) {
403 //cout << "Current other fragment is " << j << "/" << KeySet.OrderSet[SubOrder][j] << "." << endl;
404 // if the fragment's indices are all in the current fragment
405 for(int k=0;k<RowCounter[ KeySet.OrderSet[SubOrder][j] ];k++) { // go through all atoms in this fragment
406 int m = MatrixValues.Indices[ KeySet.OrderSet[SubOrder][j] ][k];
407 //cout << "Current index is " << k << "/" << m << "." << endl;
408 if (m != -1) { // if it's not an added hydrogen
409 for (int l=0;l<RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ];l++) { // look for the corresponding index in the current fragment
410 //cout << "Comparing " << m << " with " << MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][l] << "." << endl;
411 if (m == MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][l]) {
412 m = l;
413 break;
414 }
415 }
416 //cout << "Corresponding index in CurrentFragment is " << m << "." << endl;
417 if (m > RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ]) {
418 cerr << "In fragment No. " << KeySet.OrderSet[Order][CurrentFragment] << " current force index " << m << " is greater than " << RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ] << "!" << endl;
419 return false;
420 }
421 if (Order == SubOrder) { // equal order is always copy from Energies
422 for(int l=ColumnCounter[ KeySet.OrderSet[SubOrder][j] ];l--;) // then adds/subtract each column
423 Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][l] += MatrixValues.Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l];
424 } else {
425 for(int l=ColumnCounter[ KeySet.OrderSet[SubOrder][j] ];l--;)
426 Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][l] -= Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l];
427 }
428 }
429 //if ((ColumnCounter[ KeySet.OrderSet[SubOrder][j] ]>1) && (RowCounter[0]-1 >= 1))
430 //cout << "Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << RowCounter[0]-1 << "][" << 1 << "] = " << Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][RowCounter[0]-1][1] << endl;
431 }
432 } else {
433 //cout << "Fragment " << KeySet.OrderSet[SubOrder][j] << " is not contained in fragment " << KeySet.OrderSet[Order][CurrentFragment] << "." << endl;
434 }
435 }
436 }
437 //cout << "Final Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << KeySet.AtomCounter[0]-1 << "][" << 1 << "] = " << Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][KeySet.AtomCounter[0]-1][1] << endl;
438 }
439
440 return true;
441};
442
443/** Writes the summed total fragment terms \f$F_{ij}\f$ to file.
444 * \param *name inputdir
445 * \param *prefix prefix before \a EnergySuffix
446 * \return file was written
447 */
448bool MatrixContainer::WriteTotalFragments(const char *name, const char *prefix)
449{
450 ofstream output;
451 char *FragmentNumber = NULL;
452
453 cout << "Writing fragment files." << endl;
454 for(int i=0;i<MatrixCounter;i++) {
455 stringstream line;
456 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
457 line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix;
458 Free((void **)&FragmentNumber, "*FragmentNumber");
459 output.open(line.str().c_str(), ios::out);
460 if (output == NULL) {
461 cerr << "Unable to open output energy file " << line.str() << "!" << endl;
462 return false;
463 }
464 output << Header << endl;
465 for(int j=0;j<RowCounter[i];j++) {
466 for(int k=0;k<ColumnCounter[i];k++)
467 output << scientific << Matrix[i][j][k] << "\t";
468 output << endl;
469 }
470 output.close();
471 }
472 return true;
473};
474
475/** Writes the summed total values in the last matrix to file.
476 * \param *name inputdir
477 * \param *prefix prefix
478 * \param *suffix suffix
479 * \return file was written
480 */
481bool MatrixContainer::WriteLastMatrix(const char *name, const char *prefix, const char *suffix)
482{
483 ofstream output;
484 stringstream line;
485
486 cout << "Writing matrix values of " << suffix << "." << endl;
487 line << name << prefix << suffix;
488 output.open(line.str().c_str(), ios::out);
489 if (output == NULL) {
490 cerr << "Unable to open output matrix file " << line.str() << "!" << endl;
491 return false;
492 }
493 output << Header << endl;
494 for(int j=0;j<RowCounter[MatrixCounter];j++) {
495 for(int k=0;k<ColumnCounter[MatrixCounter];k++)
496 output << scientific << Matrix[MatrixCounter][j][k] << "\t";
497 output << endl;
498 }
499 output.close();
500 return true;
501};
502
503// ======================================= CLASS EnergyMatrix =============================
504
505/** Sums the energy with each factor and put into last element of \a EnergyMatrix::Matrix.
506 * Sums over the "F"-terms in ANOVA decomposition.
507 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
508 * \param CorrectionFragments MatrixContainer with hydrogen saturation correction per fragments
509 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
510 * \param Order bond order
511 * \parsm sign +1 or -1
512 * \return true if summing was successful
513 */
514bool EnergyMatrix::SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySet, int Order, double sign)
515{
516 // sum energy
517 if (CorrectionFragments == NULL)
518 for(int i=KeySet.FragmentsPerOrder[Order];i--;)
519 for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
520 for(int k=ColumnCounter[ KeySet.OrderSet[Order][i] ];k--;)
521 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k];
522 else
523 for(int i=KeySet.FragmentsPerOrder[Order];i--;)
524 for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
525 for(int k=ColumnCounter[ KeySet.OrderSet[Order][i] ];k--;)
526 Matrix[MatrixCounter][j][k] += sign*(Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k] + CorrectionFragments->Matrix[ KeySet.OrderSet[Order][i] ][j][k]);
527 return true;
528};
529
530/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
531 * \param *name directory with files
532 * \param *prefix prefix of each matrix file
533 * \param *suffix suffix of each matrix file
534 * \param skiplines number of inital lines to skip
535 * \param skiplines number of inital columns to skip
536 * \return parsing successful
537 */
538bool EnergyMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
539{
540 char filename[1024];
541 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
542
543 if (status) {
544 // count maximum of columns
545 RowCounter[MatrixCounter] = 0;
546 ColumnCounter[MatrixCounter] = 0;
547 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
548 if (RowCounter[j] > RowCounter[MatrixCounter])
549 RowCounter[MatrixCounter] = RowCounter[j];
550 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
551 ColumnCounter[MatrixCounter] = ColumnCounter[j];
552 }
553 // allocate last plus one matrix
554 cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
555 Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
556 for(int j=0;j<=RowCounter[MatrixCounter];j++)
557 Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
558
559 // try independently to parse global energysuffix file if present
560 strncpy(filename, name, 1023);
561 strncat(filename, prefix, 1023-strlen(filename));
562 strncat(filename, suffix.c_str(), 1023-strlen(filename));
563 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
564 }
565 return status;
566};
567
568// ======================================= CLASS ForceMatrix =============================
569
570/** Parsing force Indices of each fragment
571 * \param *name directory with \a ForcesFile
572 * \return parsing successful
573 */
574bool ForceMatrix::ParseIndices(char *name)
575{
576 ifstream input;
577 char *FragmentNumber = NULL;
578 char filename[1023];
579 stringstream line;
580
581 cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
582 Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "ForceMatrix::ParseIndices: **Indices");
583 line << name << FRAGMENTPREFIX << FORCESFILE;
584 input.open(line.str().c_str(), ios::in);
585 //cout << "Opening " << line.str() << " ... " << input << endl;
586 if (input == NULL) {
587 cout << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
588 return false;
589 }
590 for (int i=0;(i<MatrixCounter) && (!input.eof());i++) {
591 // get the number of atoms for this fragment
592 input.getline(filename, 1023);
593 line.str(filename);
594 // parse the values
595 Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
596 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
597 //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
598 Free((void **)&FragmentNumber, "ForceMatrix::ParseIndices: *FragmentNumber");
599 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
600 line >> Indices[i][j];
601 //cout << " " << Indices[i][j];
602 }
603 //cout << endl;
604 }
605 Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
606 for(int j=RowCounter[MatrixCounter];j--;) {
607 Indices[MatrixCounter][j] = j;
608 }
609 input.close();
610 return true;
611};
612
613
614/** Sums the forces and puts into last element of \a ForceMatrix::Matrix.
615 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
616 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
617 * \param Order bond order
618 * \param sign +1 or -1
619 * \return true if summing was successful
620 */
621bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign)
622{
623 int FragmentNr;
624 // sum forces
625 for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++) {
626 FragmentNr = KeySet.OrderSet[Order][i];
627 for(int l=0;l<RowCounter[ FragmentNr ];l++) {
628 int j = Indices[ FragmentNr ][l];
629 if (j > RowCounter[MatrixCounter]) {
630 cerr << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl;
631 return false;
632 }
633 if (j != -1) {
634 //if (j == 0) cout << "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << "." << endl;
635 for(int k=2;k<ColumnCounter[MatrixCounter];k++)
636 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][k];
637 }
638 }
639 }
640 return true;
641};
642
643
644/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
645 * \param *name directory with files
646 * \param *prefix prefix of each matrix file
647 * \param *suffix suffix of each matrix file
648 * \param skiplines number of inital lines to skip
649 * \param skiplines number of inital columns to skip
650 * \return parsing successful
651 */
652bool ForceMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
653{
654 char filename[1023];
655 ifstream input;
656 stringstream file;
657 int nr;
658 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
659
660 if (status) {
661 // count number of atoms for last plus one matrix
662 file << name << FRAGMENTPREFIX << KEYSETFILE;
663 input.open(file.str().c_str(), ios::in);
664 if (input == NULL) {
665 cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
666 return false;
667 }
668 RowCounter[MatrixCounter] = 0;
669 while (!input.eof()) {
670 input.getline(filename, 1023);
671 stringstream zeile(filename);
672 while (!zeile.eof()) {
673 zeile >> nr;
674 //cout << "Current index: " << nr << "." << endl;
675 if (nr > RowCounter[MatrixCounter])
676 RowCounter[MatrixCounter] = nr;
677 }
678 }
679 RowCounter[MatrixCounter]++; // nr start at 0, count starts at 1
680 input.close();
681
682 ColumnCounter[MatrixCounter] = 0;
683 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
684 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
685 ColumnCounter[MatrixCounter] = ColumnCounter[j];
686 }
687
688 // allocate last plus one matrix
689 cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
690 Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
691 for(int j=0;j<=RowCounter[MatrixCounter];j++)
692 Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
693
694 // try independently to parse global forcesuffix file if present
695 strncpy(filename, name, 1023);
696 strncat(filename, prefix, 1023-strlen(filename));
697 strncat(filename, suffix.c_str(), 1023-strlen(filename));
698 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
699 }
700
701
702 return status;
703};
704
705// ======================================= CLASS HessianMatrix =============================
706
707/** Parsing force Indices of each fragment
708 * \param *name directory with \a ForcesFile
709 * \return parsing successful
710 */
711bool HessianMatrix::ParseIndices(char *name)
712{
713 ifstream input;
714 char *FragmentNumber = NULL;
715 char filename[1023];
716 stringstream line;
717
718 cout << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl;
719 Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "HessianMatrix::ParseIndices: **Indices");
720 line << name << FRAGMENTPREFIX << FORCESFILE;
721 input.open(line.str().c_str(), ios::in);
722 //cout << "Opening " << line.str() << " ... " << input << endl;
723 if (input == NULL) {
724 cout << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
725 return false;
726 }
727 for (int i=0;(i<MatrixCounter) && (!input.eof());i++) {
728 // get the number of atoms for this fragment
729 input.getline(filename, 1023);
730 line.str(filename);
731 // parse the values
732 Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
733 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
734 //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
735 Free((void **)&FragmentNumber, "HessianMatrix::ParseIndices: *FragmentNumber");
736 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
737 line >> Indices[i][j];
738 //cout << " " << Indices[i][j];
739 }
740 //cout << endl;
741 }
742 Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
743 for(int j=RowCounter[MatrixCounter];j--;) {
744 Indices[MatrixCounter][j] = j;
745 }
746 input.close();
747 return true;
748};
749
750
751/** Sums the hessian entries and puts into last element of \a HessianMatrix::Matrix.
752 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
753 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
754 * \param Order bond order
755 * \param sign +1 or -1
756 * \return true if summing was successful
757 */
758bool HessianMatrix::SumSubHessians(class HessianMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign)
759{
760 int FragmentNr;
761 // sum forces
762 for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++) {
763 FragmentNr = KeySet.OrderSet[Order][i];
764 for(int l=0;l<RowCounter[ FragmentNr ];l++) {
765 int j = Indices[ FragmentNr ][l];
766 if (j > RowCounter[MatrixCounter]) {
767 cerr << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl;
768 return false;
769 }
770 if (j != -1) {
771 for(int m=0;m<ColumnCounter[ FragmentNr ];m++) {
772 int k = Indices[ FragmentNr ][m];
773 if (k > ColumnCounter[MatrixCounter]) {
774 cerr << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << "!" << endl;
775 return false;
776 }
777 if (k != -1) {
778 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][m];
779 }
780 }
781 }
782 }
783 }
784 return true;
785};
786
787
788/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
789 * \param *name directory with files
790 * \param *prefix prefix of each matrix file
791 * \param *suffix suffix of each matrix file
792 * \param skiplines number of inital lines to skip
793 * \param skiplines number of inital columns to skip
794 * \return parsing successful
795 */
796bool HessianMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
797{
798 char filename[1023];
799 ifstream input;
800 stringstream file;
801 int nr;
802 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
803
804 if (status) {
805 // count number of atoms for last plus one matrix
806 file << name << FRAGMENTPREFIX << KEYSETFILE;
807 input.open(file.str().c_str(), ios::in);
808 if (input == NULL) {
809 cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
810 return false;
811 }
812 RowCounter[MatrixCounter] = 0;
813 ColumnCounter[MatrixCounter] = 0;
814 while (!input.eof()) {
815 input.getline(filename, 1023);
816 stringstream zeile(filename);
817 while (!zeile.eof()) {
818 zeile >> nr;
819 //cout << "Current index: " << nr << "." << endl;
820 if (nr > RowCounter[MatrixCounter]) {
821 RowCounter[MatrixCounter] = nr;
822 ColumnCounter[MatrixCounter] = nr;
823 }
824 }
825 }
826 RowCounter[MatrixCounter]++; // nr start at 0, count starts at 1
827 ColumnCounter[MatrixCounter]++; // nr start at 0, count starts at 1
828 input.close();
829
830 // allocate last plus one matrix
831 cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
832 Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
833 for(int j=0;j<=RowCounter[MatrixCounter];j++)
834 Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
835
836 // try independently to parse global forcesuffix file if present
837 strncpy(filename, name, 1023);
838 strncat(filename, prefix, 1023-strlen(filename));
839 strncat(filename, suffix.c_str(), 1023-strlen(filename));
840 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
841 }
842
843
844 return status;
845};
846
847// ======================================= CLASS KeySetsContainer =============================
848
849/** Constructor of KeySetsContainer class.
850 */
851KeySetsContainer::KeySetsContainer() {
852 KeySets = NULL;
853 AtomCounter = NULL;
854 FragmentCounter = 0;
855 Order = 0;
856 FragmentsPerOrder = 0;
857 OrderSet = NULL;
858};
859
860/** Destructor of KeySetsContainer class.
861 */
862KeySetsContainer::~KeySetsContainer() {
863 for(int i=FragmentCounter;i--;)
864 Free((void **)&KeySets[i], "KeySetsContainer::~KeySetsContainer: *KeySets[]");
865 for(int i=Order;i--;)
866 Free((void **)&OrderSet[i], "KeySetsContainer::~KeySetsContainer: *OrderSet[]");
867 Free((void **)&KeySets, "KeySetsContainer::~KeySetsContainer: **KeySets");
868 Free((void **)&OrderSet, "KeySetsContainer::~KeySetsContainer: **OrderSet");
869 Free((void **)&AtomCounter, "KeySetsContainer::~KeySetsContainer: *AtomCounter");
870 Free((void **)&FragmentsPerOrder, "KeySetsContainer::~KeySetsContainer: *FragmentsPerOrder");
871};
872
873/** Parsing KeySets into array.
874 * \param *name directory with keyset file
875 * \param *ACounter number of atoms per fragment
876 * \param FCounter number of fragments
877 * \return parsing succesful
878 */
879bool KeySetsContainer::ParseKeySets(const char *name, const int *ACounter, const int FCounter) {
880 ifstream input;
881 char *FragmentNumber = NULL;
882 stringstream file;
883 char filename[1023];
884
885 FragmentCounter = FCounter;
886 cout << "Parsing key sets." << endl;
887 KeySets = (int **) Malloc(sizeof(int *)*FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
888 for(int i=FragmentCounter;i--;)
889 KeySets[i] = NULL;
890 file << name << FRAGMENTPREFIX << KEYSETFILE;
891 input.open(file.str().c_str(), ios::in);
892 if (input == NULL) {
893 cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
894 return false;
895 }
896
897 AtomCounter = (int *) Malloc(sizeof(int)*FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
898 for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
899 stringstream line;
900 AtomCounter[i] = ACounter[i];
901 // parse the values
902 KeySets[i] = (int *) Malloc(sizeof(int)*AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
903 for(int j=AtomCounter[i];j--;)
904 KeySets[i][j] = -1;
905 FragmentNumber = FixedDigitNumber(FragmentCounter, i);
906 //cout << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
907 Free((void **)&FragmentNumber, "KeySetsContainer::ParseKeySets: *FragmentNumber");
908 input.getline(filename, 1023);
909 line.str(filename);
910 for(int j=0;(j<AtomCounter[i]) && (!line.eof());j++) {
911 line >> KeySets[i][j];
912 //cout << " " << KeySets[i][j];
913 }
914 //cout << endl;
915 }
916 input.close();
917 return true;
918};
919
920/** Parse many body terms, associating each fragment to a certain bond order.
921 * \return parsing succesful
922 */
923bool KeySetsContainer::ParseManyBodyTerms()
924{
925 int Counter;
926
927 cout << "Creating Fragment terms." << endl;
928 // scan through all to determine maximum order
929 Order=0;
930 for(int i=FragmentCounter;i--;) {
931 Counter=0;
932 for(int j=AtomCounter[i];j--;)
933 if (KeySets[i][j] != -1)
934 Counter++;
935 if (Counter > Order)
936 Order = Counter;
937 }
938 cout << "Found Order is " << Order << "." << endl;
939
940 // scan through all to determine fragments per order
941 FragmentsPerOrder = (int *) Malloc(sizeof(int)*Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
942 for(int i=Order;i--;)
943 FragmentsPerOrder[i] = 0;
944 for(int i=FragmentCounter;i--;) {
945 Counter=0;
946 for(int j=AtomCounter[i];j--;)
947 if (KeySets[i][j] != -1)
948 Counter++;
949 FragmentsPerOrder[Counter-1]++;
950 }
951 for(int i=0;i<Order;i++)
952 cout << "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << "." << endl;
953
954 // scan through all to gather indices to each order set
955 OrderSet = (int **) Malloc(sizeof(int *)*Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
956 for(int i=Order;i--;)
957 OrderSet[i] = (int *) Malloc(sizeof(int)*FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
958 for(int i=Order;i--;)
959 FragmentsPerOrder[i] = 0;
960 for(int i=FragmentCounter;i--;) {
961 Counter=0;
962 for(int j=AtomCounter[i];j--;)
963 if (KeySets[i][j] != -1)
964 Counter++;
965 OrderSet[Counter-1][FragmentsPerOrder[Counter-1]] = i;
966 FragmentsPerOrder[Counter-1]++;
967 }
968 cout << "Printing OrderSet." << endl;
969 for(int i=0;i<Order;i++) {
970 for (int j=0;j<FragmentsPerOrder[i];j++) {
971 cout << " " << OrderSet[i][j];
972 }
973 cout << endl;
974 }
975 cout << endl;
976
977
978 return true;
979};
980
981/** Compares each entry in \a *SmallerSet if it is containted in \a *GreaterSet.
982 * \param GreaterSet index to greater set
983 * \param SmallerSet index to smaller set
984 * \return true if all keys of SmallerSet contained in GreaterSet
985 */
986bool KeySetsContainer::Contains(const int GreaterSet, const int SmallerSet)
987{
988 bool result = true;
989 bool intermediate;
990 if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
991 return false;
992 for(int i=AtomCounter[SmallerSet];i--;) {
993 intermediate = false;
994 for (int j=AtomCounter[GreaterSet];j--;)
995 intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
996 result = result && intermediate;
997 }
998
999 return result;
1000};
1001
1002
1003// ======================================= END =============================================
Note: See TracBrowser for help on using the repository browser.