source: src/moleculelist.cpp@ d067d45

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

Merge branch 'MultipleMolecules'

Conflicts:

molecuilder/src/analyzer.cpp
molecuilder/src/atom.cpp
molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/datacreator.hpp
molecuilder/src/helpers.cpp
molecuilder/src/joiner.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp
molecuilder/src/parser.cpp
molecuilder/src/parser.hpp
molecuilder/src/vector.cpp
molecuilder/src/verbose.cpp

merges:

compilation fixes:

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