Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_graph.cpp

    re5ad5c r68f03d  
    1717#include "memoryallocator.hpp"
    1818#include "molecule.hpp"
     19#include "World.hpp"
     20#include "Helpers/fast_functions.hpp"
    1921
    2022struct BFSAccounting
     
    5860
    5961  if (!input) {
    60     Log() << Verbose(1) << "Opening silica failed \n";
     62    DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n");
    6163  };
    6264
    6365  *input >> ws >> atom1;
    6466  *input >> ws >> atom2;
    65   Log() << Verbose(1) << "Scanning file\n";
     67  DoLog(1) && (Log() << Verbose(1) << "Scanning file\n");
    6668  while (!input->eof()) // Check whether we read everything already
    6769  {
     
    106108  LinkedCell *LC = NULL;
    107109  bool free_BG = false;
     110  double * const cell_size = World::getInstance().getDomain();
    108111
    109112  if (BG == NULL) {
     
    113116
    114117  BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem);
    115   Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl;
     118  DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl);
    116119  // remove every bond from the list
    117120  bond *Binder = NULL;
     
    126129  // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
    127130  CountAtoms();
    128   Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl;
     131  DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl);
    129132
    130133  if ((AtomCount > 1) && (bonddistance > 1.)) {
    131     Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl;
     134    DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
    132135    LC = new LinkedCell(this, bonddistance);
    133136
    134137    // create a list to map Tesselpoint::nr to atom *
    135     Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl;
     138    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    136139    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    137140    Walker = start;
     
    142145
    143146    // 3a. go through every cell
    144     Log() << Verbose(2) << "Celling ... " << endl;
     147    DoLog(2) && (Log() << Verbose(2) << "Celling ... " << endl);
    145148    for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++)
    146149      for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++)
    147150        for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) {
    148           const LinkedNodes *List = LC->GetCurrentCell();
     151          const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    149152//          Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
    150153          if (List != NULL) {
    151             for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     154            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    152155              Walker = AtomMap[(*Runner)->nr];
    153156//              Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
     
    156159                for (n[1] = -1; n[1] <= 1; n[1]++)
    157160                  for (n[2] = -1; n[2] <= 1; n[2]++) {
    158                     const LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n);
     161                    const LinkedCell::LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n);
    159162//                    Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
    160163                    if (OtherList != NULL) {
    161                       for (LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
     164                      for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
    162165                        if ((*OtherRunner)->nr > Walker->nr) {
    163166                          OtherWalker = AtomMap[(*OtherRunner)->nr];
    164167//                          Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl;
    165                           const double distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size);
     168                          const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size);
    166169//                          Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    167170                          (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
     
    187190    Free(&AtomMap);
    188191    delete (LC);
    189     Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl;
     192    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
    190193
    191194    // correct bond degree by comparing valence and bond degree
    192     Log() << Verbose(2) << "Correcting bond degree ... " << endl;
     195    DoLog(2) && (Log() << Verbose(2) << "Correcting bond degree ... " << endl);
    193196    CorrectBondDegree();
    194197
     
    196199    ActOnAllAtoms( &atom::OutputBondOfAtom );
    197200  } else
    198     Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    199   Log() << Verbose(0) << "End of CreateAdjacencyList." << endl;
     201    DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);
     202  DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
    200203  if (free_BG)
    201204    delete(BG);
     
    208211void molecule::OutputBondsList() const
    209212{
    210   Log() << Verbose(1) << endl << "From contents of bond chain list:";
     213  DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:");
    211214  bond *Binder = first;
    212215  while (Binder->next != last) {
    213216    Binder = Binder->next;
    214     Log() << Verbose(0) << *Binder << "\t" << endl;
    215   }
    216   Log() << Verbose(0) << endl;
     217    DoLog(0) && (Log() << Verbose(0) << *Binder << "\t" << endl);
     218  }
     219  DoLog(0) && (Log() << Verbose(0) << endl);
    217220}
    218221;
     
    231234
    232235  if (BondCount != 0) {
    233     Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl;
     236    DoLog(1) && (Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl);
    234237    do {
    235238      OldNo = No;
    236239      No = SumPerAtom( &atom::CorrectBondDegree );
    237240    } while (OldNo != No);
    238     Log() << Verbose(0) << " done." << endl;
     241    DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    239242  } else {
    240     Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    241   }
    242   Log() << Verbose(0) << No << " bonds could not be corrected." << endl;
     243    DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl);
     244  }
     245  DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);
    243246
    244247  return (No);
     
    259262  bond *Binder = first;
    260263  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
    261     Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;
     264    DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);
    262265    Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
    263266    while (Subgraphs->next != NULL) {
     
    314317    Walker->GraphNr = DFS.CurrentGraphNr;
    315318    Walker->LowpointNr = DFS.CurrentGraphNr;
    316     Log() << Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl;
     319    DoLog(1) && (Log() << Verbose(1) << "Setting Walker[" << Walker->getName() << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl);
    317320    DFS.AtomStack->Push(Walker);
    318321    DFS.CurrentGraphNr++;
     
    341344    if (Binder == NULL)
    342345      break;
    343     Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl;
     346    DoLog(2) && (Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl);
    344347    // (4) Mark Binder used, ...
    345348    Binder->MarkUsed(black);
    346349    OtherAtom = Binder->GetOtherAtom(Walker);
    347     Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl;
     350    DoLog(2) && (Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->getName() << "." << endl);
    348351    if (OtherAtom->GraphNr != -1) {
    349352      // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3)
     
    351354      DFS.BackEdgeStack->Push(Binder);
    352355      Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr;
    353       Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl;
     356      DoLog(3) && (Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->getName() << "] to " << Walker->LowpointNr << "." << endl);
    354357    } else {
    355358      // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2)
     
    357360      OtherAtom->Ancestor = Walker;
    358361      Walker = OtherAtom;
    359       Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl;
     362      DoLog(3) && (Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->getName() << "]'s Ancestor is now " << OtherAtom->Ancestor->getName() << ", Walker is OtherAtom " << OtherAtom->getName() << "." << endl);
    360363      break;
    361364    }
     
    379382
    380383  // (5) if Ancestor of Walker is ...
    381   Log() << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl;
     384  DoLog(1) && (Log() << Verbose(1) << "(5) Number of Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "] is " << Walker->Ancestor->GraphNr << "." << endl);
    382385
    383386  if (Walker->Ancestor->GraphNr != DFS.Root->GraphNr) {
     
    386389      // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8)
    387390      Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr;
    388       Log() << Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl;
     391      DoLog(2) && (Log() << Verbose(2) << "(6) Setting Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl);
    389392    } else {
    390393      // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component
    391394      Walker->Ancestor->SeparationVertex = true;
    392       Log() << Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl;
     395      DoLog(2) && (Log() << Verbose(2) << "(7) Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s is a separating vertex, creating component." << endl);
    393396      mol->SetNextComponentNumber(Walker->Ancestor, DFS.ComponentNumber);
    394       Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl;
     397      DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl);
    395398      mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
    396       Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     399      DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    397400      do {
    398401        OtherAtom = DFS.AtomStack->PopLast();
    399402        LeafWalker->Leaf->AddCopyAtom(OtherAtom);
    400403        mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
    401         Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     404        DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    402405      } while (OtherAtom != Walker);
    403406      DFS.ComponentNumber++;
    404407    }
    405408    // (8) Walker becomes its Ancestor, go to (3)
    406     Log() << Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl;
     409    DoLog(2) && (Log() << Verbose(2) << "(8) Walker[" << Walker->getName() << "] is now its Ancestor " << Walker->Ancestor->getName() << ", backstepping. " << endl);
    407410    Walker = Walker->Ancestor;
    408411    DFS.BackStepping = true;
     
    428431    //DFS.AtomStack->Output(out);
    429432    mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber);
    430     Log() << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;
     433    DoLog(3) && (Log() << Verbose(3) << "(9) Root[" << DFS.Root->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);
    431434    mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
    432     Log() << Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;
     435    DoLog(3) && (Log() << Verbose(3) << "(9) Walker[" << Walker->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);
    433436    do {
    434437      OtherAtom = DFS.AtomStack->PopLast();
    435438      LeafWalker->Leaf->AddCopyAtom(OtherAtom);
    436439      mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
    437       Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     440      DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    438441    } while (OtherAtom != Walker);
    439442    DFS.ComponentNumber++;
     
    442445    Walker = DFS.Root;
    443446    Binder = mol->FindNextUnused(Walker);
    444     Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl;
     447    DoLog(1) && (Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->getName() << "], next Unused Bond is " << Binder << "." << endl);
    445448    if (Binder != NULL) { // Root is separation vertex
    446       Log() << Verbose(1) << "(11) Root is a separation vertex." << endl;
     449      DoLog(1) && (Log() << Verbose(1) << "(11) Root is a separation vertex." << endl);
    447450      Walker->SeparationVertex = true;
    448451    }
     
    499502  bond *Binder = NULL;
    500503
    501   Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
     504  if (AtomCount == 0)
     505    return SubGraphs;
     506  DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl);
    502507  DepthFirstSearchAnalysis_Init(DFS, this);
    503508
     
    509514    // put into new subgraph molecule and add this to list of subgraphs
    510515    LeafWalker = new MoleculeLeafClass(LeafWalker);
    511     LeafWalker->Leaf = new molecule(elemente);
     516    LeafWalker->Leaf = World::getInstance().createMolecule();
    512517    LeafWalker->Leaf->AddCopyAtom(DFS.Root);
    513518
     
    521526
    522527        if (Binder == NULL) {
    523           Log() << Verbose(2) << "No more Unused Bonds." << endl;
     528          DoLog(2) && (Log() << Verbose(2) << "No more Unused Bonds." << endl);
    524529          break;
    525530        } else
     
    538543
    539544    // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph
    540     Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl;
     545    DoLog(0) && (Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl);
    541546    LeafWalker->Leaf->Output((ofstream *)&cout);
    542     Log() << Verbose(0) << endl;
     547    DoLog(0) && (Log() << Verbose(0) << endl);
    543548
    544549    // step on to next root
     
    558563  // free all and exit
    559564  DepthFirstSearchAnalysis_Finalize(DFS);
    560   Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl;
     565  DoLog(0) && (Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl);
    561566  return SubGraphs;
    562567}
     
    584589void molecule::OutputGraphInfoPerAtom() const
    585590{
    586   Log() << Verbose(1) << "Final graph info for each atom is:" << endl;
     591  DoLog(1) && (Log() << Verbose(1) << "Final graph info for each atom is:" << endl);
    587592  ActOnAllAtoms( &atom::OutputGraphInfo );
    588593}
     
    594599void molecule::OutputGraphInfoPerBond() const
    595600{
    596   Log() << Verbose(1) << "Final graph info for each bond is:" << endl;
     601  DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl);
    597602  bond *Binder = first;
    598603  while (Binder->next != last) {
    599604    Binder = Binder->next;
    600     Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";
    601     Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";
     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.");
    602607    Binder->leftatom->OutputComponentNumber();
    603     Log() << Verbose(0) << " ===  ";
    604     Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
     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.");
    605610    Binder->rightatom->OutputComponentNumber();
    606     Log() << Verbose(0) << ">." << endl;
     611    DoLog(0) && (Log() << Verbose(0) << ">." << endl);
    607612    if (Binder->Cyclic) // cyclic ??
    608       Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl;
     613      DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);
    609614  }
    610615}
     
    680685  do { // look for Root
    681686    Walker = BFS.BFSStack->PopFirst();
    682     Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl;
     687    DoLog(2) && (Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl);
    683688    for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    684689      if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder)
     
    687692        if (OtherAtom->type->Z != 1) {
    688693#endif
    689         Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;
     694        DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);
    690695        if (BFS.ColorList[OtherAtom->nr] == white) {
    691696          BFS.TouchedStack->Push(OtherAtom);
     
    693698          BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor
    694699          BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1;
    695           Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
     700          DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " lightgray, its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);
    696701          //if (BFS.ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance
    697           Log() << Verbose(3) << "Putting OtherAtom into queue." << endl;
     702          DoLog(3) && (Log() << Verbose(3) << "Putting OtherAtom into queue." << endl);
    698703          BFS.BFSStack->Push(OtherAtom);
    699704          //}
    700705        } else {
    701           Log() << Verbose(3) << "Not Adding, has already been visited." << endl;
     706          DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
    702707        }
    703708        if (OtherAtom == BFS.Root)
     
    705710#ifdef ADDHYDROGEN
    706711      } else {
    707         Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl;
     712        DoLog(2) && (Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl);
    708713        BFS.ColorList[OtherAtom->nr] = black;
    709714      }
    710715#endif
    711716      } else {
    712         Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl;
     717        DoLog(2) && (Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl);
    713718      }
    714719    }
    715720    BFS.ColorList[Walker->nr] = black;
    716     Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
     721    DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);
    717722    if (OtherAtom == BFS.Root) { // if we have found the root, check whether this cycle wasn't already found beforehand
    718723      // step through predecessor list
     
    724729      }
    725730      if (OtherAtom == BackEdge->rightatom) { // if each atom in found cycle is cyclic, loop's been found before already
    726         Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl;
     731        DoLog(3) && (Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl);
    727732        do {
    728733          OtherAtom = BFS.TouchedStack->PopLast();
    729734          if (BFS.PredecessorList[OtherAtom->nr] == Walker) {
    730             Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl;
     735            DoLog(4) && (Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl);
    731736            BFS.PredecessorList[OtherAtom->nr] = NULL;
    732737            BFS.ShortestPathList[OtherAtom->nr] = -1;
     
    762767    RingSize = 1;
    763768    BFS.Root->GetTrueFather()->IsCyclic = true;
    764     Log() << Verbose(1) << "Found ring contains: ";
     769    DoLog(1) && (Log() << Verbose(1) << "Found ring contains: ");
    765770    Walker = BFS.Root;
    766771    while (Walker != BackEdge->rightatom) {
    767       Log() << Verbose(0) << Walker->Name << " <-> ";
     772      DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " <-> ");
    768773      Walker = BFS.PredecessorList[Walker->nr];
    769774      Walker->GetTrueFather()->IsCyclic = true;
    770775      RingSize++;
    771776    }
    772     Log() << Verbose(0) << Walker->Name << "  with a length of " << RingSize << "." << endl << endl;
     777    DoLog(0) && (Log() << Verbose(0) << Walker->getName() << "  with a length of " << RingSize << "." << endl << endl);
    773778    // walk through all and set MinimumRingSize
    774779    Walker = BFS.Root;
     
    782787      MinRingSize = RingSize;
    783788  } else {
    784     Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl;
     789    DoLog(1) && (Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl);
    785790  }
    786791};
     
    860865
    861866      }
    862       Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl;
    863     }
    864     Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl;
     867      DoLog(1) && (Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl);
     868    }
     869    DoLog(1) && (Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl);
    865870  } else
    866     Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl;
     871    DoLog(1) && (Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl);
    867872}
    868873;
     
    892897  //BackEdgeStack->Output(out);
    893898
    894   Log() << Verbose(1) << "Analysing cycles ... " << endl;
     899  DoLog(1) && (Log() << Verbose(1) << "Analysing cycles ... " << endl);
    895900  NumCycles = 0;
    896901  while (!BackEdgeStack->IsEmpty()) {
     
    903908    ResetBFSAccounting(Walker, BFS);
    904909
    905     Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;
     910    DoLog(1) && (Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl);
    906911    OtherAtom = NULL;
    907912    CyclicStructureAnalysis_CyclicBFSFromRootToRoot(BackEdge, BFS);
     
    932937        break; // breaking here will not cause error!
    933938    }
    934     if (i == vertex->ListOfBonds.size())
    935       eLog() << Verbose(0) << "Error: All Component entries are already occupied!" << endl;
    936   } else
    937     eLog() << Verbose(0) << "Error: Given vertex is NULL!" << endl;
     939    if (i == vertex->ListOfBonds.size()) {
     940      DoeLog(0) && (eLog()<< Verbose(0) << "Error: All Component entries are already occupied!" << endl);
     941      performCriticalExit();
     942    }
     943  } else {
     944    DoeLog(0) && (eLog()<< Verbose(0) << "Error: Given vertex is NULL!" << endl);
     945    performCriticalExit();
     946  }
    938947}
    939948;
     
    971980void OutputAlreadyVisited(int *list)
    972981{
    973   Log() << Verbose(4) << "Already Visited Bonds:\t";
     982  DoLog(4) && (Log() << Verbose(4) << "Already Visited Bonds:\t");
    974983  for (int i = 1; i <= list[0]; i++)
    975     Log() << Verbose(0) << list[i] << "  ";
    976   Log() << Verbose(0) << endl;
     984    DoLog(0) && (Log() << Verbose(0) << list[i] << "  ");
     985  DoLog(0) && (Log() << Verbose(0) << endl);
    977986}
    978987;
     
    980989/** Storing the bond structure of a molecule to file.
    981990 * Simply stores Atom::nr and then the Atom::nr of all bond partners per line.
    982  * \param *out output stream for debugging
    983991 * \param *path path to file
     992 * \param *filename name of file
    984993 * \return true - file written successfully, false - writing failed
    985994 */
    986 bool molecule::StoreAdjacencyToFile(char *path)
     995bool molecule::StoreAdjacencyToFile(char *path, char *filename)
    987996{
    988997  ofstream AdjacencyFile;
     
    990999  bool status = true;
    9911000
    992   line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     1001  if (path != NULL)
     1002    line << path << "/" << filename;
     1003  else
     1004    line << filename;
    9931005  AdjacencyFile.open(line.str().c_str(), ios::out);
    994   Log() << Verbose(1) << "Saving adjacency list ... ";
     1006  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
    9951007  if (AdjacencyFile != NULL) {
     1008    AdjacencyFile << "m\tn" << endl;
    9961009    ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile);
    9971010    AdjacencyFile.close();
    998     Log() << Verbose(1) << "done." << endl;
     1011    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    9991012  } else {
    1000     Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     1013    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
     1014    status = false;
     1015  }
     1016
     1017  return status;
     1018}
     1019;
     1020
     1021/** Storing the bond structure of a molecule to file.
     1022 * Simply stores Atom::nr and then the Atom::nr of all bond partners, one per line.
     1023 * \param *path path to file
     1024 * \param *filename name of file
     1025 * \return true - file written successfully, false - writing failed
     1026 */
     1027bool molecule::StoreBondsToFile(char *path, char *filename)
     1028{
     1029  ofstream BondFile;
     1030  stringstream line;
     1031  bool status = true;
     1032
     1033  if (path != NULL)
     1034    line << path << "/" << filename;
     1035  else
     1036    line << filename;
     1037  BondFile.open(line.str().c_str(), ios::out);
     1038  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
     1039  if (BondFile != NULL) {
     1040    BondFile << "m\tn" << endl;
     1041    ActOnAllAtoms(&atom::OutputBonds, &BondFile);
     1042    BondFile.close();
     1043    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     1044  } else {
     1045    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    10011046    status = false;
    10021047  }
     
    10111056  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    10121057  File.open(filename.str().c_str(), ios::out);
    1013   Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ";
     1058  DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ");
    10141059  if (File == NULL)
    10151060    return false;
     
    10521097    //Log() << Verbose(0) << endl;
    10531098  } else {
    1054     Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl;
     1099    DoLog(0) && (Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl);
    10551100    status = false;
    10561101  }
     
    10751120
    10761121  if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) {
    1077     Log() << Verbose(1) << "Adjacency file not found." << endl;
     1122    DoLog(1) && (Log() << Verbose(1) << "Adjacency file not found." << endl);
    10781123    return true;
    10791124  }
     
    11011146
    11021147  if (status) { // if equal we parse the KeySetFile
    1103     Log() << Verbose(1) << "done: Equal." << endl;
     1148    DoLog(1) && (Log() << Verbose(1) << "done: Equal." << endl);
    11041149  } else
    1105     Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
     1150    DoLog(1) && (Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl);
    11061151  return status;
    11071152}
     
    11191164  bool status = true;
    11201165  if (ReferenceStack->IsEmpty()) {
    1121     eLog() << Verbose(0) << "ReferenceStack is empty!" << endl;
     1166    DoLog(1) && (Log() << Verbose(1) << "ReferenceStack is empty!" << endl);
    11221167    return false;
    11231168  }
     
    11341179        if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->nr]) { // found the bond
    11351180          LocalStack->Push((*Runner));
    1136           Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl;
     1181          DoLog(3) && (Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl);
    11371182          break;
    11381183        }
    11391184      }
    11401185    Binder = ReferenceStack->PopFirst(); // loop the stack for next item
    1141     Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl;
     1186    DoLog(3) && (Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl);
    11421187    ReferenceStack->Push(Binder);
    11431188  } while (FirstBond != Binder);
     
    11881233  BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor
    11891234  BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1;
    1190   Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
     1235  DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);
    11911236  if ((((BFS.ShortestPathList[OtherAtom->nr] < BFS.BondOrder) && (Binder != Bond)))) { // Check for maximum distance
    1192     Log() << Verbose(3);
     1237    DoLog(3) && (Log() << Verbose(3));
    11931238    if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far
    11941239      AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom);
    1195       Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->Name;
     1240      DoLog(0) && (Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->getName());
    11961241      AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder);
    1197       Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ";
     1242      DoLog(0) && (Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ");
    11981243    } 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)
    1199       Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->Name;
     1244      DoLog(0) && (Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->getName());
    12001245      if (AddedBondList[Binder->nr] == NULL) {
    12011246        AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder);
    1202         Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]);
     1247        DoLog(0) && (Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]));
    12031248      } else
    1204         Log() << Verbose(0) << ", not added Bond ";
    1205     }
    1206     Log() << Verbose(0) << ", putting OtherAtom into queue." << endl;
     1249        DoLog(0) && (Log() << Verbose(0) << ", not added Bond ");
     1250    }
     1251    DoLog(0) && (Log() << Verbose(0) << ", putting OtherAtom into queue." << endl);
    12071252    BFS.BFSStack->Push(OtherAtom);
    12081253  } else { // out of bond order, then replace
     
    12101255      BFS.ColorList[OtherAtom->nr] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic)
    12111256    if (Binder == Bond)
    1212       Log() << Verbose(3) << "Not Queueing, is the Root bond";
     1257      DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is the Root bond");
    12131258    else if (BFS.ShortestPathList[OtherAtom->nr] >= BFS.BondOrder)
    1214       Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder;
     1259      DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder);
    12151260    if (!Binder->Cyclic)
    1216       Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl;
     1261      DoLog(0) && (Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl);
    12171262    if (AddedBondList[Binder->nr] == NULL) {
    12181263      if ((AddedAtomList[OtherAtom->nr] != NULL)) { // .. whether we add or saturate
     
    12311276void BreadthFirstSearchAdd_VisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)
    12321277{
    1233   Log() << Verbose(3) << "Not Adding, has already been visited." << endl;
     1278  DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
    12341279  // This has to be a cyclic bond, check whether it's present ...
    12351280  if (AddedBondList[Binder->nr] == NULL) {
     
    12771322    // followed by n+1 till top of stack.
    12781323    Walker = BFS.BFSStack->PopFirst(); // pop oldest added
    1279     Log() << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl;
     1324    DoLog(1) && (Log() << Verbose(1) << "Current Walker is: " << Walker->getName() << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl);
    12801325    for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    12811326      if ((*Runner) != NULL) { // don't look at bond equal NULL
    12821327        Binder = (*Runner);
    12831328        OtherAtom = (*Runner)->GetOtherAtom(Walker);
    1284         Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;
     1329        DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);
    12851330        if (BFS.ColorList[OtherAtom->nr] == white) {
    12861331          BreadthFirstSearchAdd_UnvisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);
     
    12911336    }
    12921337    BFS.ColorList[Walker->nr] = black;
    1293     Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
     1338    DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);
    12941339  }
    12951340  BreadthFirstSearchAdd_Free(BFS);
     
    13161361  // reset parent list
    13171362  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    1318   Log() << Verbose(3) << "Resetting ParentList." << endl;
     1363  DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
    13191364}
    13201365;
     
    13231368{
    13241369  // fill parent list with sons
    1325   Log() << Verbose(3) << "Filling Parent List." << endl;
     1370  DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);
    13261371  atom *Walker = mol->start;
    13271372  while (Walker->next != mol->end) {
     
    13291374    ParentList[Walker->father->nr] = Walker;
    13301375    // Outputting List for debugging
    1331     Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl;
     1376    DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl);
    13321377  }
    13331378
     
    13471392  atom *OtherAtom = NULL;
    13481393  // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
    1349   Log() << Verbose(3) << "Creating bonds." << endl;
     1394  DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);
    13501395  Walker = Father->start;
    13511396  while (Walker->next != Father->end) {
     
    13581403          OtherAtom = (*Runner)->GetOtherAtom(Walker);
    13591404          if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
    1360             Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl;
     1405            DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);
    13611406            mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
    13621407          }
     
    13831428  atom **ParentList = NULL;
    13841429
    1385   Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     1430  DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);
    13861431  BuildInducedSubgraph_Init(ParentList, Father->AtomCount);
    13871432  BuildInducedSubgraph_FillParentList(this, Father, ParentList);
    13881433  status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
    13891434  BuildInducedSubgraph_Finalize(ParentList);
    1390   Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl;
     1435  DoLog(2) && (Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl);
    13911436  return status;
    13921437}
     
    14051450  int size;
    14061451
    1407   Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl;
    1408   Log() << Verbose(2) << "Disconnected atom: ";
     1452  DoLog(1) && (Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl);
     1453  DoLog(2) && (Log() << Verbose(2) << "Disconnected atom: ");
    14091454
    14101455  // count number of atoms in graph
     
    14281473      }
    14291474      if (!BondStatus) {
    1430         Log() << Verbose(0) << (*Walker) << endl;
     1475        DoLog(0) && (Log() << Verbose(0) << (*Walker) << endl);
    14311476        return false;
    14321477      }
    14331478    }
    14341479  else {
    1435     Log() << Verbose(0) << "none." << endl;
     1480    DoLog(0) && (Log() << Verbose(0) << "none." << endl);
    14361481    return true;
    14371482  }
    1438   Log() << Verbose(0) << "none." << endl;
    1439 
    1440   Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl;
     1483  DoLog(0) && (Log() << Verbose(0) << "none." << endl);
     1484
     1485  DoLog(1) && (Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl);
    14411486
    14421487  return true;
Note: See TracChangeset for help on using the changeset viewer.