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