Changeset 3ccc3e


Ignore:
Timestamp:
Oct 9, 2008, 6:29:03 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
1e8243
Parents:
18913c
git-author:
Frederik Heber <heber@…> (10/09/08 18:27:56)
git-committer:
Frederik Heber <heber@…> (10/09/08 18:29:03)
Message:

BUGFIXES: CyclicStructureAnalysis() now compatible to disconnected subgraphs, AssignKeySetsToFragment() and FillBondStructureFromReference() memory cleanup corrected

+ molecule::DepthFirstSearchAnalysis() now just returns BackEdgeStack, not MinimumRingSize. CyclicStructureAnalysis() is called during FragmentMolecule(), after subgraphs bonds list have been filled by FillBondStructureFromReference().
+ new function molecule::PickLocalBackEdges(), as the BackEdgeStack returned by DepthFirstSearchAnalysis() co
ntains only global bonds, not the local ones for the subgraph, we have to step through it and pick the right
ones out.
+ molecule::FragmentMolecule() now calls molecule::CyclicStructureAnalysis() separately for each subgraph, along with a BackEdgeStack filled by PickLocalBackEdges(), and allocates&initialises MinimumRingSize array. Als
o AssignKeySetsToFragment() frees the LocalListOfAtoms now (FreeList=true), now longer after the following wh
ile
+ molecule::CyclicStructureAnalysis() takes a local BackEdgeStack and analysis the subgraphs cycles, returnin
g minimum ring size
+ MoleculeLeafClass::AssignKeySetsToFragment() now frees memory for ListOfLocalAtoms when FreeList is set. BUGFIX: test of first key was testing against ..->nr != -1. However, LocalListOfAtoms was not even initialised correctly to NULL, hence ...->nr pointed in some cases to nowhere. Now it test atom* against NULL.
+ MoleculeLeafClass::FillBondStructureFromReference() now frees memory for ListOfLocalAtoms when FreeList is set correctly (only free initial pointer when FragmentCounter == 0, also it was decreased not before but after freeing, hence we free'd the wrong list). Also, father replaced by GetTrueFather() (makes the function moregenerally useable, was not a bug).
+ ParseCommandLineOptions() option 'D': adapted to changes in DepthFirstSearchAnalysis() in a similar manner
to FragmentMolecule()
+ molecule::CountCyclicBonds() adapted but does not perform CyclicStructureAnalysis()
+ molecule::CreateAdjacencyList() counts the bonds that could not be brought to covalently corrected degree (i.e. the remaining ionic atoms)
+ molecule::CreateListOfBondsPerAtom() prints atom names and number, which is helpful as name contains global

and number contains local number (helped in finding above bugs)

+ CreateFatherLookupTable(): BUGFIX: LookupTable was not initialised to NULL (see above)

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    r18913c r3ccc3e  
    952952                cout << Verbose(1) << "Depth-First-Search Analysis." << endl;
    953953                MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
    954                 int *MinimumRingSize = NULL;
     954                int *MinimumRingSize = new int[mol->AtomCount];
     955                atom ***ListOfLocalAtoms = NULL;
     956                int FragmentCounter = 0;
     957                class StackClass<bond *> *BackEdgeStack = NULL;
     958                class StackClass<bond *> *LocalBackEdgeStack = NULL;
    955959                mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr]), configuration.GetIsAngstroem());
    956960                mol->CreateListOfBondsPerAtom((ofstream *)&cout);
    957                 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
    958                 delete[](MinimumRingSize);
     961                Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
    959962                if (Subgraphs != NULL) {
     963                  Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    960964                  while (Subgraphs->next != NULL) {
    961965                    Subgraphs = Subgraphs->next;
     966                    LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
     967                    Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
     968                    Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
     969                    delete(LocalBackEdgeStack);
    962970                    delete(Subgraphs->previous);
    963971                  }
    964972                  delete(Subgraphs);
     973                  for (int i=0;i<FragmentCounter;i++)
     974                    Free((void **)&ListOfLocalAtoms[FragmentCounter], "ParseCommandLineOptions: **ListOfLocalAtoms[]");
     975                  Free((void **)&ListOfLocalAtoms, "ParseCommandLineOptions: ***ListOfLocalAtoms");
    965976                }
     977                delete(BackEdgeStack);
     978                delete[](MinimumRingSize);
    966979              }
    967980              argptr+=1;
     
    12401253  int Z;
    12411254  int j, axis, count, faktor;
    1242   int *MinimumRingSize = NULL;
     1255  clock_t start,end;
     1256//  int *MinimumRingSize = NULL;
    12431257  MoleculeLeafClass *Subgraphs = NULL;
    1244   clock_t start,end;
     1258//  class StackClass<bond *> *BackEdgeStack = NULL;
    12451259  element **Elements;
    12461260  Vector **vectors;
     
    14081422       
    14091423      case 'o': // create the connection matrix
    1410         cout << Verbose(0) << "What's the maximum bond distance: ";
    1411         cin >> tmp1;
    1412         start = clock();
    1413         mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
    1414         //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
    1415         Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
    1416         while (Subgraphs->next != NULL) {
    1417           Subgraphs = Subgraphs->next;
    1418           delete(Subgraphs->previous);
     1424        {
     1425          cout << Verbose(0) << "What's the maximum bond distance: ";
     1426          cin >> tmp1;
     1427          start = clock();
     1428          mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
     1429          mol->CreateListOfBondsPerAtom((ofstream *)&cout);
     1430//          Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
     1431//          while (Subgraphs->next != NULL) {
     1432//            Subgraphs = Subgraphs->next;
     1433//            Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
     1434//            delete(Subgraphs->previous);
     1435//          }
     1436//          delete(Subgraphs);    // we don't need the list here, so free everything
     1437//          delete[](MinimumRingSize);
     1438//          Subgraphs = NULL;
     1439          end = clock();
     1440          cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
    14191441        }
    1420         delete(Subgraphs);    // we don't need the list here, so free everything
    1421         delete[](MinimumRingSize);
    1422         Subgraphs = NULL;
    1423         end = clock();
    1424         cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
    14251442        break;
    14261443       
  • src/helpers.hpp

    r18913c r3ccc3e  
    100100    status = false;
    101101  } else {
     102    for (int i=0;i<count;i++)
     103      LookupTable[i] = NULL;
    102104    Walker = start;
    103105    while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
  • src/moleculelist.cpp

    r18913c r3ccc3e  
    584584    while (Walker->next != Leaf->end) {
    585585      Walker = Walker->next;
    586       AtomNo = Walker->father->nr;  // global id of the current walker
     586      AtomNo = Walker->GetTrueFather()->nr;  // global id of the current walker
    587587      for(int i=0;i<reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all
    588588        Binder = reference->ListOfBondsPerAtom[AtomNo][i];
    589         OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->father)->nr];    // local copy of current bond partner of walker
     589        OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->GetTrueFather())->nr];    // local copy of current bond partner of walker
    590590        if (OtherWalker != NULL) {
    591591          if (OtherWalker->nr > Walker->nr)
    592592          Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);
    593593        } else {
    594           *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->father)->nr << "] is NULL!" << endl;
     594          *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl;
    595595          status = false;
    596596        }
     
    603603  }
    604604 
     605  FragmentCounter--;
    605606  if (FreeList) {
    606607    // free the index lookup list
    607608    Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");
    608     if (ListOfLocalAtoms[FragmentCounter] == NULL)
     609    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
    609610      Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
    610611  }
     
    656657 * \param *out output stream fro debugging
    657658 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
    658  * \param &FragmentCounter counts the fragments as we move along the list
     659 * \param FragmentCounter counts the fragments as we move along the list
    659660 * \param GlobalAtomCount number of atoms in the complete molecule
    660661 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
    661662 * \return true - succes, false - failure
    662663 */
    663 bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList)
     664bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
    664665{
    665666  bool status = true;
     
    721722    KeySet *TempSet = new KeySet;
    722723    for(Graph::iterator runner = KeySetList->begin();runner != KeySetList->end(); runner++) { // key sets contain global numbers!
    723       if ( ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr]->nr != -1) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
     724      if ( ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->nr] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
    724725        // translate keyset to local numbers
    725726        for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
     
    739740    if (next != NULL)
    740741      next->AssignKeySetsToFragment(out, reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
    741     FragmentCounter--;
    742742  } else
    743743    *out << Verbose(1) << "KeySetList is NULL or empty." << endl;
    744744 
     745  FragmentCounter--;
     746  if (FreeList) {
     747    // free the index lookup list
     748    Free((void **)&ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");
     749    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
     750      Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");
     751  }
    745752  return status;
    746753};
  • src/molecules.cpp

    r18913c r3ccc3e  
    16031603  int *MinimumRingSize = NULL;
    16041604  MoleculeLeafClass *Subgraphs = NULL;
     1605  class StackClass<bond *> *BackEdgeStack = NULL;
    16051606  bond *Binder = first;
    16061607  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
    16071608    *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;
    1608     Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
     1609    Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack);
    16091610    while (Subgraphs->next != NULL) {
    16101611      Subgraphs = Subgraphs->next;
     
    16191620      No++;   
    16201621  }
     1622  delete(BackEdgeStack);
    16211623  return No;
    16221624};
     
    17001702  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    17011703  Vector x;
     1704  int FalseBondDegree = 0;
    17021705 
    17031706  BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem);
     
    17181721      j += i+1;
    17191722      divisor[i] = (int)floor(cell_size[j]/bonddistance); // take smaller value such that size of linked cell is at least bonddistance
    1720       *out << Verbose(1) << "divisor[" << i << "]  = " << divisor[i] << "." << endl;
     1723      //*out << Verbose(1) << "divisor[" << i << "]  = " << divisor[i] << "." << endl;
    17211724    }
    17221725    // 2a. allocate memory for the cell list
     
    17431746      }
    17441747      index = n[2] + (n[1] + n[0] * divisor[1]) * divisor[2];
    1745       *out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl;
     1748      //*out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl;
    17461749      // add copy atom to this cell
    17471750      if (CellList[index] == NULL)  // allocate molecule if not done
     
    17851788                        distance =   OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size);
    17861789                        if ((OtherWalker->father->nr > Walker->father->nr) && (distance <= MaxDistance*MaxDistance) && (distance >= MinDistance*MinDistance)) { // create bond if distance is smaller
    1787                           *out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl;
     1790                          //*out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl;
    17881791                          AddBond(Walker->father, OtherWalker->father, 1);  // also increases molecule::BondCount
    17891792                          BondCount++;
     
    18441847              ListOfBondsPerAtom[Walker->nr][CandidateBondNo]->BondDegree++;
    18451848              *out << Verbose(2) << "Increased bond degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl;
    1846             }
     1849            } else
     1850              *out << Verbose(2) << "Could not find correct degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl;
     1851              FalseBondDegree++;
    18471852          }
    18481853                    }
     
    18511856                } else
    18521857                        *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    1853           *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl;
     1858          *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl;
    18541859               
    18551860          // output bonds for debugging (if bond chain list was correctly installed)
     
    18721877 * We use the algorithm from [Even, Graph Algorithms, p.62].
    18731878 * \param *out output stream for debugging
    1874  * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found
     1879 * \param *&BackEdgeStack NULL pointer to StackClass with all the found back edges, allocated and filled on return
    18751880 * \return list of each disconnected subgraph as an individual molecule class structure
    18761881 */
    1877 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize)
    1878 {
    1879   class StackClass<atom *> *AtomStack;
    1880   AtomStack = new StackClass<atom *>(AtomCount);
    1881   class StackClass<bond *> *BackEdgeStack = new StackClass<bond *> (BondCount);
     1882MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack)
     1883{
     1884  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
     1885  BackEdgeStack = new StackClass<bond *> (BondCount);
    18821886  MoleculeLeafClass *SubGraphs = new MoleculeLeafClass(NULL);
    18831887  MoleculeLeafClass *LeafWalker = SubGraphs;
     
    20112015    LeafWalker->Leaf->Output(out);
    20122016    *out << endl;
    2013    
     2017
    20142018    // step on to next root
    20152019    while ((Root != end) && (Root->GraphNr != -1)) {
     
    20292033  }
    20302034
    2031   // analysis of the cycles (print rings, get minimum cycle length)
    2032   CyclicStructureAnalysis(out, BackEdgeStack, MinimumRingSize);
    20332035
    20342036  *out << Verbose(1) << "Final graph info for each atom is:" << endl;
     
    20682070 * as cyclic and print out the cycles.
    20692071 * \param *out output stream for debugging
    2070  * \param *BackEdgeStack stack with all back edges found during DFS scan
     2072 * \param *BackEdgeStack stack with all back edges found during DFS scan. Beware: This stack contains the bonds from the total molecule, not from the subgraph!
    20712073 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found, if set is maximum search distance
    20722074 * \todo BFS from the not-same-LP to find back to starting point of tributary cycle over more than one bond
     
    20892091    ColorList[i] = white;
    20902092  }
    2091   MinimumRingSize = new int[AtomCount];
    2092   for(int i=AtomCount;i--;)
    2093     MinimumRingSize[i] = AtomCount;
    2094 
    20952093 
    20962094  *out << Verbose(1) << "Back edge list - ";
     
    28942892        MoleculeListClass *BondFragments = NULL;
    28952893  int *SortIndex = NULL;
    2896   int *MinimumRingSize = NULL;
     2894  int *MinimumRingSize = new int[AtomCount];
    28972895  int FragmentCounter;
    28982896  MoleculeLeafClass *MolecularWalker = NULL;
     
    29002898  fstream File;
    29012899  bool FragmentationToDo = true;
     2900  class StackClass<bond *> *BackEdgeStack = NULL, *LocalBackEdgeStack = NULL;
    29022901  bool CheckOrder = false;
    29032902  Graph **FragmentList = NULL;
     
    29312930
    29322931  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    2933   Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
     2932  Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack);
    29342933  // fill the bond structure of the individually stored subgraphs
    29352934  Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    2936 
     2935  // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
     2936  for(int i=AtomCount;i--;)
     2937    MinimumRingSize[i] = AtomCount;
     2938  MolecularWalker = Subgraphs;
     2939  FragmentCounter = 0;
     2940  while (MolecularWalker->next != NULL) {
     2941    MolecularWalker = MolecularWalker->next;
     2942    *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     2943    LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
     2944//    // check the list of local atoms for debugging
     2945//    *out << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl;
     2946//    for (int i=0;i<AtomCount;i++)
     2947//      if (ListOfLocalAtoms[FragmentCounter][i] == NULL)
     2948//        *out << "\tNULL";
     2949//      else
     2950//        *out << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name;
     2951    MolecularWalker->Leaf->PickLocalBackEdges(out, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
     2952    MolecularWalker->Leaf->CyclicStructureAnalysis(out, LocalBackEdgeStack, MinimumRingSize);
     2953    delete(LocalBackEdgeStack);
     2954  }
     2955 
    29372956  // ===== 3. if structure still valid, parse key set file and others =====
    29382957  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList);
     
    29432962  // =================================== Begin of FRAGMENTATION ===============================
    29442963  // ===== 6a. assign each keyset to its respective subgraph =====
    2945   Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), false);
     2964  Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true);
    29462965
    29472966  // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle
     
    29802999  delete[](MinimumRingSize);
    29813000 
    2982   // free the index lookup list
    2983   for (int i=FragmentCounter;i--;)
    2984     Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
    2985   Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");
    29863001
    29873002  // ==================================== End of FRAGMENTATION ============================================
     
    30573072};
    30583073
     3074
     3075/** Picks from a global stack with all back edges the ones in the fragment.
     3076 * \param *out output stream for debugging
     3077 * \param **ListOfLocalAtoms array of father atom::nr to local atom::nr (reverse of atom::father)
     3078 * \param *ReferenceStack stack with all the back egdes
     3079 * \param *LocalStack stack to be filled
     3080 * \return true - everything ok, false - ReferenceStack was empty
     3081 */
     3082bool molecule::PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack)
     3083{
     3084  bool status = true;
     3085  if (ReferenceStack->IsEmpty()) {
     3086    cerr << "ReferenceStack is empty!" << endl;
     3087    return false;
     3088  }
     3089  bond *Binder = ReferenceStack->PopFirst();
     3090  bond *FirstBond = Binder;   // mark the first bond, so that we don't loop through the stack indefinitely
     3091  atom *Walker = NULL, *OtherAtom = NULL;
     3092  ReferenceStack->Push(Binder);
     3093 
     3094  do {  // go through all bonds and push local ones
     3095    Walker = ListOfLocalAtoms[Binder->leftatom->nr];  // get one atom in the reference molecule
     3096    if (Walker == NULL) // if this Walker exists in the subgraph ...
     3097      continue;
     3098    for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) {    // go through the local list of bonds
     3099      OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);
     3100      if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond
     3101        LocalStack->Push(ListOfBondsPerAtom[Walker->nr][i]);
     3102        break;
     3103      }
     3104    }
     3105    Binder = ReferenceStack->PopFirst();  // loop the stack for next item
     3106    ReferenceStack->Push(Binder);
     3107  } while (FirstBond != Binder);
     3108 
     3109  return status;
     3110};
     3111
    30593112/** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file.
    30603113 * Atoms not present in the file get "-1".
     
    31993252  while (Walker->next != end) {
    32003253    Walker = Walker->next;
    3201     *out << Verbose(4) << "Atom " << Walker->Name << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: ";
     3254    *out << Verbose(4) << "Atom " << Walker->Name << "/" << Walker->nr << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: ";
    32023255    TotalDegree = 0;
    32033256    for (int j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) {
  • src/molecules.hpp

    r18913c r3ccc3e  
    269269 
    270270  // Graph analysis
    271   MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize);
     271  MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
    272272  void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
     273  bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
    273274  bond * FindNextUnused(atom *vertex);
    274275  void SetNextComponentNumber(atom *vertex, int nr);
     
    363364  bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
    364365  bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
    365   bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList);
     366  bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
    366367  void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
    367368  int Count() const;
Note: See TracChangeset for help on using the changeset viewer.