source: src/moleculelist.cpp@ 8aba3c

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

New function BondedParticle::ClearBondsAtStep(), used by MoleculeLeafClass::FillBondStructureFromReference().

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