Ignore:
Timestamp:
Oct 18, 2009, 2:51:38 PM (16 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Huge refactoring: molecule::ListOfBondsPerAtom and molecule::NumberOfBondsPerAtom removed, atom::ListOfBonds introduced. Unit Test for ListOfBonds manipulation introduced.

  • changes to builder.cpp: removed CreateListOfBondsPerAtom() calls, as the creation of the global arrays is not necessary anymore
  • changes to LinkedCell: LinkedCell::CheckBounds(int[NDIM]) does not admonish out of bonds as this is not desired for the local offset which may become out of bounds.
  • changes to lists.hpp templates: BUGFIX: unlink() now sets ->next and ->previous to NULL, cleanup() uses removedwithoutcheck()
  • new templates for molecule.hpp: SumPerAtom() allows for summation of the return value of atom:...() member fiunctions. This is needed e.g. for atom::CorrectBondDegree()

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecule_graph.cpp

    rb0ee98 r872b51  
    4848    AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
    4949  }
    50 
    51   CreateListOfBondsPerAtom(out);
    5250};
    5351
     
    6462 *  -# put each atom into its corresponding cell
    6563 *  -# 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()
    6764 *  -# correct the bond degree iteratively (single->double->triple bond)
    6865 *  -# finally print the bond list to \a *out if desired
     
    148145    *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl;
    149146
    150     // create the adjacency list per atom
    151     CreateListOfBondsPerAtom(out);
    152 
    153147    // correct bond degree by comparing valence and bond degree
    154148    CorrectBondDegree(out);
    155149
    156150    // output bonds for debugging (if bond chain list was correctly installed)
    157     OutputBondsList(out);
     151    ActOnAllAtoms( &atom::OutputBondOfAtom, out );
    158152  } else
    159153    *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
     
    173167  }
    174168  *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 atom
    179  * \return number of bonds each weighted with its bond::BondDegree
    180  */
    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;
    187169};
    188170
     
    198180{
    199181  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;
    206182
    207183  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;
    210185    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 );
    242187    } while (No);
    243188    *out << " done." << endl;
     
    245190    *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    246191  }
    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);
    250195};
    251196
     
    257202int molecule::CountCyclicBonds(ofstream *out)
    258203{
    259   int No = 0;
     204  NoCyclicBonds = 0;
    260205  int *MinimumRingSize = NULL;
    261206  MoleculeLeafClass *Subgraphs = NULL;
     
    275220    Binder = Binder->next;
    276221    if (Binder->Cyclic)
    277       No++;
     222      NoCyclicBonds++;
    278223  }
    279224  delete(BackEdgeStack);
    280   return No;
     225  return NoCyclicBonds;
    281226};
    282227
     
    459404  }
    460405  // 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 */
     420void molecule::CyclicBondAnalysis()
     421{
     422  NoCyclicBonds = 0;
     423  bond *Binder = first;
    462424  while(Binder->next != last) {
    463425    Binder = Binder->next;
     
    467429    }
    468430  }
    469 
    470 
     431};
     432
     433/** Output graph information per atom.
     434 * \param *out output stream
     435 */
     436void molecule::OutputGraphInfoPerAtom(ofstream *out)
     437{
    471438  *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 */
     445void molecule::OutputGraphInfoPerBond(ofstream *out)
     446{
    480447  *out << Verbose(1) << "Final graph info for each bond is:" << endl;
    481   Binder = first;
     448  bond *Binder = first;
    482449  while(Binder->next != last) {
    483450    Binder = Binder->next;
    484451    *out << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";
    485452    *out << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";
    486     OutputComponentNumber(out, Binder->leftatom);
     453    Binder->leftatom->OutputComponentNumber(out);
    487454    *out << " ===  ";
    488455    *out << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
    489     OutputComponentNumber(out, Binder->rightatom);
     456    Binder->rightatom->OutputComponentNumber(out);
    490457    *out << ">." << endl;
    491458    if (Binder->Cyclic) // cyclic ??
    492459      *out << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl;
    493460  }
    494 
    495   // free all and exit
    496   delete(AtomStack);
    497   *out << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl;
    498   return SubGraphs;
    499461};
    500462
     
    547509      Walker = BFSStack->PopFirst();
    548510      *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);
    553514#ifdef ADDHYDROGEN
    554515          if (OtherAtom->type->Z != 1) {
     
    662623          Walker = BFSStack->PopFirst();
    663624          //*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);
    668628              //*out << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl;
    669629              if (ColorList[OtherAtom->nr] == white) {
     
    717677void molecule::SetNextComponentNumber(atom *vertex, int nr)
    718678{
    719   int i=0;
     679  size_t i=0;
    720680  if (vertex != NULL) {
    721     for(;i<NumberOfBondsPerAtom[vertex->nr];i++) {
     681    for(;i<vertex->ListOfBonds.size();i++) {
    722682      if (vertex->ComponentNr[i] == -1) {   // check if not yet used
    723683        vertex->ComponentNr[i] = nr;
     
    727687        break;  // breaking here will not cause error!
    728688    }
    729     if (i == NumberOfBondsPerAtom[vertex->nr])
     689    if (i == vertex->ListOfBonds.size())
    730690      cerr << "Error: All Component entries are already occupied!" << endl;
    731691  } else
    732692      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 debugging
    737  */
    738 void molecule::OutputComponentNumber(ofstream *out, atom *vertex)
    739 {
    740   for(int i=0;i<NumberOfBondsPerAtom[vertex->nr];i++)
    741     *out << vertex->ComponentNr[i] << "  ";
    742693};
    743694
     
    751702    if (Walker->ComponentNr != NULL)
    752703      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--;)
    755706      Walker->ComponentNr[i] = -1;
    756707  }
     
    763714bond * molecule::FindNextUnused(atom *vertex)
    764715{
    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));
    768719  return NULL;
    769720};
     
    813764{
    814765  ofstream AdjacencyFile;
    815   atom *Walker = NULL;
    816766  stringstream line;
    817767  bool status = true;
     
    821771  *out << Verbose(1) << "Saving adjacency list ... ";
    822772  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 );
    831774    AdjacencyFile.close();
    832775    *out << Verbose(1) << "done." << endl;
     
    850793  stringstream filename;
    851794  bool status = true;
     795  atom *Walker = NULL;
    852796  char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    853797
     
    859803    int NonMatchNumber = 0;   // will number of atoms with differing bond structure
    860804    int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    861     int CurrentBondsOfAtom;
     805    size_t CurrentBondsOfAtom;
    862806
    863807    // Parse the file line by line and count the bonds
     
    871815      // parse into structure
    872816      if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
     817        Walker = ListOfAtoms[AtomNr];
    873818        while (!line.eof())
    874819          line >> CurrentBonds[ ++CurrentBondsOfAtom ];
    875820        // compare against present bonds
    876821        //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;
    881826            for (;(j<CurrentBondsOfAtom) && (CurrentBonds[j++] != id);); // check against all parsed bonds
    882827            if (CurrentBonds[j-1] != id) { // no match ? Then mark in ListOfAtoms
     
    891836          //out << endl;
    892837        } 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;
    894839          status = false;
    895840        }
     
    937882    Walker = ListOfLocalAtoms[Binder->leftatom->nr];  // get one atom in the reference molecule
    938883    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 bonds
    940         OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);
    941         if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond
    942           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;
    944889          break;
    945890        }
     
    973918  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
    974919  atom *Walker = NULL, *OtherAtom = NULL;
    975   bond *Binder = NULL;
    976920
    977921  // add Root if not done yet
     
    999943    // followed by n+1 till top of stack.
    1000944    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;
    1007950        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)
    1009952            ColorList[OtherAtom->nr] = lightgray;
    1010953          PredecessorList[OtherAtom->nr] = Walker;  // Walker is the predecessor
    1011954          ShortestPathList[OtherAtom->nr] = ShortestPathList[Walker->nr]+1;
    1012955          *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 distance
     956          if ((((ShortestPathList[OtherAtom->nr] < BondOrder) && ((*Runner) != Bond))) ) { // Check for maximum distance
    1014957            *out << Verbose(3);
    1015958            if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far
    1016959              AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom);
    1017960              *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]) << ", ";
    1022963            } 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)
    1023964              *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]);
    1029968              } else
    1030969                *out << ", not added Bond ";
     
    1033972            AtomStack->Push(OtherAtom);
    1034973          } else { // out of bond order, then replace
    1035             if ((AddedAtomList[OtherAtom->nr] == NULL) && (Binder->Cyclic))
     974            if ((AddedAtomList[OtherAtom->nr] == NULL) && ((*Runner)->Cyclic))
    1036975              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)
    1038977              *out << Verbose(3) << "Not Queueing, is the Root bond";
    1039978            else if (ShortestPathList[OtherAtom->nr] >= BondOrder)
    1040979              *out << Verbose(3) << "Not Queueing, is out of Bond Count of " << BondOrder;
    1041             if (!Binder->Cyclic)
     980            if (!(*Runner)->Cyclic)
    1042981              *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) {
    1044983              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));
    1048985              } else {
    1049986#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))
    1051988                  exit(1);
    1052989#endif
     
    1057994          *out << Verbose(3) << "Not Adding, has already been visited." << endl;
    1058995          // 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));
    1064999            } else { // if it's root bond it has to broken (otherwise we would not create the fragments)
    10651000#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))
    10671002                exit(1);
    10681003#endif
     
    10801015  delete(AtomStack);
    10811016};
     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 */
     1024bond * 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
    10821032
    10831033/** Adds bond structure to this molecule from \a Father molecule.
     
    11221072        status = false;
    11231073      } 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);
    11261076          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);
    11291079          }
    11301080        }
     
    11641114      for(KeySet::iterator runners = Fragment->begin(); runners != Fragment->end(); runners++) {
    11651115        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) {
    11681118            BondStatus = true;
    11691119            break;
Note: See TracChangeset for help on using the changeset viewer.