Changeset b86de7 for molecuilder/src/molecules.cpp
- Timestamp:
- Oct 9, 2008, 6:27:56 PM (17 years ago)
- Children:
- d01f4d
- Parents:
- a7b3b8
- File:
-
- 1 edited
-
molecuilder/src/molecules.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecules.cpp
ra7b3b8 rb86de7 2244 2244 int *MinimumRingSize = NULL; 2245 2245 MoleculeLeafClass *Subgraphs = NULL; 2246 class StackClass<bond *> *BackEdgeStack = NULL; 2246 2247 bond *Binder = first; 2247 2248 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 2248 2249 *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl; 2249 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);2250 Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack); 2250 2251 while (Subgraphs->next != NULL) { 2251 2252 Subgraphs = Subgraphs->next; … … 2260 2261 No++; 2261 2262 } 2263 delete(BackEdgeStack); 2262 2264 return No; 2263 2265 }; … … 2341 2343 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 2342 2344 Vector x; 2345 int FalseBondDegree = 0; 2343 2346 2344 2347 BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem); … … 2359 2362 j += i+1; 2360 2363 divisor[i] = (int)floor(cell_size[j]/bonddistance); // take smaller value such that size of linked cell is at least bonddistance 2361 *out << Verbose(1) << "divisor[" << i << "] = " << divisor[i] << "." << endl;2364 //*out << Verbose(1) << "divisor[" << i << "] = " << divisor[i] << "." << endl; 2362 2365 } 2363 2366 // 2a. allocate memory for the cell list … … 2384 2387 } 2385 2388 index = n[2] + (n[1] + n[0] * divisor[1]) * divisor[2]; 2386 *out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl;2389 //*out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl; 2387 2390 // add copy atom to this cell 2388 2391 if (CellList[index] == NULL) // allocate molecule if not done … … 2426 2429 distance = OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size); 2427 2430 if ((OtherWalker->father->nr > Walker->father->nr) && (distance <= MaxDistance*MaxDistance) && (distance >= MinDistance*MinDistance)) { // create bond if distance is smaller 2428 *out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl;2431 //*out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl; 2429 2432 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount 2430 2433 BondCount++; … … 2485 2488 ListOfBondsPerAtom[Walker->nr][CandidateBondNo]->BondDegree++; 2486 2489 *out << Verbose(2) << "Increased bond degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl; 2487 } 2490 } else 2491 *out << Verbose(2) << "Could not find correct degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl; 2492 FalseBondDegree++; 2488 2493 } 2489 2494 } … … 2492 2497 } else 2493 2498 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 2494 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << " ." << endl;2499 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl; 2495 2500 2496 2501 // output bonds for debugging (if bond chain list was correctly installed) … … 2513 2518 * We use the algorithm from [Even, Graph Algorithms, p.62]. 2514 2519 * \param *out output stream for debugging 2515 * \param *& MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found2520 * \param *&BackEdgeStack NULL pointer to StackClass with all the found back edges, allocated and filled on return 2516 2521 * \return list of each disconnected subgraph as an individual molecule class structure 2517 2522 */ 2518 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize) 2519 { 2520 class StackClass<atom *> *AtomStack; 2521 AtomStack = new StackClass<atom *>(AtomCount); 2522 class StackClass<bond *> *BackEdgeStack = new StackClass<bond *> (BondCount); 2523 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack) 2524 { 2525 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 2526 BackEdgeStack = new StackClass<bond *> (BondCount); 2523 2527 MoleculeLeafClass *SubGraphs = new MoleculeLeafClass(NULL); 2524 2528 MoleculeLeafClass *LeafWalker = SubGraphs; … … 2652 2656 LeafWalker->Leaf->Output(out); 2653 2657 *out << endl; 2654 2658 2655 2659 // step on to next root 2656 2660 while ((Root != end) && (Root->GraphNr != -1)) { … … 2670 2674 } 2671 2675 2672 // analysis of the cycles (print rings, get minimum cycle length)2673 CyclicStructureAnalysis(out, BackEdgeStack, MinimumRingSize);2674 2676 2675 2677 *out << Verbose(1) << "Final graph info for each atom is:" << endl; … … 2709 2711 * as cyclic and print out the cycles. 2710 2712 * \param *out output stream for debugging 2711 * \param *BackEdgeStack stack with all back edges found during DFS scan 2713 * \param *BackEdgeStack stack with all back edges found during DFS scan. Beware: This stack contains the bonds from the total molecule, not from the subgraph! 2712 2714 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found, if set is maximum search distance 2713 2715 * \todo BFS from the not-same-LP to find back to starting point of tributary cycle over more than one bond … … 2730 2732 ColorList[i] = white; 2731 2733 } 2732 MinimumRingSize = new int[AtomCount];2733 for(int i=AtomCount;i--;)2734 MinimumRingSize[i] = AtomCount;2735 2736 2734 2737 2735 *out << Verbose(1) << "Back edge list - "; … … 3535 3533 MoleculeListClass *BondFragments = NULL; 3536 3534 int *SortIndex = NULL; 3537 int *MinimumRingSize = NULL;3535 int *MinimumRingSize = new int[AtomCount]; 3538 3536 int FragmentCounter; 3539 3537 MoleculeLeafClass *MolecularWalker = NULL; … … 3541 3539 fstream File; 3542 3540 bool FragmentationToDo = true; 3541 class StackClass<bond *> *BackEdgeStack = NULL, *LocalBackEdgeStack = NULL; 3543 3542 bool CheckOrder = false; 3544 3543 Graph **FragmentList = NULL; … … 3572 3571 3573 3572 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== 3574 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);3573 Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack); 3575 3574 // fill the bond structure of the individually stored subgraphs 3576 3575 Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 3577 3576 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 3577 for(int i=AtomCount;i--;) 3578 MinimumRingSize[i] = AtomCount; 3579 MolecularWalker = Subgraphs; 3580 FragmentCounter = 0; 3581 while (MolecularWalker->next != NULL) { 3582 MolecularWalker = MolecularWalker->next; 3583 *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl; 3584 LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount); 3585 // // check the list of local atoms for debugging 3586 // *out << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl; 3587 // for (int i=0;i<AtomCount;i++) 3588 // if (ListOfLocalAtoms[FragmentCounter][i] == NULL) 3589 // *out << "\tNULL"; 3590 // else 3591 // *out << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name; 3592 MolecularWalker->Leaf->PickLocalBackEdges(out, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack); 3593 MolecularWalker->Leaf->CyclicStructureAnalysis(out, LocalBackEdgeStack, MinimumRingSize); 3594 delete(LocalBackEdgeStack); 3595 } 3596 3578 3597 // ===== 3. if structure still valid, parse key set file and others ===== 3579 3598 FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList); … … 3584 3603 // =================================== Begin of FRAGMENTATION =============================== 3585 3604 // ===== 6a. assign each keyset to its respective subgraph ===== 3586 Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), false);3605 Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true); 3587 3606 3588 3607 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle … … 3621 3640 delete[](MinimumRingSize); 3622 3641 3623 // free the index lookup list3624 for (int i=FragmentCounter;i--;)3625 Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");3626 Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");3627 3642 3628 3643 // ==================================== End of FRAGMENTATION ============================================ … … 3698 3713 }; 3699 3714 3715 3716 /** Picks from a global stack with all back edges the ones in the fragment. 3717 * \param *out output stream for debugging 3718 * \param **ListOfLocalAtoms array of father atom::nr to local atom::nr (reverse of atom::father) 3719 * \param *ReferenceStack stack with all the back egdes 3720 * \param *LocalStack stack to be filled 3721 * \return true - everything ok, false - ReferenceStack was empty 3722 */ 3723 bool molecule::PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack) 3724 { 3725 bool status = true; 3726 if (ReferenceStack->IsEmpty()) { 3727 cerr << "ReferenceStack is empty!" << endl; 3728 return false; 3729 } 3730 bond *Binder = ReferenceStack->PopFirst(); 3731 bond *FirstBond = Binder; // mark the first bond, so that we don't loop through the stack indefinitely 3732 atom *Walker = NULL, *OtherAtom = NULL; 3733 ReferenceStack->Push(Binder); 3734 3735 do { // go through all bonds and push local ones 3736 Walker = ListOfLocalAtoms[Binder->leftatom->nr]; // get one atom in the reference molecule 3737 if (Walker == NULL) // if this Walker exists in the subgraph ... 3738 continue; 3739 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through the local list of bonds 3740 OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker); 3741 if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond 3742 LocalStack->Push(ListOfBondsPerAtom[Walker->nr][i]); 3743 break; 3744 } 3745 } 3746 Binder = ReferenceStack->PopFirst(); // loop the stack for next item 3747 ReferenceStack->Push(Binder); 3748 } while (FirstBond != Binder); 3749 3750 return status; 3751 }; 3752 3700 3753 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 3701 3754 * Atoms not present in the file get "-1". … … 3840 3893 while (Walker->next != end) { 3841 3894 Walker = Walker->next; 3842 *out << Verbose(4) << "Atom " << Walker->Name << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: ";3895 *out << Verbose(4) << "Atom " << Walker->Name << "/" << Walker->nr << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: "; 3843 3896 TotalDegree = 0; 3844 3897 for (int j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) {
Note:
See TracChangeset
for help on using the changeset viewer.
