Changeset 3ccc3e for src/molecules.cpp


Ignore:
Timestamp:
Oct 9, 2008, 6:29:03 PM (16 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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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++) {
Note: See TracChangeset for help on using the changeset viewer.