source: src/moleculelist.cpp@ b66c22

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 b66c22 was 29812d, checked in by Saskia Metzler <metzler@…>, 16 years ago

Ticket 11: use templates and/or traits to fix Malloc/ReAlloc-Free warnings in a clean manner

  • Property mode set to 100755
File size: 38.2 KB
RevLine 
[14de469]1/** \file MoleculeListClass.cpp
[1907a7]2 *
[14de469]3 * Function implementations for the class MoleculeListClass.
[1907a7]4 *
[14de469]5 */
6
[a80fbdf]7#include "config.hpp"
[14de469]8#include "molecules.hpp"
[29812d]9#include "memoryallocator.hpp"
[14de469]10
11/*********************************** Functions for class MoleculeListClass *************************/
12
13/** Constructor for MoleculeListClass.
14 */
15MoleculeListClass::MoleculeListClass()
16{
[1907a7]17 // empty lists
18 ListOfMolecules.clear();
19 MaxIndex = 1;
[14de469]20};
21
22/** Destructor for MoleculeListClass.
23 */
24MoleculeListClass::~MoleculeListClass()
25{
[db942e]26 cout << Verbose(3) << this << ": Freeing ListOfMolcules." << endl;
[1907a7]27 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
28 cout << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl;
29 delete (*ListRunner);
[14de469]30 }
31 cout << Verbose(4) << "Freeing ListOfMolecules." << endl;
[1907a7]32 ListOfMolecules.clear(); // empty list
[14de469]33};
34
[1907a7]35/** Insert a new molecule into the list and set its number.
36 * \param *mol molecule to add to list.
37 * \return true - add successful
[14de469]38 */
[178f92]39void MoleculeListClass::insert(molecule *mol)
[14de469]40{
[1907a7]41 mol->IndexNr = MaxIndex++;
42 ListOfMolecules.push_back(mol);
[14de469]43};
44
[db942e]45/** Compare whether two molecules are equal.
46 * \param *a molecule one
47 * \param *n molecule two
48 * \return lexical value (-1, 0, +1)
49 */
[14de469]50int MolCompare(const void *a, const void *b)
51{
52 int *aList = NULL, *bList = NULL;
53 int Count, Counter, aCounter, bCounter;
54 int flag;
55 atom *aWalker = NULL;
56 atom *bWalker = NULL;
[1907a7]57
[14de469]58 // sort each atom list and put the numbers into a list, then go through
59 //cout << "Comparing fragment no. " << *(molecule **)a << " to " << *(molecule **)b << "." << endl;
[1907a7]60 if ((**(molecule **) a).AtomCount < (**(molecule **) b).AtomCount) {
[14de469]61 return -1;
[1907a7]62 } else {
63 if ((**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount)
64 return +1;
[14de469]65 else {
[1907a7]66 Count = (**(molecule **) a).AtomCount;
[7f3b9d]67 aList = new int[Count];
68 bList = new int[Count];
[1907a7]69
[14de469]70 // fill the lists
[1907a7]71 aWalker = (**(molecule **) a).start;
72 bWalker = (**(molecule **) b).start;
[14de469]73 Counter = 0;
74 aCounter = 0;
75 bCounter = 0;
[1907a7]76 while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) {
[14de469]77 aWalker = aWalker->next;
78 bWalker = bWalker->next;
79 if (aWalker->GetTrueFather() == NULL)
80 aList[Counter] = Count + (aCounter++);
81 else
82 aList[Counter] = aWalker->GetTrueFather()->nr;
83 if (bWalker->GetTrueFather() == NULL)
84 bList[Counter] = Count + (bCounter++);
85 else
86 bList[Counter] = bWalker->GetTrueFather()->nr;
87 Counter++;
88 }
89 // check if AtomCount was for real
90 flag = 0;
[1907a7]91 if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) {
[14de469]92 flag = -1;
93 } else {
[1907a7]94 if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **) b).end))
[14de469]95 flag = 1;
96 }
97 if (flag == 0) {
98 // sort the lists
[1907a7]99 gsl_heapsort(aList, Count, sizeof(int), CompareDoubles);
100 gsl_heapsort(bList, Count, sizeof(int), CompareDoubles);
101 // compare the lists
102
[14de469]103 flag = 0;
[1907a7]104 for (int i = 0; i < Count; i++) {
[14de469]105 if (aList[i] < bList[i]) {
106 flag = -1;
107 } else {
108 if (aList[i] > bList[i])
109 flag = 1;
110 }
111 if (flag != 0)
112 break;
113 }
114 }
[1907a7]115 delete[] (aList);
116 delete[] (bList);
[14de469]117 return flag;
118 }
119 }
[1907a7]120 return -1;
121};
122
123/** Output of a list of all molecules.
124 * \param *out output stream
125 */
126void MoleculeListClass::Enumerate(ofstream *out)
127{
128 element* Elemental = NULL;
129 atom *Walker = NULL;
130 int Counts[MAX_ELEMENTS];
[3af1f0]131 double size=0;
132 Vector Origin;
[1907a7]133
134 // header
[3af1f0]135 *out << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
[1907a7]136 cout << Verbose(0) << "-----------------------------------------------" << endl;
137 if (ListOfMolecules.size() == 0)
138 *out << "\tNone" << endl;
139 else {
[3af1f0]140 Origin.Zero();
[1907a7]141 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
142 // reset element counts
143 for (int j = 0; j<MAX_ELEMENTS;j++)
144 Counts[j] = 0;
[3af1f0]145 // count atoms per element and determine size of bounding sphere
146 size=0.;
[1907a7]147 Walker = (*ListRunner)->start;
148 while (Walker->next != (*ListRunner)->end) {
149 Walker = Walker->next;
150 Counts[Walker->type->Z]++;
[3af1f0]151 if (Walker->x.DistanceSquared(&Origin) > size)
152 size = Walker->x.DistanceSquared(&Origin);
[1907a7]153 }
154 // output Index, Name, number of atoms, chemical formula
155 *out << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
156 Elemental = (*ListRunner)->elemente->end;
[3af1f0]157 while(Elemental->previous != (*ListRunner)->elemente->start) {
[1907a7]158 Elemental = Elemental->previous;
159 if (Counts[Elemental->Z] != 0)
160 *out << Elemental->symbol << Counts[Elemental->Z];
161 }
[3af1f0]162 // Center and size
163 *out << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
[1907a7]164 }
165 }
166};
167
168/** Returns the molecule with the given index \a index.
169 * \param index index of the desired molecule
170 * \return pointer to molecule structure, NULL if not found
171 */
172molecule * MoleculeListClass::ReturnIndex(int index)
173{
[3af1f0]174 for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
175 if ((*ListRunner)->IndexNr == index)
176 return (*ListRunner);
177 return NULL;
[1907a7]178};
179
180/** Simple merge of two molecules into one.
181 * \param *mol destination molecule
182 * \param *srcmol source molecule
183 * \return true - merge successful, false - merge failed (probably due to non-existant indices
184 */
185bool MoleculeListClass::SimpleMerge(molecule *mol, molecule *srcmol)
186{
187 if (srcmol == NULL)
188 return false;
189
190 // put all molecules of src into mol
191 atom *Walker = srcmol->start;
192 atom *NextAtom = Walker->next;
193 while (NextAtom != srcmol->end) {
194 Walker = NextAtom;
195 NextAtom = Walker->next;
196 srcmol->UnlinkAtom(Walker);
197 mol->AddAtom(Walker);
198 }
199
200 // remove src
201 ListOfMolecules.remove(srcmol);
202 delete(srcmol);
203 return true;
204};
205
206/** Simple add of one molecules into another.
207 * \param *mol destination molecule
208 * \param *srcmol source molecule
209 * \return true - merge successful, false - merge failed (probably due to non-existant indices
210 */
211bool MoleculeListClass::SimpleAdd(molecule *mol, molecule *srcmol)
212{
213 if (srcmol == NULL)
214 return false;
215
216 // put all molecules of src into mol
217 atom *Walker = srcmol->start;
218 atom *NextAtom = Walker->next;
219 while (NextAtom != srcmol->end) {
220 Walker = NextAtom;
221 NextAtom = Walker->next;
222 Walker = mol->AddCopyAtom(Walker);
223 Walker->father = Walker;
224 }
225
226 return true;
227};
228
229/** Simple merge of a given set of molecules into one.
230 * \param *mol destination molecule
231 * \param *src index of set of source molecule
232 * \param N number of source molecules
233 * \return true - merge successful, false - some merges failed (probably due to non-existant indices)
234 */
235bool MoleculeListClass::SimpleMultiMerge(molecule *mol, int *src, int N)
236{
237 bool status = true;
238 // check presence of all source molecules
239 for (int i=0;i<N;i++) {
240 molecule *srcmol = ReturnIndex(src[i]);
241 status = status && SimpleMerge(mol, srcmol);
242 }
243 return status;
244};
245
246/** Simple add of a given set of molecules into one.
247 * \param *mol destination molecule
248 * \param *src index of set of source molecule
249 * \param N number of source molecules
250 * \return true - merge successful, false - some merges failed (probably due to non-existant indices)
251 */
252bool MoleculeListClass::SimpleMultiAdd(molecule *mol, int *src, int N)
253{
254 bool status = true;
255 // check presence of all source molecules
256 for (int i=0;i<N;i++) {
257 molecule *srcmol = ReturnIndex(src[i]);
258 status = status && SimpleAdd(mol, srcmol);
259 }
260 return status;
261};
262
263/** Scatter merge of a given set of molecules into one.
264 * Scatter merge distributes the molecules in such a manner that they don't overlap.
265 * \param *mol destination molecule
266 * \param *src index of set of source molecule
267 * \param N number of source molecules
268 * \return true - merge successful, false - merge failed (probably due to non-existant indices
269 * \TODO find scatter center for each src molecule
270 */
271bool MoleculeListClass::ScatterMerge(molecule *mol, int *src, int N)
272{
273 // check presence of all source molecules
274 for (int i=0;i<N;i++) {
275 // get pointer to src molecule
276 molecule *srcmol = ReturnIndex(src[i]);
277 if (srcmol == NULL)
278 return false;
279 }
280 // adapt each Center
281 for (int i=0;i<N;i++) {
282 // get pointer to src molecule
283 molecule *srcmol = ReturnIndex(src[i]);
284 //srcmol->Center.Zero();
285 srcmol->Translate(&srcmol->Center);
286 }
287 // perform a simple multi merge
288 SimpleMultiMerge(mol, src, N);
289 return true;
290};
291
292/** Embedding merge of a given set of molecules into one.
293 * Embedding merge inserts one molecule into the other.
294 * \param *mol destination molecule
295 * \param *srcmol source molecule
296 * \return true - merge successful, false - merge failed (probably due to non-existant indices
297 * \TODO find embedding center
298 */
299bool MoleculeListClass::EmbedMerge(molecule *mol, molecule *srcmol)
300{
301 if (srcmol == NULL)
302 return false;
303
304 // calculate center for merge
[ca2587]305 srcmol->Center.CopyVector(mol->FindEmbeddingHole((ofstream *)&cout, srcmol));
306 srcmol->Center.Zero();
[1907a7]307
308 // perform simple merge
309 SimpleMerge(mol, srcmol);
310 return true;
[14de469]311};
312
313/** Simple output of the pointers in ListOfMolecules.
314 * \param *out output stream
315 */
316void MoleculeListClass::Output(ofstream *out)
317{
[1907a7]318 *out << Verbose(1) << "MoleculeList: ";
319 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
320 *out << *ListRunner << "\t";
[14de469]321 *out << endl;
322};
323
[390248]324/** Calculates necessary hydrogen correction due to unwanted interaction between saturated ones.
325 * If for a pair of two hydrogen atoms a and b, at least is a saturated one, and a and b are not
326 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse
327 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance.
328 * \param *out output stream for debugging
329 * \param *path path to file
330 */
331bool MoleculeListClass::AddHydrogenCorrection(ofstream *out, char *path)
332{
333 atom *Walker = NULL;
334 atom *Runner = NULL;
335 double ***FitConstant = NULL, **correction = NULL;
[1907a7]336 int a, b;
[390248]337 ofstream output;
338 ifstream input;
339 string line;
340 stringstream zeile;
341 double distance;
342 char ParsedLine[1023];
343 double tmp;
344 char *FragmentNumber = NULL;
345
346 cout << Verbose(1) << "Saving hydrogen saturation correction ... ";
347 // 0. parse in fit constant files that should have the same dimension as the final energy files
348 // 0a. find dimension of matrices with constants
349 line = path;
350 line.append("/");
351 line += FRAGMENTPREFIX;
352 line += "1";
353 line += FITCONSTANTSUFFIX;
354 input.open(line.c_str());
355 if (input == NULL) {
[1907a7]356 cerr << endl << "Unable to open " << line << ", is the directory correct?"
357 << endl;
[390248]358 return false;
359 }
[1907a7]360 a = 0;
361 b = -1; // we overcount by one
[390248]362 while (!input.eof()) {
363 input.getline(ParsedLine, 1023);
364 zeile.str(ParsedLine);
[1907a7]365 int i = 0;
[390248]366 while (!zeile.eof()) {
367 zeile >> distance;
368 i++;
369 }
[1907a7]370 if (i > a)
371 a = i;
[390248]372 b++;
373 }
374 cout << "I recognized " << a << " columns and " << b << " rows, ";
375 input.close();
[1907a7]376
[390248]377 // 0b. allocate memory for constants
[29812d]378 FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
[1907a7]379 for (int k = 0; k < 3; k++) {
[29812d]380 FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
[1907a7]381 for (int i = a; i--;) {
[29812d]382 FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
[390248]383 }
384 }
385 // 0c. parse in constants
[1907a7]386 for (int i = 0; i < 3; i++) {
[390248]387 line = path;
388 line.append("/");
389 line += FRAGMENTPREFIX;
[1907a7]390 sprintf(ParsedLine, "%d", i + 1);
[390248]391 line += ParsedLine;
392 line += FITCONSTANTSUFFIX;
393 input.open(line.c_str());
394 if (input == NULL) {
395 cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl;
396 return false;
397 }
[1907a7]398 int k = 0, l;
[390248]399 while ((!input.eof()) && (k < b)) {
400 input.getline(ParsedLine, 1023);
401 //cout << "Current Line: " << ParsedLine << endl;
402 zeile.str(ParsedLine);
403 zeile.clear();
404 l = 0;
405 while ((!zeile.eof()) && (l < a)) {
406 zeile >> FitConstant[i][l][k];
407 //cout << FitConstant[i][l][k] << "\t";
408 l++;
409 }
410 //cout << endl;
411 k++;
412 }
413 input.close();
414 }
[1907a7]415 for (int k = 0; k < 3; k++) {
[390248]416 cout << "Constants " << k << ":" << endl;
[1907a7]417 for (int j = 0; j < b; j++) {
418 for (int i = 0; i < a; i++) {
[390248]419 cout << FitConstant[k][i][j] << "\t";
420 }
421 cout << endl;
422 }
423 cout << endl;
424 }
[1907a7]425
[390248]426 // 0d. allocate final correction matrix
[29812d]427 correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
[1907a7]428 for (int i = a; i--;)
[29812d]429 correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
[1907a7]430
[390248]431 // 1a. go through every molecule in the list
[1907a7]432 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
[390248]433 // 1b. zero final correction matrix
[1907a7]434 for (int k = a; k--;)
435 for (int j = b; j--;)
[390248]436 correction[k][j] = 0.;
437 // 2. take every hydrogen that is a saturated one
[1907a7]438 Walker = (*ListRunner)->start;
439 while (Walker->next != (*ListRunner)->end) {
[390248]440 Walker = Walker->next;
[1907a7]441 //cout << Verbose(1) << "Walker: " << *Walker << " with first bond " << *(*Runner)->ListOfBondsPerAtom[Walker->nr][0] << "." << endl;
442 if ((Walker->type->Z == 1) && ((Walker->father == NULL)
443 || (Walker->father->type->Z != 1))) { // if it's a hydrogen
444 Runner = (*ListRunner)->start;
445 while (Runner->next != (*ListRunner)->end) {
[390248]446 Runner = Runner->next;
[1907a7]447 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << *(*Runner)->ListOfBondsPerAtom[Runner->nr][0] << "." << endl;
[390248]448 // 3. take every other hydrogen that is the not the first and not bound to same bonding partner
[1907a7]449 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && ((*ListRunner)->ListOfBondsPerAtom[Runner->nr][0]->GetOtherAtom(Runner) != (*ListRunner)->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!)
[390248]450 // 4. evaluate the morse potential for each matrix component and add up
[1907a7]451 distance = Runner->x.Distance(&Walker->x);
452 //cout << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl;
453 for (int k = 0; k < a; k++) {
454 for (int j = 0; j < b; j++) {
455 switch (k) {
456 case 1:
457 case 7:
458 case 11:
459 tmp = pow(FitConstant[0][k][j] * (1. - exp(-FitConstant[1][k][j] * (distance - FitConstant[2][k][j]))), 2);
460 break;
461 default:
462 tmp = FitConstant[0][k][j] * pow(distance, FitConstant[1][k][j]) + FitConstant[2][k][j];
[390248]463 };
[1907a7]464 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction)
[390248]465 //cout << tmp << "\t";
466 }
467 //cout << endl;
468 }
469 //cout << endl;
470 }
471 }
472 }
473 }
474 // 5. write final matrix to file
475 line = path;
476 line.append("/");
477 line += FRAGMENTPREFIX;
[1907a7]478 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), (*ListRunner)->IndexNr);
[390248]479 line += FragmentNumber;
[1907a7]480 delete (FragmentNumber);
[390248]481 line += HCORRECTIONSUFFIX;
482 output.open(line.c_str());
483 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl;
[1907a7]484 for (int j = 0; j < b; j++) {
485 for (int i = 0; i < a; i++)
[390248]486 output << correction[i][j] << "\t";
487 output << endl;
488 }
489 output.close();
490 }
491 line = path;
492 line.append("/");
493 line += HCORRECTIONSUFFIX;
494 output.open(line.c_str());
495 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl;
[1907a7]496 for (int j = 0; j < b; j++) {
497 for (int i = 0; i < a; i++)
[390248]498 output << 0 << "\t";
499 output << endl;
500 }
501 output.close();
502 // 6. free memory of parsed matrices
[29812d]503 FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
[1907a7]504 for (int k = 0; k < 3; k++) {
[29812d]505 FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
[1907a7]506 for (int i = a; i--;) {
[29812d]507 FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
[390248]508 }
509 }
510 cout << "done." << endl;
511 return true;
512};
[2459b1]513
514/** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config.
515 * \param *out output stream for debugging
516 * \param *path path to file
517 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
518 * \return true - file written successfully, false - writing failed
519 */
[1907a7]520bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path,
521 int *SortIndex)
[2459b1]522{
523 bool status = true;
524 ofstream ForcesFile;
525 stringstream line;
526 atom *Walker = NULL;
527 element *runner = NULL;
528
529 // open file for the force factors
530 *out << Verbose(1) << "Saving force factors ... ";
531 line << path << "/" << FRAGMENTPREFIX << FORCESFILE;
532 ForcesFile.open(line.str().c_str(), ios::out);
533 if (ForcesFile != NULL) {
534 //cout << Verbose(1) << "Final AtomicForcesList: ";
535 //output << prefix << "Forces" << endl;
[1907a7]536 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
537 runner = (*ListRunner)->elemente->start;
538 while (runner->next != (*ListRunner)->elemente->end) { // go through every element
[2459b1]539 runner = runner->next;
[1907a7]540 if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms
541 Walker = (*ListRunner)->start;
542 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element
[2459b1]543 Walker = Walker->next;
544 if (Walker->type->Z == runner->Z) {
545 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
546 //cout << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
[1907a7]547 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t";
548 } else
549 // otherwise a -1 to indicate an added saturation hydrogen
550 ForcesFile << "-1\t";
[2459b1]551 }
552 }
[1907a7]553 }
[2459b1]554 }
555 ForcesFile << endl;
556 }
557 ForcesFile.close();
558 *out << Verbose(1) << "done." << endl;
559 } else {
560 status = false;
561 *out << Verbose(1) << "failed to open file " << line.str() << "." << endl;
562 }
563 ForcesFile.close();
[1907a7]564
[2459b1]565 return status;
566};
567
[14de469]568/** Writes a config file for each molecule in the given \a **FragmentList.
[db942e]569 * \param *out output stream for debugging
[14de469]570 * \param *configuration standard configuration to attach atoms in fragment molecule to.
571 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
[85bac0]572 * \param DoPeriodic true - call ScanForPeriodicCorrection, false - don't
573 * \param DoCentering true - call molecule::CenterEdge(), false - don't
[14de469]574 * \return true - success (each file was written), false - something went wrong.
575 */
[d067d45]576bool MoleculeListClass::OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex)
[14de469]577{
578 ofstream outputFragment;
[c750cc]579 char FragmentName[MAXSTRINGSIZE];
580 char PathBackup[MAXSTRINGSIZE];
[14de469]581 bool result = true;
582 bool intermediateResult = true;
583 atom *Walker = NULL;
[e9b8bb]584 Vector BoxDimension;
[1e9384]585 char *FragmentNumber = NULL;
[5e4058]586 char *path = NULL;
[14de469]587 int FragmentCounter = 0;
[a8aac8d]588 ofstream output;
[1907a7]589
[14de469]590 // store the fragments as config and as xyz
[1907a7]591 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
[db942e]592 // save default path as it is changed for each fragment
[5e4058]593 path = configuration->GetDefaultPath();
594 if (path != NULL)
595 strcpy(PathBackup, path);
596 else
597 cerr << "OutputConfigForListOfFragments: NULL default path obtained from config!" << endl;
[db942e]598
599 // correct periodic
[1907a7]600 (*ListRunner)->ScanForPeriodicCorrection(out);
[db942e]601
602 // output xyz file
[1907a7]603 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), FragmentCounter++);
604 sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
[db942e]605 outputFragment.open(FragmentName, ios::out);
[1907a7]606 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ...";
607 if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment)))
[db942e]608 *out << " done." << endl;
609 else
610 *out << " failed." << endl;
611 result = result && intermediateResult;
612 outputFragment.close();
613 outputFragment.clear();
614
[c1fc22]615 // list atoms in fragment for debugging
[db942e]616 *out << Verbose(2) << "Contained atoms: ";
[1907a7]617 Walker = (*ListRunner)->start;
618 while (Walker->next != (*ListRunner)->end) {
[db942e]619 Walker = Walker->next;
620 *out << Walker->Name << " ";
[14de469]621 }
[db942e]622 *out << endl;
[1907a7]623
[db942e]624 // center on edge
[1907a7]625 (*ListRunner)->CenterEdge(out, &BoxDimension);
626 (*ListRunner)->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary
627 int j = -1;
628 for (int k = 0; k < NDIM; k++) {
629 j += k + 1;
630 BoxDimension.x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
631 (*ListRunner)->cell_size[j] += BoxDimension.x[k] * 2.;
[14de469]632 }
[1907a7]633 (*ListRunner)->Translate(&BoxDimension);
[db942e]634
635 // also calculate necessary orbitals
[1907a7]636 (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment
637 (*ListRunner)->CalculateOrbitals(*configuration);
638
[db942e]639 // change path in config
[c1fc22]640 //strcpy(PathBackup, configuration->configpath);
[1907a7]641 sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber);
[db942e]642 configuration->SetDefaultPath(FragmentName);
[1907a7]643
[c1fc22]644 // and save as config
[1907a7]645 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
646 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ...";
647 if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))
[db942e]648 *out << " done." << endl;
649 else
650 *out << " failed." << endl;
[9a5bcd]651 result = result && intermediateResult;
[c1fc22]652
[db942e]653 // restore old config
654 configuration->SetDefaultPath(PathBackup);
[c1fc22]655
656 // and save as mpqc input file
[1907a7]657 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
658 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ...";
659 if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))
[c1fc22]660 *out << " done." << endl;
661 else
662 *out << " failed." << endl;
[1907a7]663
[db942e]664 result = result && intermediateResult;
[9a5bcd]665 //outputFragment.close();
666 //outputFragment.clear();
[1907a7]667 delete (FragmentNumber);
[29812d]668 //Free(&FragmentNumber);
[14de469]669 }
[2459b1]670 cout << " done." << endl;
[1907a7]671
[14de469]672 // printing final number
[db942e]673 *out << "Final number of fragments: " << FragmentCounter << "." << endl;
[1907a7]674
[14de469]675 return result;
676};
677
[1907a7]678/** Counts the number of molecules with the molecule::ActiveFlag set.
679 * \return number of molecules with ActiveFlag set to true.
680 */
681int MoleculeListClass::NumberOfActiveMolecules()
682{
683 int count = 0;
684 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
685 count += ((*ListRunner)->ActiveFlag ? 1 : 0);
686 return count;
687};
688
689
[14de469]690/******************************************* Class MoleculeLeafClass ************************************************/
691
692/** Constructor for MoleculeLeafClass root leaf.
693 * \param *Up Leaf on upper level
694 * \param *PreviousLeaf NULL - We are the first leaf on this level, otherwise points to previous in list
695 */
696//MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *Up = NULL, MoleculeLeafClass *Previous = NULL)
697MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL)
698{
[437922]699 // if (Up != NULL)
700 // if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf?
701 // Up->DownLeaf = this;
702 // UpLeaf = Up;
703 // DownLeaf = NULL;
[14de469]704 Leaf = NULL;
705 previous = PreviousLeaf;
706 if (previous != NULL) {
707 MoleculeLeafClass *Walker = previous->next;
708 previous->next = this;
709 next = Walker;
710 } else {
711 next = NULL;
712 }
713};
714
715/** Destructor for MoleculeLeafClass.
716 */
717MoleculeLeafClass::~MoleculeLeafClass()
718{
[437922]719 // if (DownLeaf != NULL) {// drop leaves further down
720 // MoleculeLeafClass *Walker = DownLeaf;
721 // MoleculeLeafClass *Next;
722 // do {
723 // Next = Walker->NextLeaf;
724 // delete(Walker);
725 // Walker = Next;
726 // } while (Walker != NULL);
727 // // Last Walker sets DownLeaf automatically to NULL
728 // }
[14de469]729 // remove the leaf itself
730 if (Leaf != NULL) {
[1907a7]731 delete (Leaf);
[14de469]732 Leaf = NULL;
733 }
734 // remove this Leaf from level list
[1907a7]735 if (previous != NULL)
[14de469]736 previous->next = next;
[437922]737 // } else { // we are first in list (connects to UpLeaf->DownLeaf)
738 // if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL))
739 // NextLeaf->UpLeaf = UpLeaf; // either null as we are top level or the upleaf of the first node
740 // if (UpLeaf != NULL)
741 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first
742 // }
743 // UpLeaf = NULL;
[14de469]744 if (next != NULL) // are we last in list
745 next->previous = previous;
746 next = NULL;
747 previous = NULL;
748};
749
750/** Adds \a molecule leaf to the tree.
751 * \param *ptr ptr to molecule to be added
752 * \param *Previous previous MoleculeLeafClass referencing level and which on the level
753 * \return true - success, false - something went wrong
754 */
755bool MoleculeLeafClass::AddLeaf(molecule *ptr, MoleculeLeafClass *Previous)
756{
757 return false;
758};
[c82f3d]759
760/** Fills the bond structure of this chain list subgraphs that are derived from a complete \a *reference molecule.
761 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL.
762 * \param *out output stream for debugging
763 * \param *reference reference molecule with the bond structure to be copied
764 * \param &FragmentCounter Counter needed to address \a **ListOfLocalAtoms
765 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled
766 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
767 * \return true - success, false - faoilure
768 */
769bool MoleculeLeafClass::FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList)
770{
771 atom *Walker = NULL, *OtherWalker = NULL;
772 bond *Binder = NULL;
773 bool status = true;
774 int AtomNo;
775
[617b53]776 *out << Verbose(1) << "Begin of FillBondStructureFromReference." << endl;
[d2a294]777 // fill ListOfLocalAtoms if NULL was given
778 if (!FillListOfLocalAtoms(out, ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
779 *out << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
780 return false;
[c82f3d]781 }
[1907a7]782
[c82f3d]783 if (status) {
[1907a7]784 *out << Verbose(1) << "Creating adjacency list for subgraph " << this
785 << "." << endl;
[c82f3d]786 Walker = Leaf->start;
787 while (Walker->next != Leaf->end) {
788 Walker = Walker->next;
[1907a7]789 AtomNo = Walker->GetTrueFather()->nr; // global id of the current walker
790 for (int i = 0; i < reference->NumberOfBondsPerAtom[AtomNo]; i++) { // go through father's bonds and copy them all
[c82f3d]791 Binder = reference->ListOfBondsPerAtom[AtomNo][i];
[1907a7]792 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker
[c82f3d]793 if (OtherWalker != NULL) {
794 if (OtherWalker->nr > Walker->nr)
[1907a7]795 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);
[c82f3d]796 } else {
[3ccc3e]797 *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl;
[c82f3d]798 status = false;
799 }
800 }
801 }
802 Leaf->CreateListOfBondsPerAtom(out);
803 FragmentCounter++;
804 if (next != NULL)
805 status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
[617b53]806 FragmentCounter--;
[c82f3d]807 }
[1907a7]808
[617b53]809 if ((FreeList) && (ListOfLocalAtoms != NULL)) {
[c82f3d]810 // free the index lookup list
[29812d]811 Free(&ListOfLocalAtoms[FragmentCounter]);
[3ccc3e]812 if (FragmentCounter == 0) // first fragments frees the initial pointer to list
[29812d]813 Free(&ListOfLocalAtoms);
[c82f3d]814 }
[386aa2]815 FragmentCounter--;
[617b53]816 *out << Verbose(1) << "End of FillBondStructureFromReference." << endl;
[c82f3d]817 return status;
818};
819
[386aa2]820/** Fills the root stack for sites to be used as root in fragmentation depending on order or adaptivity criteria
821 * Again, as in \sa FillBondStructureFromReference steps recursively through each Leaf in this chain list of molecule's.
822 * \param *out output stream for debugging
823 * \param *&RootStack stack to be filled
[5de3c9]824 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site
[386aa2]825 * \param &FragmentCounter counts through the fragments in this MoleculeLeafClass
826 * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update
827 */
[1907a7]828bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out,
829 KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter)
[386aa2]830{
[5de3c9]831 atom *Walker = NULL, *Father = NULL;
[386aa2]832
833 if (RootStack != NULL) {
[1907a7]834 // find first root candidates
[de293ac]835 if (&(RootStack[FragmentCounter]) != NULL) {
[1907a7]836 RootStack[FragmentCounter].clear();
[de293ac]837 Walker = Leaf->start;
838 while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms
839 Walker = Walker->next;
840 Father = Walker->GetTrueFather();
841 if (AtomMask[Father->nr]) // apply mask
[1907a7]842#ifdef ADDHYDROGEN
[de293ac]843 if (Walker->type->Z != 1) // skip hydrogen
[1907a7]844#endif
845 RootStack[FragmentCounter].push_front(Walker->nr);
[d2a294]846 }
[de293ac]847 if (next != NULL)
848 next->FillRootStackForSubgraphs(out, RootStack, AtomMask, ++FragmentCounter);
[1907a7]849 } else {
850 *out << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl;
[de293ac]851 return false;
[386aa2]852 }
[d2a294]853 FragmentCounter--;
[386aa2]854 return true;
[d2a294]855 } else {
856 *out << Verbose(1) << "Rootstack is NULL." << endl;
[386aa2]857 return false;
[d2a294]858 }
859};
860
861/** Fills a lookup list of father's Atom::nr -> atom for each subgraph.
862 * \param *out output stream fro debugging
863 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
[3ccc3e]864 * \param FragmentCounter counts the fragments as we move along the list
[d2a294]865 * \param GlobalAtomCount number of atoms in the complete molecule
866 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
867 * \return true - succes, false - failure
868 */
[3ccc3e]869bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
[d2a294]870{
871 bool status = true;
[1907a7]872
[d2a294]873 int Counter = Count();
874 if (ListOfLocalAtoms == NULL) { // allocated initial pointer
875 // allocate and set each field to NULL
[29812d]876 ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
[d2a294]877 if (ListOfLocalAtoms != NULL) {
[1907a7]878 for (int i = Counter; i--;)
[d2a294]879 ListOfLocalAtoms[i] = NULL;
880 FreeList = FreeList && true;
881 } else
882 status = false;
883 }
[1907a7]884
[d2a294]885 if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph
886 status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount);
887 FreeList = FreeList && true;
888 }
[1907a7]889
[d2a294]890 return status;
891};
892
893/** The indices per keyset are compared to the respective father's Atom::nr in each subgraph and thus put into \a **&FragmentList.
894 * \param *out output stream fro debugging
895 * \param *reference reference molecule with the bond structure to be copied
896 * \param *KeySetList list with all keysets
897 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
898 * \param **&FragmentList list to be allocated and returned
899 * \param &FragmentCounter counts the fragments as we move along the list
900 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
901 * \retuen true - success, false - failure
902 */
[1907a7]903bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out,
904 molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms,
905 Graph **&FragmentList, int &FragmentCounter, bool FreeList)
[d2a294]906{
907 bool status = true;
908 int KeySetCounter = 0;
[1907a7]909
[617b53]910 *out << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl;
[d2a294]911 // fill ListOfLocalAtoms if NULL was given
912 if (!FillListOfLocalAtoms(out, ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
913 *out << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
914 return false;
915 }
916
917 // allocate fragment list
918 if (FragmentList == NULL) {
919 KeySetCounter = Count();
[29812d]920 FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
[1907a7]921 for (int i = KeySetCounter; i--;)
[d2a294]922 FragmentList[i] = NULL;
923 KeySetCounter = 0;
924 }
[1907a7]925
[d2a294]926 if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all
927 // assign scanned keysets
928 if (FragmentList[FragmentCounter] == NULL)
929 FragmentList[FragmentCounter] = new Graph;
930 KeySet *TempSet = new KeySet;
[1907a7]931 for (Graph::iterator runner = KeySetList->begin(); runner != KeySetList->end(); runner++) { // key sets contain global numbers!
932 if (ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
[d2a294]933 // translate keyset to local numbers
[1907a7]934 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
[d2a294]935 TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->nr]->nr);
936 // insert into FragmentList
[1907a7]937 FragmentList[FragmentCounter]->insert(GraphPair(*TempSet, pair<int, double> (KeySetCounter++, (*runner).second.second)));
[d2a294]938 }
939 TempSet->clear();
940 }
[1907a7]941 delete (TempSet);
[d2a294]942 if (KeySetCounter == 0) {// if there are no keysets, delete the list
943 *out << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl;
[1907a7]944 delete (FragmentList[FragmentCounter]);
[d2a294]945 } else
946 *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl;
947 FragmentCounter++;
948 if (next != NULL)
949 next->AssignKeySetsToFragment(out, reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
[617b53]950 FragmentCounter--;
[d2a294]951 } else
952 *out << Verbose(1) << "KeySetList is NULL or empty." << endl;
[1907a7]953
[617b53]954 if ((FreeList) && (ListOfLocalAtoms != NULL)) {
[3ccc3e]955 // free the index lookup list
[29812d]956 Free(&ListOfLocalAtoms[FragmentCounter]);
[3ccc3e]957 if (FragmentCounter == 0) // first fragments frees the initial pointer to list
[29812d]958 Free(&ListOfLocalAtoms);
[3ccc3e]959 }
[617b53]960 *out << Verbose(1) << "End of AssignKeySetsToFragment." << endl;
[d2a294]961 return status;
[386aa2]962};
[c82f3d]963
[87f6c9]964/** Translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
965 * \param *out output stream for debugging
966 * \param **FragmentList Graph with local numbers per fragment
967 * \param &FragmentCounter counts the fragments as we move along the list
968 * \param &TotalNumberOfKeySets global key set counter
969 * \param &TotalGraph Graph to be filled with global numbers
[1907a7]970 */
971void MoleculeLeafClass::TranslateIndicesToGlobalIDs(ofstream *out,
972 Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets,
973 Graph &TotalGraph)
[87f6c9]974{
[362b0e]975 *out << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl;
[87f6c9]976 KeySet *TempSet = new KeySet;
[de293ac]977 if (FragmentList[FragmentCounter] != NULL) {
[1907a7]978 for (Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
979 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
[de293ac]980 TempSet->insert((Leaf->FindAtom(*sprinter))->GetTrueFather()->nr);
[1907a7]981 TotalGraph.insert(GraphPair(*TempSet, pair<int, double> (TotalNumberOfKeySets++, (*runner).second.second)));
[de293ac]982 TempSet->clear();
983 }
[1907a7]984 delete (TempSet);
[de293ac]985 } else {
986 *out << Verbose(1) << "FragmentList is NULL." << endl;
[87f6c9]987 }
988 if (next != NULL)
989 next->TranslateIndicesToGlobalIDs(out, FragmentList, ++FragmentCounter, TotalNumberOfKeySets, TotalGraph);
990 FragmentCounter--;
[362b0e]991 *out << Verbose(1) << "End of TranslateIndicesToGlobalIDs." << endl;
[87f6c9]992};
993
[386aa2]994/** Simply counts the number of items in the list, from given MoleculeLeafClass.
995 * \return number of items
996 */
[d2a294]997int MoleculeLeafClass::Count() const
[386aa2]998{
999 if (next != NULL)
[1907a7]1000 return next->Count() + 1;
[386aa2]1001 else
[1907a7]1002 return 1;
[386aa2]1003};
[1907a7]1004
Note: See TracBrowser for help on using the repository browser.