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