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