Changeset 872b51 for molecuilder/src/molecule_graph.cpp
- Timestamp:
- Oct 18, 2009, 2:51:38 PM (16 years ago)
- Children:
- 77894f
- Parents:
- b0ee98
- git-author:
- Frederik Heber <heber@…> (10/18/09 14:15:37)
- git-committer:
- Frederik Heber <heber@…> (10/18/09 14:51:38)
- File:
-
- 1 edited
-
molecuilder/src/molecule_graph.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecule_graph.cpp
rb0ee98 r872b51 48 48 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices. 49 49 } 50 51 CreateListOfBondsPerAtom(out);52 50 }; 53 51 … … 64 62 * -# put each atom into its corresponding cell 65 63 * -# go through every cell, check the atoms therein against all possible bond partners in the 27 adjacent cells, add bond if true 66 * -# create the list of bonds via CreateListOfBondsPerAtom()67 64 * -# correct the bond degree iteratively (single->double->triple bond) 68 65 * -# finally print the bond list to \a *out if desired … … 148 145 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl; 149 146 150 // create the adjacency list per atom151 CreateListOfBondsPerAtom(out);152 153 147 // correct bond degree by comparing valence and bond degree 154 148 CorrectBondDegree(out); 155 149 156 150 // output bonds for debugging (if bond chain list was correctly installed) 157 OutputBondsList(out);151 ActOnAllAtoms( &atom::OutputBondOfAtom, out ); 158 152 } else 159 153 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; … … 173 167 } 174 168 *out << endl; 175 };176 177 /** Sums up the number of bonds times bond::BondDegree the atom with index \a nr has.178 * \param nr indexof atom179 * \return number of bonds each weighted with its bond::BondDegree180 */181 int molecule::CountAtomsBonds(int nr)182 {183 int NoBonds = 0;184 for(int j=0;j<NumberOfBondsPerAtom[nr];j++)185 NoBonds += ListOfBondsPerAtom[nr][j]->BondDegree;186 return NoBonds;187 169 }; 188 170 … … 198 180 { 199 181 int No = 0; 200 int NoBonds = 0;201 int CandidateBondNo = 0;202 int FalseBondDegree = 0;203 atom *Walker = NULL;204 atom *Candidate = NULL;205 atom *OtherWalker = NULL;206 182 207 183 if (BondCount != 0) { 208 NoCyclicBonds = 0; 209 *out << Verbose(1) << "Correcting Bond degree of each bond ... "; 184 *out << Verbose(1) << "Correcting Bond degree of each bond ... " << endl; 210 185 do { 211 No = 0; // No acts as breakup flag (if 1 we still continue) 212 Walker = start; 213 while (Walker->next != end) { // go through every atom 214 Walker = Walker->next; 215 216 NoBonds = CountAtomsBonds(Walker->nr); 217 *out << Verbose(3) << "Walker " << *Walker << ": " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 218 if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch 219 Candidate = NULL; 220 CandidateBondNo = -1; 221 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through each of its bond partners 222 OtherWalker = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker); 223 NoBonds = CountAtomsBonds(OtherWalker->nr); 224 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 225 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate 226 if ((Candidate == NULL) || (NumberOfBondsPerAtom[Candidate->nr] > NumberOfBondsPerAtom[OtherWalker->nr])) { // pick the one with fewer number of bonds first 227 Candidate = OtherWalker; 228 CandidateBondNo = i; 229 *out << Verbose(3) << "New candidate is " << *Candidate << "." << endl; 230 } 231 } 232 } 233 if ((Candidate != NULL) && (CandidateBondNo != -1)) { 234 ListOfBondsPerAtom[Walker->nr][CandidateBondNo]->BondDegree++; 235 *out << Verbose(2) << "Increased bond degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl; 236 } else { 237 *out << Verbose(2) << "Could not find correct degree for atom " << *Walker << "." << endl; 238 FalseBondDegree++; 239 } 240 } 241 } 186 No = SumPerAtom( &atom::CorrectBondDegree, out ); 242 187 } while (No); 243 188 *out << " done." << endl; … … 245 190 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 246 191 } 247 *out << FalseBondDegree<< " bonds could not be corrected." << endl;248 249 return ( FalseBondDegree);192 *out << No << " bonds could not be corrected." << endl; 193 194 return (No); 250 195 }; 251 196 … … 257 202 int molecule::CountCyclicBonds(ofstream *out) 258 203 { 259 int No= 0;204 NoCyclicBonds = 0; 260 205 int *MinimumRingSize = NULL; 261 206 MoleculeLeafClass *Subgraphs = NULL; … … 275 220 Binder = Binder->next; 276 221 if (Binder->Cyclic) 277 No ++;222 NoCyclicBonds++; 278 223 } 279 224 delete(BackEdgeStack); 280 return No ;225 return NoCyclicBonds; 281 226 }; 282 227 … … 459 404 } 460 405 // set cyclic bond criterium on "same LP" basis 461 Binder = first; 406 CyclicBondAnalysis(); 407 408 OutputGraphInfoPerAtom(out); 409 410 OutputGraphInfoPerBond(out); 411 412 // free all and exit 413 delete(AtomStack); 414 *out << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl; 415 return SubGraphs; 416 }; 417 418 /** Scans through all bonds and set bond::Cyclic to true where atom::LowpointNr of both ends is equal: LP criterion. 419 */ 420 void molecule::CyclicBondAnalysis() 421 { 422 NoCyclicBonds = 0; 423 bond *Binder = first; 462 424 while(Binder->next != last) { 463 425 Binder = Binder->next; … … 467 429 } 468 430 } 469 470 431 }; 432 433 /** Output graph information per atom. 434 * \param *out output stream 435 */ 436 void molecule::OutputGraphInfoPerAtom(ofstream *out) 437 { 471 438 *out << Verbose(1) << "Final graph info for each atom is:" << endl; 472 Walker = start;473 while (Walker->next != end) { 474 Walker = Walker->next; 475 *out << Verbose(2) << "Atom " << Walker->Name << " is " << ((Walker->SeparationVertex) ? "a" : "not a") << " separation vertex, components are "; 476 OutputComponentNumber(out, Walker);477 *out << " with Lowpoint " << Walker->LowpointNr << " and Graph Nr. " << Walker->GraphNr << "." << endl;478 } 479 439 ActOnAllAtoms( &atom::OutputGraphInfo, out ); 440 }; 441 442 /** Output graph information per bond. 443 * \param *out output stream 444 */ 445 void molecule::OutputGraphInfoPerBond(ofstream *out) 446 { 480 447 *out << Verbose(1) << "Final graph info for each bond is:" << endl; 481 Binder = first;448 bond *Binder = first; 482 449 while(Binder->next != last) { 483 450 Binder = Binder->next; 484 451 *out << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <"; 485 452 *out << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp."; 486 OutputComponentNumber(out, Binder->leftatom);453 Binder->leftatom->OutputComponentNumber(out); 487 454 *out << " === "; 488 455 *out << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp."; 489 OutputComponentNumber(out, Binder->rightatom);456 Binder->rightatom->OutputComponentNumber(out); 490 457 *out << ">." << endl; 491 458 if (Binder->Cyclic) // cyclic ?? 492 459 *out << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl; 493 460 } 494 495 // free all and exit496 delete(AtomStack);497 *out << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl;498 return SubGraphs;499 461 }; 500 462 … … 547 509 Walker = BFSStack->PopFirst(); 548 510 *out << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *Root << "." << endl; 549 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { 550 Binder = ListOfBondsPerAtom[Walker->nr][i]; 551 if (Binder != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder) 552 OtherAtom = Binder->GetOtherAtom(Walker); 511 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 512 if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder) 513 OtherAtom = (*Runner)->GetOtherAtom(Walker); 553 514 #ifdef ADDHYDROGEN 554 515 if (OtherAtom->type->Z != 1) { … … 662 623 Walker = BFSStack->PopFirst(); 663 624 //*out << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *Root << "." << endl; 664 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { 665 Binder = ListOfBondsPerAtom[Walker->nr][i]; 666 if ((Binder != BackEdge) || (NumberOfBondsPerAtom[Walker->nr] == 1)) { // only walk along DFS spanning tree (otherwise we always find SP of 1 being backedge Binder), but terminal hydrogens may be connected via backedge, hence extra check 667 OtherAtom = Binder->GetOtherAtom(Walker); 625 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 626 if (((*Runner) != BackEdge) || (Walker->ListOfBonds.size() == 1)) { // only walk along DFS spanning tree (otherwise we always find SP of 1 being backedge Binder), but terminal hydrogens may be connected via backedge, hence extra check 627 OtherAtom = (*Runner)->GetOtherAtom(Walker); 668 628 //*out << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl; 669 629 if (ColorList[OtherAtom->nr] == white) { … … 717 677 void molecule::SetNextComponentNumber(atom *vertex, int nr) 718 678 { 719 int i=0;679 size_t i=0; 720 680 if (vertex != NULL) { 721 for(;i< NumberOfBondsPerAtom[vertex->nr];i++) {681 for(;i<vertex->ListOfBonds.size();i++) { 722 682 if (vertex->ComponentNr[i] == -1) { // check if not yet used 723 683 vertex->ComponentNr[i] = nr; … … 727 687 break; // breaking here will not cause error! 728 688 } 729 if (i == NumberOfBondsPerAtom[vertex->nr])689 if (i == vertex->ListOfBonds.size()) 730 690 cerr << "Error: All Component entries are already occupied!" << endl; 731 691 } else 732 692 cerr << "Error: Given vertex is NULL!" << endl; 733 };734 735 /** Output a list of flags, stating whether the bond was visited or not.736 * \param *out output stream for debugging737 */738 void molecule::OutputComponentNumber(ofstream *out, atom *vertex)739 {740 for(int i=0;i<NumberOfBondsPerAtom[vertex->nr];i++)741 *out << vertex->ComponentNr[i] << " ";742 693 }; 743 694 … … 751 702 if (Walker->ComponentNr != NULL) 752 703 Free(&Walker->ComponentNr); 753 Walker->ComponentNr = Malloc<int>( NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");754 for (int i= NumberOfBondsPerAtom[Walker->nr];i--;)704 Walker->ComponentNr = Malloc<int>(Walker->ListOfBonds.size()+1, "molecule::InitComponentNumbers: *Walker->ComponentNr"); 705 for (int i=Walker->ListOfBonds.size()+1;i--;) 755 706 Walker->ComponentNr[i] = -1; 756 707 } … … 763 714 bond * molecule::FindNextUnused(atom *vertex) 764 715 { 765 for (int i=0;i<NumberOfBondsPerAtom[vertex->nr];i++)766 if ( ListOfBondsPerAtom[vertex->nr][i]->IsUsed() == white)767 return( ListOfBondsPerAtom[vertex->nr][i]);716 for (BondList::const_iterator Runner = vertex->ListOfBonds.begin(); Runner != vertex->ListOfBonds.end(); (++Runner)) 717 if ((*Runner)->IsUsed() == white) 718 return((*Runner)); 768 719 return NULL; 769 720 }; … … 813 764 { 814 765 ofstream AdjacencyFile; 815 atom *Walker = NULL;816 766 stringstream line; 817 767 bool status = true; … … 821 771 *out << Verbose(1) << "Saving adjacency list ... "; 822 772 if (AdjacencyFile != NULL) { 823 Walker = start; 824 while(Walker->next != end) { 825 Walker = Walker->next; 826 AdjacencyFile << Walker->nr << "\t"; 827 for (int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) 828 AdjacencyFile << ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker)->nr << "\t"; 829 AdjacencyFile << endl; 830 } 773 ActOnAllAtoms( &atom::OutputAdjacency, &AdjacencyFile ); 831 774 AdjacencyFile.close(); 832 775 *out << Verbose(1) << "done." << endl; … … 850 793 stringstream filename; 851 794 bool status = true; 795 atom *Walker = NULL; 852 796 char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 853 797 … … 859 803 int NonMatchNumber = 0; // will number of atoms with differing bond structure 860 804 int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 861 int CurrentBondsOfAtom;805 size_t CurrentBondsOfAtom; 862 806 863 807 // Parse the file line by line and count the bonds … … 871 815 // parse into structure 872 816 if ((AtomNr >= 0) && (AtomNr < AtomCount)) { 817 Walker = ListOfAtoms[AtomNr]; 873 818 while (!line.eof()) 874 819 line >> CurrentBonds[ ++CurrentBondsOfAtom ]; 875 820 // compare against present bonds 876 821 //cout << Verbose(2) << "Walker is " << *Walker << ", bond partners: "; 877 if (CurrentBondsOfAtom == NumberOfBondsPerAtom[AtomNr]) {878 for (int i=0;i<NumberOfBondsPerAtom[AtomNr];i++) {879 int id = ListOfBondsPerAtom[AtomNr][i]->GetOtherAtom(ListOfAtoms[AtomNr])->nr;880 int j = 0;822 if (CurrentBondsOfAtom == Walker->ListOfBonds.size()) { 823 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 824 int id = (*Runner)->GetOtherAtom(Walker)->nr; 825 size_t j = 0; 881 826 for (;(j<CurrentBondsOfAtom) && (CurrentBonds[j++] != id);); // check against all parsed bonds 882 827 if (CurrentBonds[j-1] != id) { // no match ? Then mark in ListOfAtoms … … 891 836 //out << endl; 892 837 } else { 893 *out << "Number of bonds for Atom " << * ListOfAtoms[AtomNr] << " does not match, parsed " << CurrentBondsOfAtom << " against " << NumberOfBondsPerAtom[AtomNr]<< "." << endl;838 *out << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl; 894 839 status = false; 895 840 } … … 937 882 Walker = ListOfLocalAtoms[Binder->leftatom->nr]; // get one atom in the reference molecule 938 883 if (Walker != NULL) // if this Walker exists in the subgraph ... 939 for (int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through the local list of bonds940 OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);941 if (OtherAtom == ListOfLocalAtoms[ Binder->rightatom->nr]) { // found the bond942 LocalStack->Push( ListOfBondsPerAtom[Walker->nr][i]);943 *out << Verbose(3) << "Found local edge " << *( ListOfBondsPerAtom[Walker->nr][i]) << "." << endl;884 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 885 OtherAtom = (*Runner)->GetOtherAtom(Walker); 886 if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->nr]) { // found the bond 887 LocalStack->Push((*Runner)); 888 *out << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl; 944 889 break; 945 890 } … … 973 918 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 974 919 atom *Walker = NULL, *OtherAtom = NULL; 975 bond *Binder = NULL;976 920 977 921 // add Root if not done yet … … 999 943 // followed by n+1 till top of stack. 1000 944 Walker = AtomStack->PopFirst(); // pop oldest added 1001 *out << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << NumberOfBondsPerAtom[Walker->nr] << " bonds." << endl; 1002 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { 1003 Binder = ListOfBondsPerAtom[Walker->nr][i]; 1004 if (Binder != NULL) { // don't look at bond equal NULL 1005 OtherAtom = Binder->GetOtherAtom(Walker); 1006 *out << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl; 945 *out << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl; 946 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 947 if ((*Runner) != NULL) { // don't look at bond equal NULL 948 OtherAtom = (*Runner)->GetOtherAtom(Walker); 949 *out << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl; 1007 950 if (ColorList[OtherAtom->nr] == white) { 1008 if ( Binder!= Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem)951 if ((*Runner) != Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem) 1009 952 ColorList[OtherAtom->nr] = lightgray; 1010 953 PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor 1011 954 ShortestPathList[OtherAtom->nr] = ShortestPathList[Walker->nr]+1; 1012 955 *out << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 1013 if ((((ShortestPathList[OtherAtom->nr] < BondOrder) && ( Binder!= Bond))) ) { // Check for maximum distance956 if ((((ShortestPathList[OtherAtom->nr] < BondOrder) && ((*Runner) != Bond))) ) { // Check for maximum distance 1014 957 *out << Verbose(3); 1015 958 if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far 1016 959 AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom); 1017 960 *out << "Added OtherAtom " << OtherAtom->Name; 1018 AddedBondList[Binder->nr] = Mol->AddBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder->BondDegree); 1019 AddedBondList[Binder->nr]->Cyclic = Binder->Cyclic; 1020 AddedBondList[Binder->nr]->Type = Binder->Type; 1021 *out << " and bond " << *(AddedBondList[Binder->nr]) << ", "; 961 AddedBondList[(*Runner)->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], (*Runner)); 962 *out << " and bond " << *(AddedBondList[(*Runner)->nr]) << ", "; 1022 963 } else { // this code should actually never come into play (all white atoms are not yet present in BondMolecule, that's why they are white in the first place) 1023 964 *out << "Not adding OtherAtom " << OtherAtom->Name; 1024 if (AddedBondList[Binder->nr] == NULL) { 1025 AddedBondList[Binder->nr] = Mol->AddBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder->BondDegree); 1026 AddedBondList[Binder->nr]->Cyclic = Binder->Cyclic; 1027 AddedBondList[Binder->nr]->Type = Binder->Type; 1028 *out << ", added Bond " << *(AddedBondList[Binder->nr]); 965 if (AddedBondList[(*Runner)->nr] == NULL) { 966 AddedBondList[(*Runner)->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], (*Runner)); 967 *out << ", added Bond " << *(AddedBondList[(*Runner)->nr]); 1029 968 } else 1030 969 *out << ", not added Bond "; … … 1033 972 AtomStack->Push(OtherAtom); 1034 973 } else { // out of bond order, then replace 1035 if ((AddedAtomList[OtherAtom->nr] == NULL) && ( Binder->Cyclic))974 if ((AddedAtomList[OtherAtom->nr] == NULL) && ((*Runner)->Cyclic)) 1036 975 ColorList[OtherAtom->nr] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic) 1037 if ( Binder== Bond)976 if ((*Runner) == Bond) 1038 977 *out << Verbose(3) << "Not Queueing, is the Root bond"; 1039 978 else if (ShortestPathList[OtherAtom->nr] >= BondOrder) 1040 979 *out << Verbose(3) << "Not Queueing, is out of Bond Count of " << BondOrder; 1041 if (! Binder->Cyclic)980 if (!(*Runner)->Cyclic) 1042 981 *out << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl; 1043 if (AddedBondList[ Binder->nr] == NULL) {982 if (AddedBondList[(*Runner)->nr] == NULL) { 1044 983 if ((AddedAtomList[OtherAtom->nr] != NULL)) { // .. whether we add or saturate 1045 AddedBondList[Binder->nr] = Mol->AddBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder->BondDegree); 1046 AddedBondList[Binder->nr]->Cyclic = Binder->Cyclic; 1047 AddedBondList[Binder->nr]->Type = Binder->Type; 984 AddedBondList[(*Runner)->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], (*Runner)); 1048 985 } else { 1049 986 #ifdef ADDHYDROGEN 1050 if (!Mol->AddHydrogenReplacementAtom(out, Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, ListOfBondsPerAtom[Walker->nr], NumberOfBondsPerAtom[Walker->nr], IsAngstroem))987 if (!Mol->AddHydrogenReplacementAtom(out, (*Runner), AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem)) 1051 988 exit(1); 1052 989 #endif … … 1057 994 *out << Verbose(3) << "Not Adding, has already been visited." << endl; 1058 995 // This has to be a cyclic bond, check whether it's present ... 1059 if (AddedBondList[Binder->nr] == NULL) { 1060 if ((Binder != Bond) && (Binder->Cyclic) && (((ShortestPathList[Walker->nr]+1) < BondOrder))) { 1061 AddedBondList[Binder->nr] = Mol->AddBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder->BondDegree); 1062 AddedBondList[Binder->nr]->Cyclic = Binder->Cyclic; 1063 AddedBondList[Binder->nr]->Type = Binder->Type; 996 if (AddedBondList[(*Runner)->nr] == NULL) { 997 if (((*Runner) != Bond) && ((*Runner)->Cyclic) && (((ShortestPathList[Walker->nr]+1) < BondOrder))) { 998 AddedBondList[(*Runner)->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], (*Runner)); 1064 999 } else { // if it's root bond it has to broken (otherwise we would not create the fragments) 1065 1000 #ifdef ADDHYDROGEN 1066 if(!Mol->AddHydrogenReplacementAtom(out, Binder, AddedAtomList[Walker->nr], Walker, OtherAtom, ListOfBondsPerAtom[Walker->nr], NumberOfBondsPerAtom[Walker->nr], IsAngstroem))1001 if(!Mol->AddHydrogenReplacementAtom(out, (*Runner), AddedAtomList[Walker->nr], Walker, OtherAtom, IsAngstroem)) 1067 1002 exit(1); 1068 1003 #endif … … 1080 1015 delete(AtomStack); 1081 1016 }; 1017 1018 /** Adds a bond as a copy to a given one 1019 * \param *left leftatom of new bond 1020 * \param *right rightatom of new bond 1021 * \param *CopyBond rest of fields in bond are copied from this 1022 * \return pointer to new bond 1023 */ 1024 bond * molecule::CopyBond(atom *left, atom *right, bond *CopyBond) 1025 { 1026 bond *Binder = AddBond(left, right, CopyBond->BondDegree); 1027 Binder->Cyclic = CopyBond->Cyclic; 1028 Binder->Type = CopyBond->Type; 1029 return Binder; 1030 }; 1031 1082 1032 1083 1033 /** Adds bond structure to this molecule from \a Father molecule. … … 1122 1072 status = false; 1123 1073 } else { 1124 for ( int i=0;i<Father->NumberOfBondsPerAtom[Walker->nr];i++) {1125 OtherAtom = Father->ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);1074 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1075 OtherAtom = (*Runner)->GetOtherAtom(Walker); 1126 1076 if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond 1127 *out << Verbose(4) << "Endpoints of Bond " << Father->ListOfBondsPerAtom[Walker->nr][i]<< " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl;1128 AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], Father->ListOfBondsPerAtom[Walker->nr][i]->BondDegree);1077 *out << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl; 1078 AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree); 1129 1079 } 1130 1080 } … … 1164 1114 for(KeySet::iterator runners = Fragment->begin(); runners != Fragment->end(); runners++) { 1165 1115 Walker2 = FindAtom(*runners); 1166 for ( int i=0;i<NumberOfBondsPerAtom[Walker->nr]; i++) {1167 if ( ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker) == Walker2) {1116 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1117 if ((*Runner)->GetOtherAtom(Walker) == Walker2) { 1168 1118 BondStatus = true; 1169 1119 break;
Note:
See TracChangeset
for help on using the changeset viewer.
