source: src/moleculelist.cpp@ 31fb1d

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 31fb1d was 81a9bc, checked in by Frederik Heber <heber@…>, 15 years ago

BUGFIX: fixed initializer list sequence of MoleculeListClass.

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