Changes in molecuilder/src/moleculelist.cpp [1b2aa1:f23d7d]
- File:
-
- 1 edited
-
molecuilder/src/moleculelist.cpp (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/moleculelist.cpp
r1b2aa1 rf23d7d 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 // empty lists 16 ListOfMolecules.clear(); 17 MaxIndex = 1; 18 }; 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 19 30 20 31 /** Destructor for MoleculeListClass. … … 23 34 { 24 35 cout << Verbose(3) << this << ": Freeing ListOfMolcules." << endl; 25 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 26 cout << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl; 27 delete (*ListRunner); 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 } 28 42 } 29 43 cout << Verbose(4) << "Freeing ListOfMolecules." << endl; 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); 44 Free((void **)&ListOfMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules"); 41 45 }; 42 46 … … 53 57 atom *aWalker = NULL; 54 58 atom *bWalker = NULL; 55 59 56 60 // sort each atom list and put the numbers into a list, then go through 57 61 //cout << "Comparing fragment no. " << *(molecule **)a << " to " << *(molecule **)b << "." << endl; 58 if ( (**(molecule **) a).AtomCount < (**(molecule **) b).AtomCount) {62 if ( (**(molecule **)a).AtomCount < (**(molecule **)b).AtomCount ) { 59 63 return -1; 60 } else { 61 if ((**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount) 62 return +1; 64 } else { if ((**(molecule **)a).AtomCount > (**(molecule **)b).AtomCount) 65 return +1; 63 66 else { 64 Count = (**(molecule **) a).AtomCount;67 Count = (**(molecule **)a).AtomCount; 65 68 aList = new int[Count]; 66 69 bList = new int[Count]; 67 70 68 71 // fill the lists 69 aWalker = (**(molecule **) a).start;70 bWalker = (**(molecule **) b).start;72 aWalker = (**(molecule **)a).start; 73 bWalker = (**(molecule **)b).start; 71 74 Counter = 0; 72 75 aCounter = 0; 73 76 bCounter = 0; 74 while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **)b).end)) {77 while ((aWalker->next != (**(molecule **)a).end) && (bWalker->next != (**(molecule **)b).end)) { 75 78 aWalker = aWalker->next; 76 79 bWalker = bWalker->next; … … 87 90 // check if AtomCount was for real 88 91 flag = 0; 89 if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **)b).end)) {92 if ((aWalker->next == (**(molecule **)a).end) && (bWalker->next != (**(molecule **)b).end)) { 90 93 flag = -1; 91 94 } else { 92 if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **)b).end))95 if ((aWalker->next != (**(molecule **)a).end) && (bWalker->next == (**(molecule **)b).end)) 93 96 flag = 1; 94 97 } 95 98 if (flag == 0) { 96 99 // sort the lists 97 gsl_heapsort(aList, Count, sizeof(int), CompareDoubles);98 gsl_heapsort(bList, Count, sizeof(int), CompareDoubles);99 // compare the lists 100 100 gsl_heapsort(aList,Count, sizeof(int), CompareDoubles); 101 gsl_heapsort(bList,Count, sizeof(int), CompareDoubles); 102 // compare the lists 103 101 104 flag = 0; 102 for (int i = 0; i < Count;i++) {105 for(int i=0;i<Count;i++) { 103 106 if (aList[i] < bList[i]) { 104 107 flag = -1; … … 111 114 } 112 115 } 113 delete[] (aList);114 delete[] (bList);116 delete[](aList); 117 delete[](bList); 115 118 return flag; 116 119 } 117 120 } 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; 121 return -1; 310 122 }; 311 123 … … 315 127 void MoleculeListClass::Output(ofstream *out) 316 128 { 317 *out << Verbose(1) << "MoleculeList: ";318 for ( MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)319 *out << *ListRunner<< "\t";129 *out<< Verbose(1) << "MoleculeList: "; 130 for (int i=0;i<NumberOfMolecules;i++) 131 *out << ListOfMolecules[i] << "\t"; 320 132 *out << endl; 321 133 }; … … 333 145 atom *Runner = NULL; 334 146 double ***FitConstant = NULL, **correction = NULL; 335 int a, b;147 int a,b; 336 148 ofstream output; 337 149 ifstream input; … … 353 165 input.open(line.c_str()); 354 166 if (input == NULL) { 355 cerr << endl << "Unable to open " << line << ", is the directory correct?" 356 << endl; 167 cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl; 357 168 return false; 358 169 } 359 a =0;360 b = -1; // we overcount by one170 a=0; 171 b=-1; // we overcount by one 361 172 while (!input.eof()) { 362 173 input.getline(ParsedLine, 1023); 363 174 zeile.str(ParsedLine); 364 int i =0;175 int i=0; 365 176 while (!zeile.eof()) { 366 177 zeile >> distance; 367 178 i++; 368 179 } 369 if (i > a) 370 a = i; 180 if (i > a) 181 a = i; 371 182 b++; 372 183 } 373 184 cout << "I recognized " << a << " columns and " << b << " rows, "; 374 185 input.close(); 375 186 376 187 // 0b. allocate memory for constants 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[][]");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[][]"); 382 193 } 383 194 } 384 195 // 0c. parse in constants 385 for (int i = 0; i < 3;i++) {196 for (int i=0;i<3;i++) { 386 197 line = path; 387 198 line.append("/"); 388 199 line += FRAGMENTPREFIX; 389 sprintf(ParsedLine, "%d", i +1);200 sprintf(ParsedLine, "%d", i+1); 390 201 line += ParsedLine; 391 202 line += FITCONSTANTSUFFIX; … … 395 206 return false; 396 207 } 397 int k = 0, l;208 int k = 0,l; 398 209 while ((!input.eof()) && (k < b)) { 399 210 input.getline(ParsedLine, 1023); … … 412 223 input.close(); 413 224 } 414 for (int k = 0; k < 3;k++) {225 for(int k=0;k<3;k++) { 415 226 cout << "Constants " << k << ":" << endl; 416 for (int j = 0; j < b;j++) {417 for (int i = 0; i < a;i++) {227 for (int j=0;j<b;j++) { 228 for (int i=0;i<a;i++) { 418 229 cout << FitConstant[k][i][j] << "\t"; 419 230 } … … 422 233 cout << endl; 423 234 } 424 235 425 236 // 0d. allocate final correction matrix 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 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 430 241 // 1a. go through every molecule in the list 431 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {242 for(int i=NumberOfMolecules;i--;) { 432 243 // 1b. zero final correction matrix 433 for (int k = a;k--;)434 for (int j = b;j--;)244 for (int k=a;k--;) 245 for (int j=b;j--;) 435 246 correction[k][j] = 0.; 436 247 // 2. take every hydrogen that is a saturated one 437 Walker = (*ListRunner)->start;438 while (Walker->next != (*ListRunner)->end) {248 Walker = ListOfMolecules[i]->start; 249 while (Walker->next != ListOfMolecules[i]->end) { 439 250 Walker = Walker->next; 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) { 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) { 445 255 Runner = Runner->next; 446 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << * (*Runner)->ListOfBondsPerAtom[Runner->nr][0] << "." << endl;256 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0] << "." << endl; 447 257 // 3. take every other hydrogen that is the not the first and not bound to same 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!)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!) 449 259 // 4. evaluate the morse potential for each matrix component and add up 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];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]; 462 272 }; 463 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction)273 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction) 464 274 //cout << tmp << "\t"; 465 275 } … … 475 285 line.append("/"); 476 286 line += FRAGMENTPREFIX; 477 FragmentNumber = FixedDigitNumber( ListOfMolecules.size(), (*ListRunner)->IndexNr);287 FragmentNumber = FixedDigitNumber(NumberOfMolecules, i); 478 288 line += FragmentNumber; 479 delete (FragmentNumber);289 delete(FragmentNumber); 480 290 line += HCORRECTIONSUFFIX; 481 291 output.open(line.c_str()); 482 292 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 483 for (int j = 0; j < b;j++) {484 for (int i = 0; i < a;i++)293 for (int j=0;j<b;j++) { 294 for(int i=0;i<a;i++) 485 295 output << correction[i][j] << "\t"; 486 296 output << endl; … … 493 303 output.open(line.c_str()); 494 304 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 495 for (int j = 0; j < b;j++) {496 for (int i = 0; i < a;i++)305 for (int j=0;j<b;j++) { 306 for(int i=0;i<a;i++) 497 307 output << 0 << "\t"; 498 308 output << endl; … … 500 310 output.close(); 501 311 // 6. free memory of parsed matrices 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[][]");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[][]"); 507 317 } 508 318 } … … 517 327 * \return true - file written successfully, false - writing failed 518 328 */ 519 bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path, 520 int *SortIndex) 329 bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path, int *SortIndex) 521 330 { 522 331 bool status = true; … … 533 342 //cout << Verbose(1) << "Final AtomicForcesList: "; 534 343 //output << prefix << "Forces" << endl; 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 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 538 348 runner = runner->next; 539 if ( (*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms540 Walker = (*ListRunner)->start;541 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element349 if (ListOfMolecules[j]->ElementsInMolecule[runner->Z]) { // if this element got atoms 350 Walker = ListOfMolecules[j]->start; 351 while (Walker->next != ListOfMolecules[j]->end) { // go through every atom of this element 542 352 Walker = Walker->next; 543 353 if (Walker->type->Z == runner->Z) { 544 354 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 545 355 //cout << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it 546 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t";547 } else548 // otherwise a -1 to indicate an added saturation hydrogen549 ForcesFile << "-1\t";356 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t"; 357 } else // otherwise a -1 to indicate an added saturation hydrogen 358 ForcesFile << "-1\t"; 359 } 550 360 } 551 361 } 552 }553 362 } 554 363 ForcesFile << endl; … … 561 370 } 562 371 ForcesFile.close(); 563 372 564 373 return status; 565 374 }; … … 571 380 * \return true - success (each file was written), false - something went wrong. 572 381 */ 573 bool MoleculeListClass::OutputConfigForListOfFragments(ofstream *out, 574 config *configuration, int *SortIndex) 382 bool MoleculeListClass::OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex) 575 383 { 576 384 ofstream outputFragment; … … 585 393 int FragmentCounter = 0; 586 394 ofstream output; 587 395 string basis("3-21G"); 396 588 397 // store the fragments as config and as xyz 589 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {398 for(int i=0;i<NumberOfMolecules;i++) { 590 399 // save default path as it is changed for each fragment 591 400 path = configuration->GetDefaultPath(); … … 596 405 597 406 // correct periodic 598 (*ListRunner)->ScanForPeriodicCorrection(out);407 //ListOfMolecules[i]->ScanForPeriodicCorrection(out); 599 408 600 409 // output xyz file 601 FragmentNumber = FixedDigitNumber( ListOfMolecules.size(), FragmentCounter++);410 FragmentNumber = FixedDigitNumber(NumberOfMolecules, FragmentCounter++); 602 411 sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 603 412 outputFragment.open(FragmentName, ios::out); 604 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as XYZ ...";605 if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment)))413 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as XYZ ..."; 414 if ((intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment))) 606 415 *out << " done." << endl; 607 416 else … … 613 422 // list atoms in fragment for debugging 614 423 *out << Verbose(2) << "Contained atoms: "; 615 Walker = (*ListRunner)->start;616 while (Walker->next != (*ListRunner)->end) {424 Walker = ListOfMolecules[i]->start; 425 while (Walker->next != ListOfMolecules[i]->end) { 617 426 Walker = Walker->next; 618 427 *out << Walker->Name << " "; 619 428 } 620 429 *out << endl; 621 430 622 431 // center on edge 623 (*ListRunner)->CenterEdge(out, &BoxDimension);624 (*ListRunner)->SetBoxDimension(&BoxDimension);// update Box of atoms by boundary432 ListOfMolecules[i]->CenterEdge(out, &BoxDimension); 433 ListOfMolecules[i]->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary 625 434 int j = -1; 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);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); 632 441 633 442 // also calculate necessary orbitals 634 (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment635 (*ListRunner)->CalculateOrbitals(*configuration);636 443 ListOfMolecules[i]->CountElements(); // this is a bugfix, atoms should should actually be added correctly to this fragment 444 ListOfMolecules[i]->CalculateOrbitals(*configuration); 445 637 446 // change path in config 638 447 //strcpy(PathBackup, configuration->configpath); 639 448 sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber); 640 449 configuration->SetDefaultPath(FragmentName); 641 450 642 451 // and save as config 643 452 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 644 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as config ...";645 if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))453 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as config ..."; 454 if ((intermediateResult = configuration->Save(FragmentName, ListOfMolecules[i]->elemente, ListOfMolecules[i]))) 646 455 *out << " done." << endl; 647 456 else … … 652 461 configuration->SetDefaultPath(PathBackup); 653 462 463 654 464 // and save as mpqc input file 655 465 sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); 656 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter -1 << " as mpqc input ...";657 if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))466 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as mpqc input ..."; 467 if ((intermediateResult = configuration->SaveMPQC(FragmentName, ListOfMolecules[i]))) 658 468 *out << " done." << endl; 659 469 else 660 470 *out << " failed." << endl; 661 471 662 472 result = result && intermediateResult; 663 473 //outputFragment.close(); 664 474 //outputFragment.clear(); 665 delete (FragmentNumber);475 delete(FragmentNumber); 666 476 //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber"); 667 477 } 668 478 cout << " done." << endl; 669 479 670 480 // printing final number 671 481 *out << "Final number of fragments: " << FragmentCounter << "." << endl; 672 482 673 483 return result; 674 484 }; 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 687 485 688 486 /******************************************* Class MoleculeLeafClass ************************************************/ … … 695 493 MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL) 696 494 { 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;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; 702 500 Leaf = NULL; 703 501 previous = PreviousLeaf; … … 715 513 MoleculeLeafClass::~MoleculeLeafClass() 716 514 { 717 // if (DownLeaf != NULL) {// drop leaves further down718 // 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 NULL726 // }515 // if (DownLeaf != NULL) {// drop leaves further down 516 // 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 NULL 524 // } 727 525 // remove the leaf itself 728 526 if (Leaf != NULL) { 729 delete (Leaf);527 delete(Leaf); 730 528 Leaf = NULL; 731 529 } 732 530 // remove this Leaf from level list 733 if (previous != NULL) 531 if (previous != NULL) 734 532 previous->next = next; 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 node738 // if (UpLeaf != NULL)739 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first740 // }741 // UpLeaf = NULL;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 node 536 // if (UpLeaf != NULL) 537 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first 538 // } 539 // UpLeaf = NULL; 742 540 if (next != NULL) // are we last in list 743 541 next->previous = previous; … … 778 576 return false; 779 577 } 780 578 781 579 if (status) { 782 *out << Verbose(1) << "Creating adjacency list for subgraph " << this 783 << "." << endl; 580 *out << Verbose(1) << "Creating adjacency list for subgraph " << this << "." << endl; 784 581 Walker = Leaf->start; 785 582 while (Walker->next != Leaf->end) { 786 583 Walker = Walker->next; 787 AtomNo = Walker->GetTrueFather()->nr; // global id of the current walker788 for (int i = 0; i < reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all584 AtomNo = Walker->GetTrueFather()->nr; // global id of the current walker 585 for(int i=0;i<reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all 789 586 Binder = reference->ListOfBondsPerAtom[AtomNo][i]; 790 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker587 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker 791 588 if (OtherWalker != NULL) { 792 589 if (OtherWalker->nr > Walker->nr) 793 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);590 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree); 794 591 } else { 795 592 *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl; … … 804 601 FragmentCounter--; 805 602 } 806 603 807 604 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 808 605 // free the index lookup list 809 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");606 Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]"); 810 607 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 811 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");608 Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 812 609 } 813 610 FragmentCounter--; … … 824 621 * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update 825 622 */ 826 bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, 827 KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 623 bool MoleculeLeafClass::FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 828 624 { 829 625 atom *Walker = NULL, *Father = NULL; 830 626 831 627 if (RootStack != NULL) { 832 // find first root candidates 628 // find first root candidates 833 629 if (&(RootStack[FragmentCounter]) != NULL) { 834 RootStack[FragmentCounter].clear(); 630 RootStack[FragmentCounter].clear(); 835 631 Walker = Leaf->start; 836 632 while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms … … 838 634 Father = Walker->GetTrueFather(); 839 635 if (AtomMask[Father->nr]) // apply mask 840 #ifdef ADDHYDROGEN636 #ifdef ADDHYDROGEN 841 637 if (Walker->type->Z != 1) // skip hydrogen 842 #endif843 RootStack[FragmentCounter].push_front(Walker->nr);638 #endif 639 RootStack[FragmentCounter].push_front(Walker->nr); 844 640 } 845 641 if (next != NULL) 846 642 next->FillRootStackForSubgraphs(out, RootStack, AtomMask, ++FragmentCounter); 847 } else {848 *out << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl;643 } else { 644 *out << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl; 849 645 return false; 850 646 } … … 868 664 { 869 665 bool status = true; 870 666 871 667 int Counter = Count(); 872 668 if (ListOfLocalAtoms == NULL) { // allocated initial pointer 873 669 // allocate and set each field to NULL 874 ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **) *Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");670 ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 875 671 if (ListOfLocalAtoms != NULL) { 876 for (int i = Counter;i--;)672 for (int i=Counter;i--;) 877 673 ListOfLocalAtoms[i] = NULL; 878 674 FreeList = FreeList && true; … … 880 676 status = false; 881 677 } 882 678 883 679 if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph 884 680 status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount); 885 681 FreeList = FreeList && true; 886 682 } 887 683 888 684 return status; 889 685 }; … … 899 695 * \retuen true - success, false - failure 900 696 */ 901 bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out, 902 molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, 903 Graph **&FragmentList, int &FragmentCounter, bool FreeList) 697 bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList) 904 698 { 905 699 bool status = true; 906 700 int KeySetCounter = 0; 907 701 908 702 *out << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl; 909 703 // fill ListOfLocalAtoms if NULL was given … … 916 710 if (FragmentList == NULL) { 917 711 KeySetCounter = Count(); 918 FragmentList = (Graph **) Malloc(sizeof(Graph *) *KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");919 for (int i = KeySetCounter;i--;)712 FragmentList = (Graph **) Malloc(sizeof(Graph *)*KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList"); 713 for(int i=KeySetCounter;i--;) 920 714 FragmentList[i] = NULL; 921 715 KeySetCounter = 0; 922 716 } 923 717 924 718 if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all 925 719 // assign scanned keysets … … 927 721 FragmentList[FragmentCounter] = new Graph; 928 722 KeySet *TempSet = new KeySet; 929 for (Graph::iterator runner = KeySetList->begin();runner != KeySetList->end(); runner++) { // key sets contain global numbers!930 if ( ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set723 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 set 931 725 // translate keyset to local numbers 932 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)726 for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++) 933 727 TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->nr]->nr); 934 728 // insert into FragmentList 935 FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int, double>(KeySetCounter++, (*runner).second.second)));729 FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int,double>(KeySetCounter++, (*runner).second.second))); 936 730 } 937 731 TempSet->clear(); 938 732 } 939 delete (TempSet);733 delete(TempSet); 940 734 if (KeySetCounter == 0) {// if there are no keysets, delete the list 941 735 *out << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl; 942 delete (FragmentList[FragmentCounter]);736 delete(FragmentList[FragmentCounter]); 943 737 } else 944 738 *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl; … … 949 743 } else 950 744 *out << Verbose(1) << "KeySetList is NULL or empty." << endl; 951 745 952 746 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 953 747 // free the index lookup list 954 Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");748 Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]"); 955 749 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 956 Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");750 Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms"); 957 751 } 958 752 *out << Verbose(1) << "End of AssignKeySetsToFragment." << endl; … … 966 760 * \param &TotalNumberOfKeySets global key set counter 967 761 * \param &TotalGraph Graph to be filled with global numbers 968 */ 969 void MoleculeLeafClass::TranslateIndicesToGlobalIDs(ofstream *out, 970 Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, 971 Graph &TotalGraph) 762 */ 763 void MoleculeLeafClass::TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph) 972 764 { 973 765 *out << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl; 974 766 KeySet *TempSet = new KeySet; 975 767 if (FragmentList[FragmentCounter] != NULL) { 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++)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++) 978 770 TempSet->insert((Leaf->FindAtom(*sprinter))->GetTrueFather()->nr); 979 TotalGraph.insert(GraphPair(*TempSet, pair<int, double>(TotalNumberOfKeySets++, (*runner).second.second)));771 TotalGraph.insert(GraphPair(*TempSet, pair<int,double>(TotalNumberOfKeySets++, (*runner).second.second))); 980 772 TempSet->clear(); 981 773 } 982 delete (TempSet);774 delete(TempSet); 983 775 } else { 984 776 *out << Verbose(1) << "FragmentList is NULL." << endl; … … 996 788 { 997 789 if (next != NULL) 998 return next->Count() +1;790 return next->Count()+1; 999 791 else 1000 return 1; 1001 }; 1002 792 return 1; 793 };
Note:
See TracChangeset
for help on using the changeset viewer.
