Changes in src/moleculelist.cpp [2746be:437922]
- File:
-
- 1 edited
-
src/moleculelist.cpp (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/moleculelist.cpp
r2746be r437922 1 1 /** \file MoleculeListClass.cpp 2 * 2 * 3 3 * Function implementations for the class MoleculeListClass. 4 * 4 * 5 5 */ 6 6 … … 13 13 MoleculeListClass::MoleculeListClass() 14 14 { 15 }; 16 17 /** constructor for MoleculeListClass. 18 * \param NumMolecules number of molecules to allocate for 19 * \param NumAtoms number of atoms to allocate for 20 */ 21 MoleculeListClass::MoleculeListClass(int NumMolecules, int NumAtoms) 22 { 23 ListOfMolecules = (molecule **) Malloc(sizeof(molecule *)*NumMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules"); 24 for (int i=NumMolecules;i--;) 25 ListOfMolecules[i] = NULL; 26 NumberOfMolecules = NumMolecules; 27 NumberOfTopAtoms = NumAtoms; 28 }; 29 15 // empty lists 16 ListOfMolecules.clear(); 17 MaxIndex = 1; 18 }; 30 19 31 20 /** Destructor for MoleculeListClass. … … 34 23 { 35 24 cout << Verbose(3) << this << ": Freeing ListOfMolcules." << endl; 36 for (int i=NumberOfMolecules;i--;) { 37 if (ListOfMolecules[i] != NULL) { // if NULL don't free 38 cout << Verbose(4) << "ListOfMolecules: Freeing " << ListOfMolecules[i] << "." << endl; 39 delete(ListOfMolecules[i]); 40 ListOfMolecules[i] = NULL; 41 } 25 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 26 cout << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl; 27 delete (*ListRunner); 42 28 } 43 29 cout << Verbose(4) << "Freeing ListOfMolecules." << endl; 44 Free((void **)&ListOfMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules"); 30 ListOfMolecules.clear(); // empty list 31 }; 32 33 /** Insert a new molecule into the list and set its number. 34 * \param *mol molecule to add to list. 35 * \return true - add successful 36 */ 37 void MoleculeListClass::insert(molecule *mol) 38 { 39 mol->IndexNr = MaxIndex++; 40 ListOfMolecules.push_back(mol); 45 41 }; 46 42 … … 57 53 atom *aWalker = NULL; 58 54 atom *bWalker = NULL; 59 55 60 56 // sort each atom list and put the numbers into a list, then go through 61 57 //cout << "Comparing fragment no. " << *(molecule **)a << " to " << *(molecule **)b << "." << endl; 62 if ( (**(molecule **)a).AtomCount < (**(molecule **)b).AtomCount) {58 if ((**(molecule **) a).AtomCount < (**(molecule **) b).AtomCount) { 63 59 return -1; 64 } else { if ((**(molecule **)a).AtomCount > (**(molecule **)b).AtomCount) 65 return +1; 60 } else { 61 if ((**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount) 62 return +1; 66 63 else { 67 Count = (**(molecule **) a).AtomCount;64 Count = (**(molecule **) a).AtomCount; 68 65 aList = new int[Count]; 69 66 bList = new int[Count]; 70 67 71 68 // fill the lists 72 aWalker = (**(molecule **) a).start;73 bWalker = (**(molecule **) b).start;69 aWalker = (**(molecule **) a).start; 70 bWalker = (**(molecule **) b).start; 74 71 Counter = 0; 75 72 aCounter = 0; 76 73 bCounter = 0; 77 while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **)b).end)) {74 while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) { 78 75 aWalker = aWalker->next; 79 76 bWalker = bWalker->next; … … 90 87 // check if AtomCount was for real 91 88 flag = 0; 92 if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **)b).end)) {89 if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) { 93 90 flag = -1; 94 91 } else { 95 if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **)b).end))92 if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **) b).end)) 96 93 flag = 1; 97 94 } 98 95 if (flag == 0) { 99 96 // sort the lists 100 gsl_heapsort(aList, Count, sizeof(int), CompareDoubles);101 gsl_heapsort(bList, Count, sizeof(int), CompareDoubles);102 // compare the lists 103 97 gsl_heapsort(aList, Count, sizeof(int), CompareDoubles); 98 gsl_heapsort(bList, Count, sizeof(int), CompareDoubles); 99 // compare the lists 100 104 101 flag = 0; 105 for (int i=0;i<Count;i++) {102 for (int i = 0; i < Count; i++) { 106 103 if (aList[i] < bList[i]) { 107 104 flag = -1; … … 114 111 } 115 112 } 116 delete[] (aList);117 delete[] (bList);113 delete[] (aList); 114 delete[] (bList); 118 115 return flag; 119 116 } 120 117 } 121 return -1; 118 return -1; 119 }; 120 121 /** Output of a list of all molecules. 122 * \param *out output stream 123 */ 124 void MoleculeListClass::Enumerate(ofstream *out) 125 { 126 int i=1; 127 element* Elemental = NULL; 128 atom *Walker = NULL; 129 int Counts[MAX_ELEMENTS]; 130 double size=0; 131 Vector Origin; 132 133 // header 134 *out << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl; 135 cout << Verbose(0) << "-----------------------------------------------" << endl; 136 if (ListOfMolecules.size() == 0) 137 *out << "\tNone" << endl; 138 else { 139 Origin.Zero(); 140 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 141 // reset element counts 142 for (int j = 0; j<MAX_ELEMENTS;j++) 143 Counts[j] = 0; 144 // count atoms per element and determine size of bounding sphere 145 size=0.; 146 Walker = (*ListRunner)->start; 147 while (Walker->next != (*ListRunner)->end) { 148 Walker = Walker->next; 149 Counts[Walker->type->Z]++; 150 if (Walker->x.DistanceSquared(&Origin) > size) 151 size = Walker->x.DistanceSquared(&Origin); 152 } 153 // output Index, Name, number of atoms, chemical formula 154 *out << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t"; 155 Elemental = (*ListRunner)->elemente->end; 156 while(Elemental->previous != (*ListRunner)->elemente->start) { 157 Elemental = Elemental->previous; 158 if (Counts[Elemental->Z] != 0) 159 *out << Elemental->symbol << Counts[Elemental->Z]; 160 } 161 // Center and size 162 *out << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl; 163 } 164 } 165 }; 166 167 /** Returns the molecule with the given index \a index. 168 * \param index index of the desired molecule 169 * \return pointer to molecule structure, NULL if not found 170 */ 171 molecule * MoleculeListClass::ReturnIndex(int index) 172 { 173 for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) 174 if ((*ListRunner)->IndexNr == index) 175 return (*ListRunner); 176 return NULL; 177 }; 178 179 /** Simple merge of two molecules into one. 180 * \param *mol destination molecule 181 * \param *srcmol source molecule 182 * \return true - merge successful, false - merge failed (probably due to non-existant indices 183 */ 184 bool MoleculeListClass::SimpleMerge(molecule *mol, molecule *srcmol) 185 { 186 if (srcmol == NULL) 187 return false; 188 189 // put all molecules of src into mol 190 atom *Walker = srcmol->start; 191 atom *NextAtom = Walker->next; 192 while (NextAtom != srcmol->end) { 193 Walker = NextAtom; 194 NextAtom = Walker->next; 195 srcmol->UnlinkAtom(Walker); 196 mol->AddAtom(Walker); 197 } 198 199 // remove src 200 ListOfMolecules.remove(srcmol); 201 delete(srcmol); 202 return true; 203 }; 204 205 /** Simple add of one molecules into another. 206 * \param *mol destination molecule 207 * \param *srcmol source molecule 208 * \return true - merge successful, false - merge failed (probably due to non-existant indices 209 */ 210 bool MoleculeListClass::SimpleAdd(molecule *mol, molecule *srcmol) 211 { 212 if (srcmol == NULL) 213 return false; 214 215 // put all molecules of src into mol 216 atom *Walker = srcmol->start; 217 atom *NextAtom = Walker->next; 218 while (NextAtom != srcmol->end) { 219 Walker = NextAtom; 220 NextAtom = Walker->next; 221 Walker = mol->AddCopyAtom(Walker); 222 Walker->father = Walker; 223 } 224 225 return true; 226 }; 227 228 /** Simple merge of a given set of molecules into one. 229 * \param *mol destination molecule 230 * \param *src index of set of source molecule 231 * \param N number of source molecules 232 * \return true - merge successful, false - some merges failed (probably due to non-existant indices) 233 */ 234 bool MoleculeListClass::SimpleMultiMerge(molecule *mol, int *src, int N) 235 { 236 bool status = true; 237 // check presence of all source molecules 238 for (int i=0;i<N;i++) { 239 molecule *srcmol = ReturnIndex(src[i]); 240 status = status && SimpleMerge(mol, srcmol); 241 } 242 return status; 243 }; 244 245 /** Simple add of a given set of molecules into one. 246 * \param *mol destination molecule 247 * \param *src index of set of source molecule 248 * \param N number of source molecules 249 * \return true - merge successful, false - some merges failed (probably due to non-existant indices) 250 */ 251 bool MoleculeListClass::SimpleMultiAdd(molecule *mol, int *src, int N) 252 { 253 bool status = true; 254 // check presence of all source molecules 255 for (int i=0;i<N;i++) { 256 molecule *srcmol = ReturnIndex(src[i]); 257 status = status && SimpleAdd(mol, srcmol); 258 } 259 return status; 260 }; 261 262 /** Scatter merge of a given set of molecules into one. 263 * Scatter merge distributes the molecules in such a manner that they don't overlap. 264 * \param *mol destination molecule 265 * \param *src index of set of source molecule 266 * \param N number of source molecules 267 * \return true - merge successful, false - merge failed (probably due to non-existant indices 268 * \TODO find scatter center for each src molecule 269 */ 270 bool MoleculeListClass::ScatterMerge(molecule *mol, int *src, int N) 271 { 272 // check presence of all source molecules 273 for (int i=0;i<N;i++) { 274 // get pointer to src molecule 275 molecule *srcmol = ReturnIndex(src[i]); 276 if (srcmol == NULL) 277 return false; 278 } 279 // adapt each Center 280 for (int i=0;i<N;i++) { 281 // get pointer to src molecule 282 molecule *srcmol = ReturnIndex(src[i]); 283 //srcmol->Center.Zero(); 284 srcmol->Translate(&srcmol->Center); 285 } 286 // perform a simple multi merge 287 SimpleMultiMerge(mol, src, N); 288 return true; 289 }; 290 291 /** Embedding merge of a given set of molecules into one. 292 * Embedding merge inserts one molecule into the other. 293 * \param *mol destination molecule 294 * \param *srcmol source molecule 295 * \return true - merge successful, false - merge failed (probably due to non-existant indices 296 * \TODO find embedding center 297 */ 298 bool MoleculeListClass::EmbedMerge(molecule *mol, molecule *srcmol) 299 { 300 if (srcmol == NULL) 301 return false; 302 303 // calculate center for merge 304 srcmol->Center.CopyVector(mol->FindEmbeddingHole((ofstream *)&cout, srcmol)); 305 srcmol->Center.Zero(); 306 307 // perform simple merge 308 SimpleMerge(mol, srcmol); 309 return true; 122 310 }; 123 311 … … 127 315 void MoleculeListClass::Output(ofstream *out) 128 316 { 129 *out << Verbose(1) << "MoleculeList: ";130 for ( int i=0;i<NumberOfMolecules;i++)131 *out << ListOfMolecules[i]<< "\t";317 *out << Verbose(1) << "MoleculeList: "; 318 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) 319 *out << *ListRunner << "\t"; 132 320 *out << endl; 133 321 }; … … 145 333 atom *Runner = NULL; 146 334 double ***FitConstant = NULL, **correction = NULL; 147 int a, b;335 int a, b; 148 336 ofstream output; 149 337 ifstream input; … … 165 353 input.open(line.c_str()); 166 354 if (input == NULL) { 167 cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl; 355 cerr << endl << "Unable to open " << line << ", is the directory correct?" 356 << endl; 168 357 return false; 169 358 } 170 a =0;171 b =-1; // we overcount by one359 a = 0; 360 b = -1; // we overcount by one 172 361 while (!input.eof()) { 173 362 input.getline(ParsedLine, 1023); 174 363 zeile.str(ParsedLine); 175 int i =0;364 int i = 0; 176 365 while (!zeile.eof()) { 177 366 zeile >> distance; 178 367 i++; 179 368 } 180 if (i > a) 181 a = i; 369 if (i > a) 370 a = i; 182 371 b++; 183 372 } 184 373 cout << "I recognized " << a << " columns and " << b << " rows, "; 185 374 input.close(); 186 375 187 376 // 0b. allocate memory for constants 188 FitConstant = (double ***) Malloc(sizeof(double **) *3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");189 for (int k =0;k<3;k++) {190 FitConstant[k] = (double **) Malloc(sizeof(double *) *a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");191 for (int i =a;i--;) {192 FitConstant[k][i] = (double *) Malloc(sizeof(double) *b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");377 FitConstant = (double ***) Malloc(sizeof(double **) * 3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 378 for (int k = 0; k < 3; k++) { 379 FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 380 for (int i = a; i--;) { 381 FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 193 382 } 194 383 } 195 384 // 0c. parse in constants 196 for (int i =0;i<3;i++) {385 for (int i = 0; i < 3; i++) { 197 386 line = path; 198 387 line.append("/"); 199 388 line += FRAGMENTPREFIX; 200 sprintf(ParsedLine, "%d", i +1);389 sprintf(ParsedLine, "%d", i + 1); 201 390 line += ParsedLine; 202 391 line += FITCONSTANTSUFFIX; … … 206 395 return false; 207 396 } 208 int k = 0, l;397 int k = 0, l; 209 398 while ((!input.eof()) && (k < b)) { 210 399 input.getline(ParsedLine, 1023); … … 223 412 input.close(); 224 413 } 225 for (int k=0;k<3;k++) {414 for (int k = 0; k < 3; k++) { 226 415 cout << "Constants " << k << ":" << endl; 227 for (int j =0;j<b;j++) {228 for (int i =0;i<a;i++) {416 for (int j = 0; j < b; j++) { 417 for (int i = 0; i < a; i++) { 229 418 cout << FitConstant[k][i][j] << "\t"; 230 419 } … … 233 422 cout << endl; 234 423 } 235 424 236 425 // 0d. allocate final correction matrix 237 correction = (double **) Malloc(sizeof(double *) *a, "MoleculeListClass::AddHydrogenCorrection: **correction");238 for (int i =a;i--;)239 correction[i] = (double *) Malloc(sizeof(double) *b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");240 426 correction = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **correction"); 427 for (int i = a; i--;) 428 correction[i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *correction[]"); 429 241 430 // 1a. go through every molecule in the list 242 for (int i=NumberOfMolecules;i--;) {431 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 243 432 // 1b. zero final correction matrix 244 for (int k =a;k--;)245 for (int j =b;j--;)433 for (int k = a; k--;) 434 for (int j = b; j--;) 246 435 correction[k][j] = 0.; 247 436 // 2. take every hydrogen that is a saturated one 248 Walker = ListOfMolecules[i]->start;249 while (Walker->next != ListOfMolecules[i]->end) {437 Walker = (*ListRunner)->start; 438 while (Walker->next != (*ListRunner)->end) { 250 439 Walker = Walker->next; 251 //cout << Verbose(1) << "Walker: " << *Walker << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0] << "." << endl; 252 if ((Walker->type->Z == 1) && ((Walker->father == NULL) || (Walker->father->type->Z != 1))) { // if it's a hydrogen 253 Runner = ListOfMolecules[i]->start; 254 while (Runner->next != ListOfMolecules[i]->end) { 440 //cout << Verbose(1) << "Walker: " << *Walker << " with first bond " << *(*Runner)->ListOfBondsPerAtom[Walker->nr][0] << "." << endl; 441 if ((Walker->type->Z == 1) && ((Walker->father == NULL) 442 || (Walker->father->type->Z != 1))) { // if it's a hydrogen 443 Runner = (*ListRunner)->start; 444 while (Runner->next != (*ListRunner)->end) { 255 445 Runner = Runner->next; 256 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << * ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0] << "." << endl;446 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << *(*Runner)->ListOfBondsPerAtom[Runner->nr][0] << "." << endl; 257 447 // 3. take every other hydrogen that is the not the first and not bound to same bonding partner 258 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && ( ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0]->GetOtherAtom(Runner) != ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker))) {// (hydrogens have only one bonding partner!)448 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && ((*ListRunner)->ListOfBondsPerAtom[Runner->nr][0]->GetOtherAtom(Runner) != (*ListRunner)->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!) 259 449 // 4. evaluate the morse potential for each matrix component and add up 260 distance = sqrt(Runner->x.Distance(&Walker->x));261 //cout << "Fragment " << i<< ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl;262 for (int k=0;k<a;k++) {263 for (int j =0;j<b;j++) {264 switch (k) {265 case 1:266 case 7:267 case 11:268 tmp = pow(FitConstant[0][k][j] * ( 1. - exp(-FitConstant[1][k][j] * (distance - FitConstant[2][k][j]) ) ),2);269 break;270 default:271 tmp = FitConstant[0][k][j] * pow( distance,FitConstant[1][k][j]) + FitConstant[2][k][j];450 distance = Runner->x.Distance(&Walker->x); 451 //cout << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl; 452 for (int k = 0; k < a; k++) { 453 for (int j = 0; j < b; j++) { 454 switch (k) { 455 case 1: 456 case 7: 457 case 11: 458 tmp = pow(FitConstant[0][k][j] * (1. - exp(-FitConstant[1][k][j] * (distance - FitConstant[2][k][j]))), 2); 459 break; 460 default: 461 tmp = FitConstant[0][k][j] * pow(distance, FitConstant[1][k][j]) + FitConstant[2][k][j]; 272 462 }; 273 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction)463 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction) 274 464 //cout << tmp << "\t"; 275 465 } … … 285 475 line.append("/"); 286 476 line += FRAGMENTPREFIX; 287 FragmentNumber = FixedDigitNumber( NumberOfMolecules, i);477 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), (*ListRunner)->IndexNr); 288 478 line += FragmentNumber; 289 delete (FragmentNumber);479 delete (FragmentNumber); 290 480 line += HCORRECTIONSUFFIX; 291 481 output.open(line.c_str()); 292 482 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 293 for (int j =0;j<b;j++) {294 for (int i=0;i<a;i++)483 for (int j = 0; j < b; j++) { 484 for (int i = 0; i < a; i++) 295 485 output << correction[i][j] << "\t"; 296 486 output << endl; … … 303 493 output.open(line.c_str()); 304 494 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 305 for (int j =0;j<b;j++) {306 for (int i=0;i<a;i++)495 for (int j = 0; j < b; j++) { 496 for (int i = 0; i < a; i++) 307 497 output << 0 << "\t"; 308 498 output << endl; … … 310 500 output.close(); 311 501 // 6. free memory of parsed matrices 312 FitConstant = (double ***) Malloc(sizeof(double **) *a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");313 for (int k =0;k<3;k++) {314 FitConstant[k] = (double **) Malloc(sizeof(double *) *a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");315 for (int i =a;i--;) {316 FitConstant[k][i] = (double *) Malloc(sizeof(double) *b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");502 FitConstant = (double ***) Malloc(sizeof(double **) * a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 503 for (int k = 0; k < 3; k++) { 504 FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 505 for (int i = a; i--;) { 506 FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 317 507 } 318 508 } … … 327 517 * \return true - file written successfully, false - writing failed 328 518 */ 329 bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path, int *SortIndex) 519 bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path, 520 int *SortIndex) 330 521 { 331 522 bool status = true; … … 342 533 //cout << Verbose(1) << "Final AtomicForcesList: "; 343 534 //output << prefix << "Forces" << endl; 344 for(int j=0;j<NumberOfMolecules;j++) { 345 //if (TEList[j] != 0) { 346 runner = ListOfMolecules[j]->elemente->start; 347 while (runner->next != ListOfMolecules[j]->elemente->end) { // go through every element 535 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 536 runner = (*ListRunner)->elemente->start; 537 while (runner->next != (*ListRunner)->elemente->end) { // go through every element 348 538 runner = runner->next; 349 if ( ListOfMolecules[j]->ElementsInMolecule[runner->Z]) { // if this element got atoms350 Walker = ListOfMolecules[j]->start;351 while (Walker->next != ListOfMolecules[j]->end) { // go through every atom of this element539 if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms 540 Walker = (*ListRunner)->start; 541 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element 352 542 Walker = Walker->next; 353 543 if (Walker->type->Z == runner->Z) { 354 544 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 355 545 //cout << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it 356 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t";357 } else // otherwise a -1 to indicate an added saturation hydrogen358 ForcesFile << "-1\t";359 }546 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t"; 547 } else 548 // otherwise a -1 to indicate an added saturation hydrogen 549 ForcesFile << "-1\t"; 360 550 } 361 551 } 552 } 362 553 } 363 554 ForcesFile << endl; … … 370 561 } 371 562 ForcesFile.close(); 372 563 373 564 return status; 374 565 }; … … 380 571 * \return true - success (each file was written), false - something went wrong. 381 572 */ 382 bool MoleculeListClass::OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex) 573 bool MoleculeListClass::OutputConfigForListOfFragments(ofstream *out, 574 config *configuration, int *SortIndex) 383 575 { 384 576 ofstream outputFragment; … … 393 585 int FragmentCounter = 0; 394 586 ofstream output; 395 string basis("3-21G"); 396 587 397 588 // store the fragments as config and as xyz 398 for (int i=0;i<NumberOfMolecules;i++) {589 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 399 590 // save default path as it is changed for each fragment 400 591 path = configuration->GetDefaultPath(); … … 405 596 406 597 // correct periodic 407 //ListOfMolecules[i]->ScanForPeriodicCorrection(out);598 (*ListRunner)->ScanForPeriodicCorrection(out); 408 599 409 600 // output xyz file 410 FragmentNumber = FixedDigitNumber( NumberOfMolecules, FragmentCounter++);601 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), FragmentCounter++); 411 602 sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 412 603 outputFragment.open(FragmentName, ios::out); 413 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as XYZ ...";414 if ((intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment)))604 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ..."; 605 if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment))) 415 606 *out << " done." << endl; 416 607 else … … 422 613 // list atoms in fragment for debugging 423 614 *out << Verbose(2) << "Contained atoms: "; 424 Walker = ListOfMolecules[i]->start;425 while (Walker->next != ListOfMolecules[i]->end) {615 Walker = (*ListRunner)->start; 616 while (Walker->next != (*ListRunner)->end) { 426 617 Walker = Walker->next; 427 618 *out << Walker->Name << " "; 428 619 } 429 620 *out << endl; 430 621 431 622 // center on edge 432 ListOfMolecules[i]->CenterEdge(out, &BoxDimension);433 ListOfMolecules[i]->SetBoxDimension(&BoxDimension);// update Box of atoms by boundary623 (*ListRunner)->CenterEdge(out, &BoxDimension); 624 (*ListRunner)->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary 434 625 int j = -1; 435 for (int k =0;k<NDIM;k++) {436 j += k +1;437 BoxDimension.x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1./AtomicLengthToAngstroem);438 ListOfMolecules[i]->cell_size[j] += BoxDimension.x[k]*2.;439 } 440 ListOfMolecules[i]->Translate(&BoxDimension);626 for (int k = 0; k < NDIM; k++) { 627 j += k + 1; 628 BoxDimension.x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem); 629 (*ListRunner)->cell_size[j] += BoxDimension.x[k] * 2.; 630 } 631 (*ListRunner)->Translate(&BoxDimension); 441 632 442 633 // also calculate necessary orbitals 443 ListOfMolecules[i]->CountElements(); // this is a bugfix, atoms should should actually be added correctly to this fragment444 ListOfMolecules[i]->CalculateOrbitals(*configuration);445 634 (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment 635 (*ListRunner)->CalculateOrbitals(*configuration); 636 446 637 // change path in config 447 638 //strcpy(PathBackup, configuration->configpath); 448 639 sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber); 449 640 configuration->SetDefaultPath(FragmentName); 450 641 451 642 // and save as config 452 643 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 453 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as config ...";454 if ((intermediateResult = configuration->Save(FragmentName, ListOfMolecules[i]->elemente, ListOfMolecules[i])))644 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ..."; 645 if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner)))) 455 646 *out << " done." << endl; 456 647 else … … 461 652 configuration->SetDefaultPath(PathBackup); 462 653 463 464 654 // and save as mpqc input file 465 655 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 466 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as mpqc input ...";467 if ((intermediateResult = configuration->SaveMPQC(FragmentName, ListOfMolecules[i])))656 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ..."; 657 if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner)))) 468 658 *out << " done." << endl; 469 659 else 470 660 *out << " failed." << endl; 471 661 472 662 result = result && intermediateResult; 473 663 //outputFragment.close(); 474 664 //outputFragment.clear(); 475 delete (FragmentNumber);665 delete (FragmentNumber); 476 666 //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber"); 477 667 } 478 668 cout << " done." << endl; 479 669 480 670 // printing final number 481 671 *out << "Final number of fragments: " << FragmentCounter << "." << endl; 482 672 483 673 return result; 484 674 }; 675 676 /** Counts the number of molecules with the molecule::ActiveFlag set. 677 * \return number of molecules with ActiveFlag set to true. 678 */ 679 int MoleculeListClass::NumberOfActiveMolecules() 680 { 681 int count = 0; 682 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) 683 count += ((*ListRunner)->ActiveFlag ? 1 : 0); 684 return count; 685 }; 686 485 687 486 688 /******************************************* Class MoleculeLeafClass ************************************************/ … … 493 695 MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL) 494 696 { 495 // if (Up != NULL)496 // if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf?497 // Up->DownLeaf = this;498 // UpLeaf = Up;499 // DownLeaf = NULL;697 // if (Up != NULL) 698 // if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf? 699 // Up->DownLeaf = this; 700 // UpLeaf = Up; 701 // DownLeaf = NULL; 500 702 Leaf = NULL; 501 703 previous = PreviousLeaf; … … 513 715 MoleculeLeafClass::~MoleculeLeafClass() 514 716 { 515 // if (DownLeaf != NULL) {// drop leaves further down516 // MoleculeLeafClass *Walker = DownLeaf;517 // MoleculeLeafClass *Next;518 // do {519 // Next = Walker->NextLeaf;520 // delete(Walker);521 // Walker = Next;522 // } while (Walker != NULL);523 // // Last Walker sets DownLeaf automatically to NULL524 // }717 // if (DownLeaf != NULL) {// drop leaves further down 718 // MoleculeLeafClass *Walker = DownLeaf; 719 // MoleculeLeafClass *Next; 720 // do { 721 // Next = Walker->NextLeaf; 722 // delete(Walker); 723 // Walker = Next; 724 // } while (Walker != NULL); 725 // // Last Walker sets DownLeaf automatically to NULL 726 // } 525 727 // remove the leaf itself 526 728 if (Leaf != NULL) { 527 delete (Leaf);729 delete (Leaf); 528 730 Leaf = NULL; 529 731 } 530 732 // remove this Leaf from level list 531 if (previous != NULL) 733 if (previous != NULL) 532 734 previous->next = next; 533 // } else { // we are first in list (connects to UpLeaf->DownLeaf)534 // if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL))535 // NextLeaf->UpLeaf = UpLeaf; // either null as we are top level or the upleaf of the first node536 // if (UpLeaf != NULL)537 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first538 // }539 // UpLeaf = NULL;735 // } else { // we are first in list (connects to UpLeaf->DownLeaf) 736 // if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL)) 737 // NextLeaf->UpLeaf = UpLeaf; // either null as we are top level or the upleaf of the first node 738 // if (UpLeaf != NULL) 739 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first 740 // } 741 // UpLeaf = NULL; 540 742 if (next != NULL) // are we last in list 541 743 next->previous = previous; … … 576 778 return false; 577 779 } 578 780 579 781 if (status) { 580 *out << Verbose(1) << "Creating adjacency list for subgraph " << this << "." << endl; 782 *out << Verbose(1) << "Creating adjacency list for subgraph " << this 783 << "." << endl; 581 784 Walker = Leaf->start; 582 785 while (Walker->next != Leaf->end) { 583 786 Walker = Walker->next; 584 AtomNo = Walker->GetTrueFather()->nr; // global id of the current walker585 for (int i=0;i<reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all787 AtomNo = Walker->GetTrueFather()->nr; // global id of the current walker 788 for (int i = 0; i < reference->NumberOfBondsPerAtom[AtomNo]; i++) { // go through father's bonds and copy them all 586 789 Binder = reference->ListOfBondsPerAtom[AtomNo][i]; 587 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker790 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker 588 791 if (OtherWalker != NULL) { 589 792 if (OtherWalker->nr > Walker->nr) 590 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);793 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree); 591 794 } else { 592 795 *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl; … … 601 804 FragmentCounter--; 602 805 } 603 806 604 807 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 605 808 // free the index lookup list 606 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");809 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]"); 607 810 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 608 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");811 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 609 812 } 610 813 FragmentCounter--; … … 621 824 * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update 622 825 */ 623 bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 826 bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, 827 KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 624 828 { 625 829 atom *Walker = NULL, *Father = NULL; 626 830 627 831 if (RootStack != NULL) { 628 // find first root candidates 832 // find first root candidates 629 833 if (&(RootStack[FragmentCounter]) != NULL) { 630 RootStack[FragmentCounter].clear(); 834 RootStack[FragmentCounter].clear(); 631 835 Walker = Leaf->start; 632 836 while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms … … 634 838 Father = Walker->GetTrueFather(); 635 839 if (AtomMask[Father->nr]) // apply mask 636 #ifdef ADDHYDROGEN840 #ifdef ADDHYDROGEN 637 841 if (Walker->type->Z != 1) // skip hydrogen 638 #endif639 RootStack[FragmentCounter].push_front(Walker->nr);842 #endif 843 RootStack[FragmentCounter].push_front(Walker->nr); 640 844 } 641 845 if (next != NULL) 642 846 next->FillRootStackForSubgraphs(out, RootStack, AtomMask, ++FragmentCounter); 643 } else {644 *out << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl;847 } else { 848 *out << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl; 645 849 return false; 646 850 } … … 664 868 { 665 869 bool status = true; 666 870 667 871 int Counter = Count(); 668 872 if (ListOfLocalAtoms == NULL) { // allocated initial pointer 669 873 // allocate and set each field to NULL 670 ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **) *Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");874 ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **) * Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 671 875 if (ListOfLocalAtoms != NULL) { 672 for (int i =Counter;i--;)876 for (int i = Counter; i--;) 673 877 ListOfLocalAtoms[i] = NULL; 674 878 FreeList = FreeList && true; … … 676 880 status = false; 677 881 } 678 882 679 883 if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph 680 884 status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount); 681 885 FreeList = FreeList && true; 682 886 } 683 887 684 888 return status; 685 889 }; … … 695 899 * \retuen true - success, false - failure 696 900 */ 697 bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList) 901 bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out, 902 molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, 903 Graph **&FragmentList, int &FragmentCounter, bool FreeList) 698 904 { 699 905 bool status = true; 700 906 int KeySetCounter = 0; 701 907 702 908 *out << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl; 703 909 // fill ListOfLocalAtoms if NULL was given … … 710 916 if (FragmentList == NULL) { 711 917 KeySetCounter = Count(); 712 FragmentList = (Graph **) Malloc(sizeof(Graph *) *KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");713 for (int i=KeySetCounter;i--;)918 FragmentList = (Graph **) Malloc(sizeof(Graph *) * KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList"); 919 for (int i = KeySetCounter; i--;) 714 920 FragmentList[i] = NULL; 715 921 KeySetCounter = 0; 716 922 } 717 923 718 924 if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all 719 925 // assign scanned keysets … … 721 927 FragmentList[FragmentCounter] = new Graph; 722 928 KeySet *TempSet = new KeySet; 723 for (Graph::iterator runner = KeySetList->begin();runner != KeySetList->end(); runner++) { // key sets contain global numbers!724 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 set929 for (Graph::iterator runner = KeySetList->begin(); runner != KeySetList->end(); runner++) { // key sets contain global numbers! 930 if (ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set 725 931 // translate keyset to local numbers 726 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)932 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++) 727 933 TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->nr]->nr); 728 934 // insert into FragmentList 729 FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int,double>(KeySetCounter++, (*runner).second.second)));935 FragmentList[FragmentCounter]->insert(GraphPair(*TempSet, pair<int, double> (KeySetCounter++, (*runner).second.second))); 730 936 } 731 937 TempSet->clear(); 732 938 } 733 delete (TempSet);939 delete (TempSet); 734 940 if (KeySetCounter == 0) {// if there are no keysets, delete the list 735 941 *out << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl; 736 delete (FragmentList[FragmentCounter]);942 delete (FragmentList[FragmentCounter]); 737 943 } else 738 944 *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl; … … 743 949 } else 744 950 *out << Verbose(1) << "KeySetList is NULL or empty." << endl; 745 951 746 952 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 747 953 // free the index lookup list 748 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");954 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]"); 749 955 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 750 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");956 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms"); 751 957 } 752 958 *out << Verbose(1) << "End of AssignKeySetsToFragment." << endl; … … 760 966 * \param &TotalNumberOfKeySets global key set counter 761 967 * \param &TotalGraph Graph to be filled with global numbers 762 */ 763 void MoleculeLeafClass::TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph) 968 */ 969 void MoleculeLeafClass::TranslateIndicesToGlobalIDs(ofstream *out, 970 Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, 971 Graph &TotalGraph) 764 972 { 765 973 *out << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl; 766 974 KeySet *TempSet = new KeySet; 767 975 if (FragmentList[FragmentCounter] != NULL) { 768 for (Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {769 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)976 for (Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) { 977 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++) 770 978 TempSet->insert((Leaf->FindAtom(*sprinter))->GetTrueFather()->nr); 771 TotalGraph.insert(GraphPair(*TempSet, pair<int, double>(TotalNumberOfKeySets++, (*runner).second.second)));979 TotalGraph.insert(GraphPair(*TempSet, pair<int, double> (TotalNumberOfKeySets++, (*runner).second.second))); 772 980 TempSet->clear(); 773 981 } 774 delete (TempSet);982 delete (TempSet); 775 983 } else { 776 984 *out << Verbose(1) << "FragmentList is NULL." << endl; … … 788 996 { 789 997 if (next != NULL) 790 return next->Count() +1;998 return next->Count() + 1; 791 999 else 792 return 1; 793 }; 1000 return 1; 1001 }; 1002
Note:
See TracChangeset
for help on using the changeset viewer.
