Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_graph.cpp

    r112b09 r68f03d  
    55 *      Author: heber
    66 */
    7 
    8 #include "Helpers/MemDebug.hpp"
    97
    108#include "atom.hpp"
     
    1412#include "element.hpp"
    1513#include "helpers.hpp"
    16 #include "info.hpp"
    1714#include "linkedcell.hpp"
    1815#include "lists.hpp"
     
    2219#include "World.hpp"
    2320#include "Helpers/fast_functions.hpp"
    24 #include "Helpers/Assert.hpp"
    25 
    2621
    2722struct BFSAccounting
     
    5954void molecule::CreateAdjacencyListFromDbondFile(ifstream *input)
    6055{
    61   Info FunctionInfo(__func__);
     56
    6257  // 1 We will parse bonds out of the dbond file created by tremolo.
    6358  int atom1, atom2;
    6459  atom *Walker, *OtherWalker;
    65   char line[MAXSTRINGSIZE];
    66 
    67   if (input->fail()) {
    68     DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n");
    69     performCriticalExit();
     60
     61  if (!input) {
     62    DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n");
    7063  };
    71   doCountAtoms();
    72 
    73   // skip header
    74   input->getline(line,MAXSTRINGSIZE);
    75   DoLog(1) && (Log() << Verbose(1) << "Scanning file ... \n");
     64
     65  *input >> ws >> atom1;
     66  *input >> ws >> atom2;
     67  DoLog(1) && (Log() << Verbose(1) << "Scanning file\n");
    7668  while (!input->eof()) // Check whether we read everything already
    7769  {
    78     input->getline(line,MAXSTRINGSIZE);
    79     stringstream zeile(line);
    80     zeile >> atom1;
    81     zeile >> atom2;
    82 
    83     DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl);
     70    *input >> ws >> atom1;
     71    *input >> ws >> atom2;
     72
    8473    if (atom2 < atom1) //Sort indices of atoms in order
    8574      flip(atom1, atom2);
    8675    Walker = FindAtom(atom1);
    87     ASSERT(Walker,"Could not find an atom with the ID given in dbond file");
    8876    OtherWalker = FindAtom(atom2);
    89     ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file");
    9077    AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
    9178  }
     
    116103  atom *Walker = NULL;
    117104  atom *OtherWalker = NULL;
     105  atom **AtomMap = NULL;
    118106  int n[NDIM];
    119107  double MinDistance, MaxDistance;
     
    130118  DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl);
    131119  // remove every bond from the list
    132   for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    133     for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
    134       if ((*BondRunner)->leftatom == *AtomRunner)
    135         delete((*BondRunner));
     120  bond *Binder = NULL;
     121  while (last->previous != first) {
     122    Binder = last->previous;
     123    Binder->leftatom->UnregisterBond(Binder);
     124    Binder->rightatom->UnregisterBond(Binder);
     125    removewithoutcheck(Binder);
     126  }
    136127  BondCount = 0;
    137128
    138129  // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
    139   DoLog(1) && (Log() << Verbose(1) << "AtomCount " << getAtomCount() << " and bonddistance is " << bonddistance << "." << endl);
    140 
    141   if ((getAtomCount() > 1) && (bonddistance > 1.)) {
     130  CountAtoms();
     131  DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl);
     132
     133  if ((AtomCount > 1) && (bonddistance > 1.)) {
    142134    DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
    143135    LC = new LinkedCell(this, bonddistance);
     
    145137    // create a list to map Tesselpoint::nr to atom *
    146138    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    147 
    148     // set numbers for atoms that can later be used
    149     int i=0;
    150     for(internal_iterator iter = atoms.begin();iter!= atoms.end(); ++iter){
    151       (*iter)->nr = i++;
     139    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
     140    Walker = start;
     141    while (Walker->next != end) {
     142      Walker = Walker->next;
     143      AtomMap[Walker->nr] = Walker;
    152144    }
    153145
     
    161153          if (List != NULL) {
    162154            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    163               Walker = dynamic_cast<atom*>(*Runner);
    164               ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode");
    165               //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
     155              Walker = AtomMap[(*Runner)->nr];
     156//              Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
    166157              // 3c. check for possible bond between each atom in this and every one in the 27 cells
    167158              for (n[0] = -1; n[0] <= 1; n[0]++)
     
    173164                      for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
    174165                        if ((*OtherRunner)->nr > Walker->nr) {
    175                           OtherWalker = dynamic_cast<atom*>(*OtherRunner);
    176                           ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode");
    177                           //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
     166                          OtherWalker = AtomMap[(*OtherRunner)->nr];
     167//                          Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl;
     168                          const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size);
     169//                          Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    178170                          (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
    179                           const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x,cell_size);
    180171                          const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance);
    181172//                          Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl;
     
    197188          }
    198189        }
     190    Free(&AtomMap);
    199191    delete (LC);
    200192    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
     
    207199    ActOnAllAtoms( &atom::OutputBondOfAtom );
    208200  } else
    209     DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << getAtomCount() << ", thus no bonds, no connections!." << endl);
     201    DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);
    210202  DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
    211203  if (free_BG)
     
    214206;
    215207
    216 /** Checks for presence of bonds within atom list.
    217  * TODO: more sophisticated check for bond structure (e.g. connected subgraph, ...)
    218  * \return true - bonds present, false - no bonds
    219  */
    220 bool molecule::hasBondStructure()
    221 {
    222   for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    223     if (!(*AtomRunner)->ListOfBonds.empty())
    224       return true;
    225   return false;
    226 }
    227 
    228 /** Counts the number of present bonds.
    229  * \return number of bonds
    230  */
    231 unsigned int molecule::CountBonds() const
    232 {
    233   unsigned int counter = 0;
    234   for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    235     for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    236       if ((*BondRunner)->leftatom == *AtomRunner)
    237         counter++;
    238   return counter;
    239 }
    240 
    241208/** Prints a list of all bonds to \a *out.
    242209 * \param output stream
     
    245212{
    246213  DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:");
    247   for(molecule::const_iterator AtomRunner = molecule::begin(); AtomRunner != molecule::end(); ++AtomRunner)
    248     for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    249       if ((*BondRunner)->leftatom == *AtomRunner) {
    250         DoLog(0) && (Log() << Verbose(0) << *(*BondRunner) << "\t" << endl);
    251       }
     214  bond *Binder = first;
     215  while (Binder->next != last) {
     216    Binder = Binder->next;
     217    DoLog(0) && (Log() << Verbose(0) << *Binder << "\t" << endl);
     218  }
    252219  DoLog(0) && (Log() << Verbose(0) << endl);
    253220}
     
    274241    DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    275242  } else {
    276     DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << getAtomCount() << " atoms." << endl);
     243    DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl);
    277244  }
    278245  DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);
     
    293260  MoleculeLeafClass *Subgraphs = NULL;
    294261  class StackClass<bond *> *BackEdgeStack = NULL;
    295   for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    296     if ((!(*AtomRunner)->ListOfBonds.empty()) && ((*(*AtomRunner)->ListOfBonds.begin())->Type == Undetermined)) {
    297       DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);
    298       Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
    299       while (Subgraphs->next != NULL) {
    300         Subgraphs = Subgraphs->next;
    301         delete (Subgraphs->previous);
    302       }
    303       delete (Subgraphs);
    304       delete[] (MinimumRingSize);
    305       break;
    306     }
    307   for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    308     for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    309       if ((*BondRunner)->leftatom == *AtomRunner)
    310         if ((*BondRunner)->Cyclic)
    311           NoCyclicBonds++;
     262  bond *Binder = first;
     263  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
     264    DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);
     265    Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
     266    while (Subgraphs->next != NULL) {
     267      Subgraphs = Subgraphs->next;
     268      delete (Subgraphs->previous);
     269    }
     270    delete (Subgraphs);
     271    delete[] (MinimumRingSize);
     272  }
     273  while (Binder->next != last) {
     274    Binder = Binder->next;
     275    if (Binder->Cyclic)
     276      NoCyclicBonds++;
     277  }
    312278  delete (BackEdgeStack);
    313279  return NoCyclicBonds;
     
    495461void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol)
    496462{
    497   DFS.AtomStack = new StackClass<atom *> (mol->getAtomCount());
     463  DFS.AtomStack = new StackClass<atom *> (mol->AtomCount);
    498464  DFS.CurrentGraphNr = 0;
    499465  DFS.ComponentNumber = 0;
     
    536502  bond *Binder = NULL;
    537503
    538   if (getAtomCount() == 0)
     504  if (AtomCount == 0)
    539505    return SubGraphs;
    540506  DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl);
    541507  DepthFirstSearchAnalysis_Init(DFS, this);
    542508
    543   for (molecule::const_iterator iter = begin(); iter != end();) {
    544     DFS.Root = *iter;
     509  DFS.Root = start->next;
     510  while (DFS.Root != end) { // if there any atoms at all
    545511    // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
    546512    DFS.AtomStack->ClearStack();
     
    582548
    583549    // step on to next root
    584     while ((iter != end()) && ((*iter)->GraphNr != -1)) {
    585       //Log() << Verbose(1) << "Current next subgraph root candidate is " << (*iter)->Name << "." << endl;
    586       if ((*iter)->GraphNr != -1) // if already discovered, step on
    587         iter++;
     550    while ((DFS.Root != end) && (DFS.Root->GraphNr != -1)) {
     551      //Log() << Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl;
     552      if (DFS.Root->GraphNr != -1) // if already discovered, step on
     553        DFS.Root = DFS.Root->next;
    588554    }
    589555  }
     
    607573{
    608574  NoCyclicBonds = 0;
    609   for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    610     for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    611       if ((*BondRunner)->leftatom == *AtomRunner)
    612         if ((*BondRunner)->rightatom->LowpointNr == (*BondRunner)->leftatom->LowpointNr) { // cyclic ??
    613           (*BondRunner)->Cyclic = true;
    614           NoCyclicBonds++;
    615         }
     575  bond *Binder = first;
     576  while (Binder->next != last) {
     577    Binder = Binder->next;
     578    if (Binder->rightatom->LowpointNr == Binder->leftatom->LowpointNr) { // cyclic ??
     579      Binder->Cyclic = true;
     580      NoCyclicBonds++;
     581    }
     582  }
    616583}
    617584;
     
    632599void molecule::OutputGraphInfoPerBond() const
    633600{
    634   bond *Binder = NULL;
    635601  DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl);
    636   for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    637     for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    638       if ((*BondRunner)->leftatom == *AtomRunner) {
    639         Binder = *BondRunner;
    640         DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <");
    641         DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.");
    642         Binder->leftatom->OutputComponentNumber();
    643         DoLog(0) && (Log() << Verbose(0) << " ===  ");
    644         DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.");
    645         Binder->rightatom->OutputComponentNumber();
    646         DoLog(0) && (Log() << Verbose(0) << ">." << endl);
    647         if (Binder->Cyclic) // cyclic ??
    648           DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);
    649       }
     602  bond *Binder = first;
     603  while (Binder->next != last) {
     604    Binder = Binder->next;
     605    DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <");
     606    DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.");
     607    Binder->leftatom->OutputComponentNumber();
     608    DoLog(0) && (Log() << Verbose(0) << " ===  ");
     609    DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.");
     610    Binder->rightatom->OutputComponentNumber();
     611    DoLog(0) && (Log() << Verbose(0) << ">." << endl);
     612    if (Binder->Cyclic) // cyclic ??
     613      DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);
     614  }
    650615}
    651616;
     
    659624{
    660625  BFS.AtomCount = AtomCount;
    661   BFS.PredecessorList = new atom*[AtomCount];
    662   BFS.ShortestPathList = new int[AtomCount];
    663   BFS.ColorList = new enum Shading[AtomCount];
     626  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     627  BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
     628  BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    664629  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    665630
    666   for (int i = AtomCount; i--;) {
     631  for (int i = AtomCount; i--;)
    667632    BFS.ShortestPathList[i] = -1;
    668     BFS.PredecessorList[i] = 0;
    669   }
    670633};
    671634
     
    676639void FinalizeBFSAccounting(struct BFSAccounting &BFS)
    677640{
    678   delete[](BFS.PredecessorList);
    679   delete[](BFS.ShortestPathList);
    680   delete[](BFS.ColorList);
     641  Free(&BFS.PredecessorList);
     642  Free(&BFS.ShortestPathList);
     643  Free(&BFS.ColorList);
    681644  delete (BFS.BFSStack);
    682645  BFS.AtomCount = 0;
     
    891854  if (MinRingSize != -1) { // if rings are present
    892855    // go over all atoms
    893     for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    894       Root = *iter;
    895 
    896       if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->getAtomCount()) { // check whether MinimumRingSize is set, if not BFS to next where it is
     856    Root = mol->start;
     857    while (Root->next != mol->end) {
     858      Root = Root->next;
     859
     860      if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->AtomCount) { // check whether MinimumRingSize is set, if not BFS to next where it is
    897861        Walker = Root;
    898862
    899863        //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;
    900         CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->getAtomCount());
     864        CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->AtomCount);
    901865
    902866      }
     
    928892  int MinRingSize = -1;
    929893
    930   InitializeBFSAccounting(BFS, getAtomCount());
     894  InitializeBFSAccounting(BFS, AtomCount);
    931895
    932896  //Log() << Verbose(1) << "Back edge list - ";
     
    1002966void molecule::ResetAllBondsToUnused() const
    1003967{
    1004   for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    1005     for(BondList::const_iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    1006       if ((*BondRunner)->leftatom == *AtomRunner)
    1007         (*BondRunner)->ResetUsed();
     968  bond *Binder = first;
     969  while (Binder->next != last) {
     970    Binder = Binder->next;
     971    Binder->ResetUsed();
     972  }
    1008973}
    1009974;
     
    10391004    line << filename;
    10401005  AdjacencyFile.open(line.str().c_str(), ios::out);
    1041   DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl);
     1006  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
    10421007  if (AdjacencyFile != NULL) {
    10431008    AdjacencyFile << "m\tn" << endl;
    10441009    ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile);
    10451010    AdjacencyFile.close();
    1046     DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl);
     1011    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    10471012  } else {
    1048     DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line.str() << "." << endl);
     1013    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    10491014    status = false;
    10501015  }
     
    10711036    line << filename;
    10721037  BondFile.open(line.str().c_str(), ios::out);
    1073   DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl);
     1038  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
    10741039  if (BondFile != NULL) {
    10751040    BondFile << "m\tn" << endl;
    10761041    ActOnAllAtoms(&atom::OutputBonds, &BondFile);
    10771042    BondFile.close();
    1078     DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl);
     1043    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    10791044  } else {
    1080     DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line.str() << "." << endl);
     1045    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    10811046    status = false;
    10821047  }
     
    10911056  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    10921057  File.open(filename.str().c_str(), ios::out);
    1093   DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl);
     1058  DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ");
    10941059  if (File == NULL)
    10951060    return false;
    10961061
    10971062  // allocate storage structure
    1098   CurrentBonds = new int[8]; // contains parsed bonds of current atom
    1099   for(int i=0;i<8;i++)
    1100     CurrentBonds[i] = 0;
     1063  CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    11011064  return true;
    11021065}
     
    11071070  File.close();
    11081071  File.clear();
    1109   delete[](CurrentBonds);
     1072  Free(&CurrentBonds);
    11101073}
    11111074;
     
    11271090        NonMatchNumber++;
    11281091        status = false;
    1129         DoeLog(2) && (eLog() << Verbose(2) << id << " can not be found in list." << endl);
     1092        //Log() << Verbose(0) << "[" << id << "]\t";
    11301093      } else {
    1131         //Log() << Verbose(0) << "[" << id << "]\t";
     1094        //Log() << Verbose(0) << id << "\t";
    11321095      }
    11331096    }
     
    11511114  bool status = true;
    11521115  atom *Walker = NULL;
     1116  char *buffer = NULL;
    11531117  int *CurrentBonds = NULL;
    11541118  int NonMatchNumber = 0; // will number of atoms with differing bond structure
    11551119  size_t CurrentBondsOfAtom = -1;
    1156   const int AtomCount = getAtomCount();
    11571120
    11581121  if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) {
     
    11611124  }
    11621125
    1163   char buffer[MAXSTRINGSIZE];
     1126  buffer = Malloc<char> (MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    11641127  // Parse the file line by line and count the bonds
    11651128  while (!File.eof()) {
     
    11771140      // compare against present bonds
    11781141      CheckAdjacencyFileAgainstMolecule_CompareBonds(status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms);
    1179     } else {
    1180       if (AtomNr != -1)
    1181         DoeLog(2) && (eLog() << Verbose(2) << AtomNr << " is not valid in the range of ids [" << 0 << "," << AtomCount << ")." << endl);
    1182     }
    1183   }
     1142    }
     1143  }
     1144  Free(&buffer);
    11841145  CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds);
    11851146
     
    12351196  BFS.AtomCount = AtomCount;
    12361197  BFS.BondOrder = BondOrder;
    1237   BFS.PredecessorList = new atom*[AtomCount];
    1238   BFS.ShortestPathList = new int[AtomCount];
    1239   BFS.ColorList = new enum Shading[AtomCount];
     1198  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     1199  BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
     1200  BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    12401201  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    12411202
     
    12461207  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    12471208  for (int i = AtomCount; i--;) {
    1248     BFS.PredecessorList[i] = NULL;
    12491209    BFS.ShortestPathList[i] = -1;
    12501210    if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
     
    12531213      BFS.ColorList[i] = white;
    12541214  }
    1255   //BFS.ShortestPathList[Root->nr] = 0; // done by Calloc
     1215  //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
    12561216}
    12571217;
     
    12591219void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS)
    12601220{
    1261   delete[](BFS.PredecessorList);
    1262   delete[](BFS.ShortestPathList);
    1263   delete[](BFS.ColorList);
     1221  Free(&BFS.PredecessorList);
     1222  Free(&BFS.ShortestPathList);
     1223  Free(&BFS.ColorList);
    12641224  delete (BFS.BFSStack);
    12651225  BFS.AtomCount = 0;
     
    13531313    AddedAtomList[Root->nr] = Mol->AddCopyAtom(Root);
    13541314
    1355   BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, getAtomCount(), AddedAtomList);
     1315  BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, AtomCount, AddedAtomList);
    13561316
    13571317  // and go on ... Queue always contains all lightgray vertices
     
    14001360{
    14011361  // reset parent list
    1402   ParentList = new atom*[AtomCount];
    1403   for (int i=0;i<AtomCount;i++)
    1404     ParentList[i] = NULL;
     1362  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    14051363  DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
    14061364}
     
    14111369  // fill parent list with sons
    14121370  DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);
    1413   for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    1414     ParentList[(*iter)->father->nr] = (*iter);
     1371  atom *Walker = mol->start;
     1372  while (Walker->next != mol->end) {
     1373    Walker = Walker->next;
     1374    ParentList[Walker->father->nr] = Walker;
    14151375    // Outputting List for debugging
    1416     DoLog(4) && (Log() << Verbose(4) << "Son[" << (*iter)->father->nr << "] of " << (*iter)->father << " is " << ParentList[(*iter)->father->nr] << "." << endl);
    1417   }
    1418 };
     1376    DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl);
     1377  }
     1378
     1379}
     1380;
    14191381
    14201382void BuildInducedSubgraph_Finalize(atom **&ParentList)
    14211383{
    1422   delete[](ParentList);
     1384  Free(&ParentList);
    14231385}
    14241386;
     
    14271389{
    14281390  bool status = true;
     1391  atom *Walker = NULL;
    14291392  atom *OtherAtom = NULL;
    14301393  // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
    14311394  DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);
    1432   for (molecule::const_iterator iter = Father->begin(); iter != Father->end(); ++iter) {
    1433     if (ParentList[(*iter)->nr] != NULL) {
    1434       if (ParentList[(*iter)->nr]->father != (*iter)) {
     1395  Walker = Father->start;
     1396  while (Walker->next != Father->end) {
     1397    Walker = Walker->next;
     1398    if (ParentList[Walker->nr] != NULL) {
     1399      if (ParentList[Walker->nr]->father != Walker) {
    14351400        status = false;
    14361401      } else {
    1437         for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
    1438           OtherAtom = (*Runner)->GetOtherAtom((*iter));
     1402        for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
     1403          OtherAtom = (*Runner)->GetOtherAtom(Walker);
    14391404          if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
    1440             DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[(*iter)->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);
    1441             mol->AddBond(ParentList[(*iter)->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
     1405            DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);
     1406            mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
    14421407          }
    14431408        }
     
    14621427  bool status = true;
    14631428  atom **ParentList = NULL;
     1429
    14641430  DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);
    1465   BuildInducedSubgraph_Init(ParentList, Father->getAtomCount());
     1431  BuildInducedSubgraph_Init(ParentList, Father->AtomCount);
    14661432  BuildInducedSubgraph_FillParentList(this, Father, ParentList);
    14671433  status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
Note: See TracChangeset for help on using the changeset viewer.