Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_graph.cpp

    r920c70 r68f03d  
    1212#include "element.hpp"
    1313#include "helpers.hpp"
    14 #include "info.hpp"
    1514#include "linkedcell.hpp"
    1615#include "lists.hpp"
     
    5554void molecule::CreateAdjacencyListFromDbondFile(ifstream *input)
    5655{
    57   Info FunctionInfo(__func__);
     56
    5857  // 1 We will parse bonds out of the dbond file created by tremolo.
    5958  int atom1, atom2;
    6059  atom *Walker, *OtherWalker;
    61   char line[MAXSTRINGSIZE];
    62 
    63   if (input->fail()) {
    64     DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n");
    65     performCriticalExit();
     60
     61  if (!input) {
     62    DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n");
    6663  };
    6764
    68   // skip header
    69   input->getline(line,MAXSTRINGSIZE);
    70   DoLog(1) && (Log() << Verbose(1) << "Scanning file ... \n");
     65  *input >> ws >> atom1;
     66  *input >> ws >> atom2;
     67  DoLog(1) && (Log() << Verbose(1) << "Scanning file\n");
    7168  while (!input->eof()) // Check whether we read everything already
    7269  {
    73     input->getline(line,MAXSTRINGSIZE);
    74     stringstream zeile(line);
    75     zeile >> atom1;
    76     zeile >> atom2;
    77 
    78     DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl);
     70    *input >> ws >> atom1;
     71    *input >> ws >> atom2;
     72
    7973    if (atom2 < atom1) //Sort indices of atoms in order
    8074      flip(atom1, atom2);
     
    143137    // create a list to map Tesselpoint::nr to atom *
    144138    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    145     AtomMap = new atom *[AtomCount];
    146     for (int i=0;i<AtomCount;i++)
    147       AtomMap[i] = NULL;
     139    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    148140    Walker = start;
    149141    while (Walker->next != end) {
     
    196188          }
    197189        }
    198     delete[](AtomMap);
     190    Free(&AtomMap);
    199191    delete (LC);
    200192    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
     
    632624{
    633625  BFS.AtomCount = AtomCount;
    634   BFS.PredecessorList = new atom*[AtomCount];
    635   BFS.ShortestPathList = new int[AtomCount];
    636   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");
    637629  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    638630
    639   for (int i = AtomCount; i--;) {
     631  for (int i = AtomCount; i--;)
    640632    BFS.ShortestPathList[i] = -1;
    641     BFS.PredecessorList[i] = 0;
    642   }
    643633};
    644634
     
    649639void FinalizeBFSAccounting(struct BFSAccounting &BFS)
    650640{
    651   delete[](BFS.PredecessorList);
    652   delete[](BFS.ShortestPathList);
    653   delete[](BFS.ColorList);
     641  Free(&BFS.PredecessorList);
     642  Free(&BFS.ShortestPathList);
     643  Free(&BFS.ColorList);
    654644  delete (BFS.BFSStack);
    655645  BFS.AtomCount = 0;
     
    10711061
    10721062  // allocate storage structure
    1073   CurrentBonds = new int[8]; // contains parsed bonds of current atom
    1074   for(int i=0;i<8;i++)
    1075     CurrentBonds[i] = 0;
     1063  CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    10761064  return true;
    10771065}
     
    10821070  File.close();
    10831071  File.clear();
    1084   delete[](CurrentBonds);
     1072  Free(&CurrentBonds);
    10851073}
    10861074;
     
    11261114  bool status = true;
    11271115  atom *Walker = NULL;
     1116  char *buffer = NULL;
    11281117  int *CurrentBonds = NULL;
    11291118  int NonMatchNumber = 0; // will number of atoms with differing bond structure
     
    11351124  }
    11361125
    1137   char buffer[MAXSTRINGSIZE];
     1126  buffer = Malloc<char> (MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    11381127  // Parse the file line by line and count the bonds
    11391128  while (!File.eof()) {
     
    11531142    }
    11541143  }
     1144  Free(&buffer);
    11551145  CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds);
    11561146
     
    12061196  BFS.AtomCount = AtomCount;
    12071197  BFS.BondOrder = BondOrder;
    1208   BFS.PredecessorList = new atom*[AtomCount];
    1209   BFS.ShortestPathList = new int[AtomCount];
    1210   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");
    12111201  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    12121202
     
    12171207  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    12181208  for (int i = AtomCount; i--;) {
    1219     BFS.PredecessorList[i] = NULL;
    12201209    BFS.ShortestPathList[i] = -1;
    12211210    if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
     
    12241213      BFS.ColorList[i] = white;
    12251214  }
    1226   //BFS.ShortestPathList[Root->nr] = 0; // done by Calloc
     1215  //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
    12271216}
    12281217;
     
    12301219void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS)
    12311220{
    1232   delete[](BFS.PredecessorList);
    1233   delete[](BFS.ShortestPathList);
    1234   delete[](BFS.ColorList);
     1221  Free(&BFS.PredecessorList);
     1222  Free(&BFS.ShortestPathList);
     1223  Free(&BFS.ColorList);
    12351224  delete (BFS.BFSStack);
    12361225  BFS.AtomCount = 0;
     
    13711360{
    13721361  // reset parent list
    1373   ParentList = new atom*[AtomCount];
    1374   for (int i=0;i<AtomCount;i++)
    1375     ParentList[i] = NULL;
     1362  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    13761363  DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
    13771364}
     
    13951382void BuildInducedSubgraph_Finalize(atom **&ParentList)
    13961383{
    1397   delete[](ParentList);
     1384  Free(&ParentList);
    13981385}
    13991386;
Note: See TracChangeset for help on using the changeset viewer.