Changes in src/moleculelist.cpp [7fd416:1513a74]
- File:
-
- 1 edited
-
src/moleculelist.cpp (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/moleculelist.cpp
r7fd416 r1513a74 20 20 #include "memoryallocator.hpp" 21 21 #include "periodentafel.hpp" 22 #include "Helpers/Assert.hpp" 23 24 #include "Helpers/Assert.hpp" 22 #include "World.hpp" 25 23 26 24 /*********************************** Functions for class MoleculeListClass *************************/ … … 40 38 MoleculeListClass::~MoleculeListClass() 41 39 { 42 DoLog(4) && (Log() << Verbose(4) << "Clearing ListOfMolecules." << endl); 43 for(MoleculeList::iterator MolRunner = ListOfMolecules.begin(); MolRunner != ListOfMolecules.end(); ++MolRunner) 44 (*MolRunner)->signOff(this); 40 DoLog(3) && (Log() << Verbose(3) << this << ": Freeing ListOfMolcules." << endl); 41 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 42 DoLog(4) && (Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl); 43 world->destroyMolecule(*ListRunner); 44 } 45 DoLog(4) && (Log() << Verbose(4) << "Freeing ListOfMolecules." << endl); 45 46 ListOfMolecules.clear(); // empty list 46 47 }; … … 48 49 /** Insert a new molecule into the list and set its number. 49 50 * \param *mol molecule to add to list. 51 * \return true - add successful 50 52 */ 51 53 void MoleculeListClass::insert(molecule *mol) … … 57 59 }; 58 60 59 /** Erases a molecule from the list.60 * \param *mol molecule to add to list.61 */62 void MoleculeListClass::erase(molecule *mol)63 {64 OBSERVE;65 mol->signOff(this);66 ListOfMolecules.remove(mol);67 };68 69 61 /** Compare whether two molecules are equal. 70 62 * \param *a molecule one … … 77 69 int Count, Counter, aCounter, bCounter; 78 70 int flag; 71 atom *aWalker = NULL; 72 atom *bWalker = NULL; 79 73 80 74 // sort each atom list and put the numbers into a list, then go through 81 75 //Log() << Verbose(0) << "Comparing fragment no. " << *(molecule **)a << " to " << *(molecule **)b << "." << endl; 82 // Yes those types are awkward... but check it for yourself it checks out this way 83 molecule *const *mol1_ptr= static_cast<molecule *const *>(a); 84 molecule *mol1 = *mol1_ptr; 85 molecule *const *mol2_ptr= static_cast<molecule *const *>(b); 86 molecule *mol2 = *mol2_ptr; 87 if (mol1->getAtomCount() < mol2->getAtomCount()) { 76 if ((**(molecule **) a).AtomCount < (**(molecule **) b).AtomCount) { 88 77 return -1; 89 78 } else { 90 if ( mol1->getAtomCount() > mol2->getAtomCount())79 if ((**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount) 91 80 return +1; 92 81 else { 93 Count = mol1->getAtomCount();82 Count = (**(molecule **) a).AtomCount; 94 83 aList = new int[Count]; 95 84 bList = new int[Count]; 96 85 97 86 // fill the lists 87 aWalker = (**(molecule **) a).start; 88 bWalker = (**(molecule **) b).start; 98 89 Counter = 0; 99 90 aCounter = 0; 100 91 bCounter = 0; 101 molecule::const_iterator aiter = mol1->begin(); 102 molecule::const_iterator biter = mol2->begin(); 103 for (;(aiter != mol1->end()) && (biter != mol2->end()); 104 ++aiter, ++biter) { 105 if ((*aiter)->GetTrueFather() == NULL) 92 while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) { 93 aWalker = aWalker->next; 94 bWalker = bWalker->next; 95 if (aWalker->GetTrueFather() == NULL) 106 96 aList[Counter] = Count + (aCounter++); 107 97 else 108 aList[Counter] = (*aiter)->GetTrueFather()->nr;109 if ( (*biter)->GetTrueFather() == NULL)98 aList[Counter] = aWalker->GetTrueFather()->nr; 99 if (bWalker->GetTrueFather() == NULL) 110 100 bList[Counter] = Count + (bCounter++); 111 101 else 112 bList[Counter] = (*biter)->GetTrueFather()->nr;102 bList[Counter] = bWalker->GetTrueFather()->nr; 113 103 Counter++; 114 104 } 115 105 // check if AtomCount was for real 116 106 flag = 0; 117 if ((a iter == mol1->end()) && (biter != mol2->end())) {107 if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) { 118 108 flag = -1; 119 109 } else { 120 if ((a iter != mol1->end()) && (biter == mol2->end()))110 if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **) b).end)) 121 111 flag = 1; 122 112 } … … 152 142 void MoleculeListClass::Enumerate(ostream *out) 153 143 { 144 atom *Walker = NULL; 154 145 periodentafel *periode = World::getInstance().getPeriode(); 155 146 std::map<atomicNumber_t,unsigned int> counts; … … 167 158 // count atoms per element and determine size of bounding sphere 168 159 size=0.; 169 for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) { 170 counts[(*iter)->type->getNumber()]++; 171 if ((*iter)->x.DistanceSquared(Origin) > size) 172 size = (*iter)->x.DistanceSquared(Origin); 160 Walker = (*ListRunner)->start; 161 while (Walker->next != (*ListRunner)->end) { 162 Walker = Walker->next; 163 counts[Walker->type->getNumber()]++; 164 if (Walker->x.DistanceSquared(Origin) > size) 165 size = Walker->x.DistanceSquared(Origin); 173 166 } 174 167 // output Index, Name, number of atoms, chemical formula 175 (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)-> getAtomCount()<< "\t";168 (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t"; 176 169 177 170 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; … … 209 202 210 203 // put all molecules of src into mol 211 molecule::iterator runner; 212 for (molecule::iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) { 213 runner = iter++; 214 srcmol->UnlinkAtom((*runner)); 215 mol->AddAtom((*runner)); 204 atom *Walker = srcmol->start; 205 atom *NextAtom = Walker->next; 206 while (NextAtom != srcmol->end) { 207 Walker = NextAtom; 208 NextAtom = Walker->next; 209 srcmol->UnlinkAtom(Walker); 210 mol->AddAtom(Walker); 216 211 } 217 212 … … 233 228 234 229 // put all molecules of src into mol 235 atom *Walker = NULL; 236 for (molecule::iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) { 237 Walker = mol->AddCopyAtom((*iter)); 230 atom *Walker = srcmol->start; 231 atom *NextAtom = Walker->next; 232 while (NextAtom != srcmol->end) { 233 Walker = NextAtom; 234 NextAtom = Walker->next; 235 Walker = mol->AddCopyAtom(Walker); 238 236 Walker->father = Walker; 239 237 } … … 332 330 333 331 // prepare index list for bonds 334 atom ** CopyAtoms = new atom*[srcmol->getAtomCount()]; 335 for(int i=0;i<srcmol->getAtomCount();i++) 332 srcmol->CountAtoms(); 333 atom ** CopyAtoms = new atom*[srcmol->AtomCount]; 334 for(int i=0;i<srcmol->AtomCount;i++) 336 335 CopyAtoms[i] = NULL; 337 336 338 337 // for each of the source atoms check whether we are in- or outside and add copy atom 338 atom *Walker = srcmol->start; 339 339 int nr=0; 340 for (molecule::const_iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) { 341 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << **iter << "." << endl); 342 if (!TesselStruct->IsInnerPoint((*iter)->x, LCList)) { 343 CopyAtoms[(*iter)->nr] = (*iter)->clone(); 344 mol->AddAtom(CopyAtoms[(*iter)->nr]); 340 while (Walker->next != srcmol->end) { 341 Walker = Walker->next; 342 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl); 343 if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) { 344 CopyAtoms[Walker->nr] = Walker->clone(); 345 mol->AddAtom(CopyAtoms[Walker->nr]); 345 346 nr++; 346 347 } else { … … 348 349 } 349 350 } 350 DoLog(1) && (Log() << Verbose(1) << nr << " of " << srcmol-> getAtomCount()<< " atoms have been merged.");351 DoLog(1) && (Log() << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged."); 351 352 352 353 // go through all bonds and add as well 353 for(molecule::iterator AtomRunner = srcmol->begin(); AtomRunner != srcmol->end(); ++AtomRunner)354 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)355 if ((*BondRunner)->leftatom == *AtomRunner) {356 DoLog(3) && (Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[(*BondRunner)->leftatom->nr] << " and " << *CopyAtoms[(*BondRunner)->rightatom->nr]<< "." << endl);357 mol->AddBond(CopyAtoms[(*BondRunner)->leftatom->nr], CopyAtoms[(*BondRunner)->rightatom->nr], (*BondRunner)->BondDegree);358 }354 bond *Binder = srcmol->first; 355 while(Binder->next != srcmol->last) { 356 Binder = Binder->next; 357 DoLog(3) && (Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl); 358 mol->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree); 359 } 359 360 delete(LCList); 360 361 return true; … … 381 382 bool MoleculeListClass::AddHydrogenCorrection(char *path) 382 383 { 384 atom *Walker = NULL; 385 atom *Runner = NULL; 383 386 bond *Binder = NULL; 384 387 double ***FitConstant = NULL, **correction = NULL; … … 424 427 425 428 // 0b. allocate memory for constants 426 FitConstant = new double**[3];429 FitConstant = Calloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 427 430 for (int k = 0; k < 3; k++) { 428 FitConstant[k] = new double*[a];431 FitConstant[k] = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 429 432 for (int i = a; i--;) { 430 FitConstant[k][i] = new double[b]; 431 for (int j = b; j--;) { 432 FitConstant[k][i][j] = 0.; 433 } 433 FitConstant[k][i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 434 434 } 435 435 } … … 477 477 478 478 // 0d. allocate final correction matrix 479 correction = new double*[a];479 correction = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction"); 480 480 for (int i = a; i--;) 481 correction[i] = new double[b];481 correction[i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]"); 482 482 483 483 // 1a. go through every molecule in the list … … 488 488 correction[k][j] = 0.; 489 489 // 2. take every hydrogen that is a saturated one 490 for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) { 491 //Log() << Verbose(1) << "(*iter): " << *(*iter) << " with first bond " << *((*iter)->ListOfBonds.begin()) << "." << endl; 492 if (((*iter)->type->Z == 1) && (((*iter)->father == NULL) 493 || ((*iter)->father->type->Z != 1))) { // if it's a hydrogen 494 for (molecule::const_iterator runner = (*ListRunner)->begin(); runner != (*ListRunner)->end(); ++runner) { 495 //Log() << Verbose(2) << "Runner: " << *(*runner) << " with first bond " << *((*iter)->ListOfBonds.begin()) << "." << endl; 490 Walker = (*ListRunner)->start; 491 while (Walker->next != (*ListRunner)->end) { 492 Walker = Walker->next; 493 //Log() << Verbose(1) << "Walker: " << *Walker << " with first bond " << *(Walker->ListOfBonds.begin()) << "." << endl; 494 if ((Walker->type->Z == 1) && ((Walker->father == NULL) 495 || (Walker->father->type->Z != 1))) { // if it's a hydrogen 496 Runner = (*ListRunner)->start; 497 while (Runner->next != (*ListRunner)->end) { 498 Runner = Runner->next; 499 //Log() << Verbose(2) << "Runner: " << *Runner << " with first bond " << *(Walker->ListOfBonds.begin()) << "." << endl; 496 500 // 3. take every other hydrogen that is the not the first and not bound to same bonding partner 497 Binder = *( (*runner)->ListOfBonds.begin());498 if (( (*runner)->type->Z == 1) && ((*runner)->nr > (*iter)->nr) && (Binder->GetOtherAtom((*runner)) != Binder->GetOtherAtom((*iter)))) { // (hydrogens have only one bonding partner!)501 Binder = *(Runner->ListOfBonds.begin()); 502 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (Binder->GetOtherAtom(Runner) != Binder->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!) 499 503 // 4. evaluate the morse potential for each matrix component and add up 500 distance = (*runner)->x.distance((*iter)->x);501 //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << * (*runner) << "<= " << distance << "=>" << *(*iter)<< ":" << endl;504 distance = Runner->x.distance(Walker->x); 505 //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl; 502 506 for (int k = 0; k < a; k++) { 503 507 for (int j = 0; j < b; j++) { … … 527 531 FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), (*ListRunner)->IndexNr); 528 532 line += FragmentNumber; 529 delete [](FragmentNumber);533 delete (FragmentNumber); 530 534 line += HCORRECTIONSUFFIX; 531 535 output.open(line.c_str()); … … 538 542 output.close(); 539 543 } 540 for (int i = a; i--;)541 delete[](correction[i]);542 delete[](correction);543 544 544 line = path; 545 545 line.append("/"); … … 556 556 for (int k = 0; k < 3; k++) { 557 557 for (int i = a; i--;) { 558 delete[](FitConstant[k][i]);559 } 560 delete[](FitConstant[k]);561 } 562 delete[](FitConstant);558 Free(&FitConstant[k][i]); 559 } 560 Free(&FitConstant[k]); 561 } 562 Free(&FitConstant); 563 563 DoLog(0) && (Log() << Verbose(0) << "done." << endl); 564 564 return true; … … 577 577 ofstream ForcesFile; 578 578 stringstream line; 579 atom *Walker = NULL; 579 580 periodentafel *periode=World::getInstance().getPeriode(); 580 581 … … 589 590 periodentafel::const_iterator elemIter; 590 591 for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){ 591 if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms 592 for(molecule::iterator atomIter = (*ListRunner)->begin(); atomIter !=(*ListRunner)->end();++atomIter){ 593 if ((*atomIter)->type->getNumber() == (*elemIter).first) { 594 if (((*atomIter)->GetTrueFather() != NULL) && ((*atomIter)->GetTrueFather() != (*atomIter))) {// if there is a rea 592 if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms 593 Walker = (*ListRunner)->start; 594 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element 595 Walker = Walker->next; 596 if (Walker->type->getNumber() == (*elemIter).first) { 597 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 595 598 //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it 596 ForcesFile << SortIndex[ (*atomIter)->GetTrueFather()->nr] << "\t";599 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t"; 597 600 } else 598 601 // otherwise a -1 to indicate an added saturation hydrogen … … 619 622 * \param *configuration standard configuration to attach atoms in fragment molecule to. 620 623 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config 624 * \param DoPeriodic true - call ScanForPeriodicCorrection, false - don't 625 * \param DoCentering true - call molecule::CenterEdge(), false - don't 621 626 * \return true - success (each file was written), false - something went wrong. 622 627 */ … … 628 633 bool result = true; 629 634 bool intermediateResult = true; 635 atom *Walker = NULL; 630 636 Vector BoxDimension; 631 637 char *FragmentNumber = NULL; … … 668 674 // list atoms in fragment for debugging 669 675 DoLog(2) && (Log() << Verbose(2) << "Contained atoms: "); 670 for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) { 671 DoLog(0) && (Log() << Verbose(0) << (*iter)->getName() << " "); 676 Walker = (*ListRunner)->start; 677 while (Walker->next != (*ListRunner)->end) { 678 Walker = Walker->next; 679 DoLog(0) && (Log() << Verbose(0) << Walker->Name << " "); 672 680 } 673 681 DoLog(0) && (Log() << Verbose(0) << endl); … … 716 724 //outputFragment.close(); 717 725 //outputFragment.clear(); 718 delete[](FragmentNumber);726 Free(&FragmentNumber); 719 727 } 720 728 DoLog(0) && (Log() << Verbose(0) << " done." << endl); … … 748 756 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration) 749 757 { 750 // 0a. remove all present molecules 751 vector<molecule *> allmolecules = World::getInstance().getAllMolecules(); 752 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) { 753 erase(*MolRunner); 758 molecule *mol = World::getInstance().createMolecule(); 759 atom *Walker = NULL; 760 atom *Advancer = NULL; 761 bond *Binder = NULL; 762 bond *Stepper = NULL; 763 // 0. gather all atoms into single molecule 764 for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) { 765 // shift all atoms to new molecule 766 Advancer = (*MolRunner)->start->next; 767 while (Advancer != (*MolRunner)->end) { 768 Walker = Advancer; 769 Advancer = Advancer->next; 770 DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl); 771 unlink(Walker); 772 Walker->father = Walker; 773 mol->AddAtom(Walker); // counting starts at 1 774 } 775 // remove all bonds 776 Stepper = (*MolRunner)->first->next; 777 while (Stepper != (*MolRunner)->last) { 778 Binder = Stepper; 779 Stepper = Stepper->next; 780 delete(Binder); 781 } 782 // remove the molecule 754 783 World::getInstance().destroyMolecule(*MolRunner); 755 } 756 // 0b. remove all bonds and construct a molecule with all atoms 757 molecule *mol = World::getInstance().createMolecule(); 758 vector <atom *> allatoms = World::getInstance().getAllAtoms(); 759 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) { 760 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 761 delete(*BondRunner); 762 mol->AddAtom(*AtomRunner); 784 ListOfMolecules.erase(MolRunner); 763 785 } 764 786 … … 788 810 const int MolCount = Subgraphs->next->Count(); 789 811 char number[MAXSTRINGSIZE]; 790 molecule **molecules = new molecule *[MolCount]; 791 MoleculeLeafClass *MolecularWalker = Subgraphs; 812 molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules"); 792 813 for (int i=0;i<MolCount;i++) { 793 MolecularWalker = MolecularWalker->next;794 814 molecules[i] = World::getInstance().createMolecule(); 795 815 molecules[i]->ActiveFlag = true; … … 800 820 } 801 821 DoLog(1) && (Log() << Verbose(1) << "MolName is " << molecules[i]->name << endl); 802 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); iter != MolecularWalker->Leaf->end(); ++iter) {803 DoLog(1) && (Log() << Verbose(1) << **iter << endl);804 }805 822 insert(molecules[i]); 806 823 } … … 808 825 // 4b. create and fill map of which atom is associated to which connected molecule (note, counting starts at 1) 809 826 int FragmentCounter = 0; 810 map<int, atom *> AtomToFragmentMap; 811 MolecularWalker = Subgraphs; 827 int *MolMap = Calloc<int>(mol->AtomCount, "config::Load() - *MolMap"); 828 MoleculeLeafClass *MolecularWalker = Subgraphs; 829 Walker = NULL; 812 830 while (MolecularWalker->next != NULL) { 813 831 MolecularWalker = MolecularWalker->next; 814 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); !MolecularWalker->Leaf->empty(); iter = MolecularWalker->Leaf->begin()) { 815 atom * Walker = *iter; 816 DoLog(1) && (Log() << Verbose(1) << "Re-linking " << Walker << "..." << endl); 817 MolecularWalker->Leaf->erase(iter); 818 molecules[FragmentCounter]->AddAtom(Walker); // counting starts at 1 832 Walker = MolecularWalker->Leaf->start; 833 while (Walker->next != MolecularWalker->Leaf->end) { 834 Walker = Walker->next; 835 MolMap[Walker->GetTrueFather()->nr] = FragmentCounter+1; 819 836 } 820 837 FragmentCounter++; 821 838 } 822 World::getInstance().destroyMolecule(mol); 823 839 840 // 4c. relocate atoms to new molecules and remove from Leafs 841 Walker = NULL; 842 while (mol->start->next != mol->end) { 843 Walker = mol->start->next; 844 if ((Walker->nr <0) || (Walker->nr >= mol->AtomCount)) { 845 DoeLog(0) && (eLog()<< Verbose(0) << "Index of atom " << *Walker << " is invalid!" << endl); 846 performCriticalExit(); 847 } 848 FragmentCounter = MolMap[Walker->nr]; 849 if (FragmentCounter != 0) { 850 DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl); 851 unlink(Walker); 852 molecules[FragmentCounter-1]->AddAtom(Walker); // counting starts at 1 853 } else { 854 DoeLog(0) && (eLog()<< Verbose(0) << "Atom " << *Walker << " not associated to molecule!" << endl); 855 performCriticalExit(); 856 } 857 } 824 858 // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list 825 // TODO: check whether this is really not needed anymore 859 Binder = mol->first; 860 while (mol->first->next != mol->last) { 861 Binder = mol->first->next; 862 Walker = Binder->leftatom; 863 unlink(Binder); 864 link(Binder,molecules[MolMap[Walker->nr]-1]->last); // counting starts at 1 865 } 826 866 // 4e. free Leafs 827 867 MolecularWalker = Subgraphs; … … 831 871 } 832 872 delete(MolecularWalker); 833 delete[](molecules); 873 Free(&MolMap); 874 Free(&molecules); 834 875 DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl); 835 876 }; … … 841 882 int MoleculeListClass::CountAllAtoms() const 842 883 { 884 atom *Walker = NULL; 843 885 int AtomNo = 0; 844 886 for (MoleculeList::const_iterator MolWalker = ListOfMolecules.begin(); MolWalker != ListOfMolecules.end(); MolWalker++) { 845 AtomNo += (*MolWalker)->size(); 887 Walker = (*MolWalker)->start; 888 while (Walker->next != (*MolWalker)->end) { 889 Walker = Walker->next; 890 AtomNo++; 891 } 846 892 } 847 893 return AtomNo; … … 1018 1064 bool MoleculeLeafClass::FillBondStructureFromReference(const molecule * const reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList) 1019 1065 { 1066 atom *Walker = NULL; 1020 1067 atom *OtherWalker = NULL; 1021 1068 atom *Father = NULL; … … 1025 1072 DoLog(1) && (Log() << Verbose(1) << "Begin of FillBondStructureFromReference." << endl); 1026 1073 // fill ListOfLocalAtoms if NULL was given 1027 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference-> getAtomCount(), FreeList)) {1074 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) { 1028 1075 DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl); 1029 1076 return false; … … 1033 1080 DoLog(1) && (Log() << Verbose(1) << "Creating adjacency list for subgraph " << Leaf << "." << endl); 1034 1081 // remove every bond from the list 1035 for(molecule::iterator AtomRunner = Leaf->begin(); AtomRunner != Leaf->end(); ++AtomRunner) 1036 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 1037 if ((*BondRunner)->leftatom == *AtomRunner) 1038 delete((*BondRunner)); 1039 1040 for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) { 1041 Father = (*iter)->GetTrueFather(); 1082 bond *Binder = NULL; 1083 while (Leaf->last->previous != Leaf->first) { 1084 Binder = Leaf->last->previous; 1085 Binder->leftatom->UnregisterBond(Binder); 1086 Binder->rightatom->UnregisterBond(Binder); 1087 removewithoutcheck(Binder); 1088 } 1089 1090 Walker = Leaf->start; 1091 while (Walker->next != Leaf->end) { 1092 Walker = Walker->next; 1093 Father = Walker->GetTrueFather(); 1042 1094 AtomNo = Father->nr; // global id of the current walker 1043 1095 for (BondList::const_iterator Runner = Father->ListOfBonds.begin(); Runner != Father->ListOfBonds.end(); (++Runner)) { 1044 OtherWalker = ListOfLocalAtoms[FragmentCounter][(*Runner)->GetOtherAtom( (*iter)->GetTrueFather())->nr]; // local copy of current bond partner of walker1096 OtherWalker = ListOfLocalAtoms[FragmentCounter][(*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker 1045 1097 if (OtherWalker != NULL) { 1046 if (OtherWalker->nr > (*iter)->nr)1047 Leaf->AddBond( (*iter), OtherWalker, (*Runner)->BondDegree);1098 if (OtherWalker->nr > Walker->nr) 1099 Leaf->AddBond(Walker, OtherWalker, (*Runner)->BondDegree); 1048 1100 } else { 1049 DoLog(1) && (Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom( (*iter)->GetTrueFather())->nr << "] is NULL!" << endl);1101 DoLog(1) && (Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl); 1050 1102 status = false; 1051 1103 } … … 1056 1108 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 1057 1109 // free the index lookup list 1058 delete[](ListOfLocalAtoms[FragmentCounter]);1110 Free(&ListOfLocalAtoms[FragmentCounter]); 1059 1111 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 1060 delete[](ListOfLocalAtoms);1112 Free(&ListOfLocalAtoms); 1061 1113 } 1062 1114 DoLog(1) && (Log() << Verbose(1) << "End of FillBondStructureFromReference." << endl); … … 1074 1126 bool MoleculeLeafClass::FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 1075 1127 { 1076 atom * Father = NULL;1128 atom *Walker = NULL, *Father = NULL; 1077 1129 1078 1130 if (RootStack != NULL) { … … 1080 1132 if (&(RootStack[FragmentCounter]) != NULL) { 1081 1133 RootStack[FragmentCounter].clear(); 1082 for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) { 1083 Father = (*iter)->GetTrueFather(); 1134 Walker = Leaf->start; 1135 while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms 1136 Walker = Walker->next; 1137 Father = Walker->GetTrueFather(); 1084 1138 if (AtomMask[Father->nr]) // apply mask 1085 1139 #ifdef ADDHYDROGEN 1086 if ( (*iter)->type->Z != 1) // skip hydrogen1140 if (Walker->type->Z != 1) // skip hydrogen 1087 1141 #endif 1088 RootStack[FragmentCounter].push_front( (*iter)->nr);1142 RootStack[FragmentCounter].push_front(Walker->nr); 1089 1143 } 1090 1144 if (next != NULL) … … 1117 1171 // allocate and set each field to NULL 1118 1172 const int Counter = Count(); 1119 ASSERT(FragmentCounter < Counter, "FillListOfLocalAtoms: FragmenCounter greater than present fragments."); 1120 ListOfLocalAtoms = new atom**[Counter]; 1173 ListOfLocalAtoms = Calloc<atom**>(Counter, "MoleculeLeafClass::FillListOfLocalAtoms - ***ListOfLocalAtoms"); 1121 1174 if (ListOfLocalAtoms == NULL) { 1122 1175 FreeList = FreeList && false; 1123 1176 status = false; 1124 1177 } 1125 for (int i=0;i<Counter;i++)1126 ListOfLocalAtoms[i] = NULL;1127 1178 } 1128 1179 1129 1180 if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph 1130 status = status && Leaf->CreateFatherLookupTable(ListOfLocalAtoms[FragmentCounter], GlobalAtomCount);1181 status = status && CreateFatherLookupTable(Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount); 1131 1182 FreeList = FreeList && true; 1132 1183 } … … 1152 1203 DoLog(1) && (Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl); 1153 1204 // fill ListOfLocalAtoms if NULL was given 1154 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference-> getAtomCount(), FreeList)) {1205 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) { 1155 1206 DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl); 1156 1207 return false; … … 1160 1211 if (FragmentList == NULL) { 1161 1212 KeySetCounter = Count(); 1162 FragmentList = new Graph*[KeySetCounter]; 1163 for (int i=0;i<KeySetCounter;i++) 1164 FragmentList[i] = NULL; 1213 FragmentList = Calloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList"); 1165 1214 KeySetCounter = 0; 1166 1215 } … … 1196 1245 if ((FreeList) && (ListOfLocalAtoms != NULL)) { 1197 1246 // free the index lookup list 1198 delete[](ListOfLocalAtoms[FragmentCounter]);1247 Free(&ListOfLocalAtoms[FragmentCounter]); 1199 1248 if (FragmentCounter == 0) // first fragments frees the initial pointer to list 1200 delete[](ListOfLocalAtoms);1249 Free(&ListOfLocalAtoms); 1201 1250 } 1202 1251 DoLog(1) && (Log() << Verbose(1) << "End of AssignKeySetsToFragment." << endl);
Note:
See TracChangeset
for help on using the changeset viewer.
