Ignore:
Timestamp:
Oct 25, 2011, 12:08:03 PM (14 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, Candidate_v1.7.0, 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:
246e13
Parents:
d0b375b
git-author:
Frederik Heber <heber@…> (10/18/11 13:16:51)
git-committer:
Frederik Heber <heber@…> (10/25/11 12:08:03)
Message:

Placed all functions related to BondsPerSPList into own class BondsPerShortestPath.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/UniqueFragments.cpp

    rd0b375b r212c179  
    5858};
    5959
    60 /** Allocates memory for UniqueFragments::BondsPerSPList.
    61  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    62  * \sa UniqueFragments::FreeSPList()
    63  */
    64 void UniqueFragments::InitialiseSPList(int Order)
    65 {
    66   BondsPerSPList.resize(Order);
    67   BondsPerSPCount = new int[Order];
    68   for (int i=Order;i--;) {
    69     BondsPerSPCount[i] = 0;
    70   }
    71 };
    72 
    73 /** Free's memory for for UniqueFragments::BondsPerSPList.
    74  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    75  * \sa UniqueFragments::InitialiseSPList()
    76  */
    77 void UniqueFragments::FreeSPList(int Order)
    78 {
    79   delete[](BondsPerSPCount);
    80 };
    81 
    82 /** Sets FragmenSearch to initial value.
    83  * Sets UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and adds initial bond
    84  * UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList
    85  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    86  * \sa UniqueFragments::FreeSPList()
    87  */
    88 void UniqueFragments::SetSPList(int Order)
    89 {
    90   // prepare root level (SP = 0) and a loop bond denoting Root
    91   for (int i=Order;i--;)
    92     BondsPerSPCount[i] = 0;
    93   BondsPerSPCount[0] = 1;
    94   bond *Binder = new bond(Root, Root);
    95   BondsPerSPList[0].push_back(Binder);
    96 };
    97 
    98 /** Cleans bonds from UniqueFragments::BondsPerSPList.
    99  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    100  * \sa UniqueFragments::InitialiseSPList()
    101  */
    102 void UniqueFragments::ResetSPList(int Order)
    103 {
    104   DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
    105   for(int i=Order;i--;) {
    106     DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
    107     // delete added bonds
    108     for (UniqueFragments::BondsPerSP::iterator iter = BondsPerSPList[i].begin();
    109         iter != BondsPerSPList[i].end();
    110         ++iter) {
    111       delete(*iter);
    112     }
    113     BondsPerSPList[i].clear();
    114     // also start and end node
    115     DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
    116   }
    117 };
    118 
    119 
    120 /** Fills the Bonds per Shortest Path List and set the vertex labels.
    121  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    122  * \param RestrictedKeySet Restricted vertex set to use in context of molecule
    123  */
    124 void UniqueFragments::FillSPListandLabelVertices(int Order, KeySet &RestrictedKeySet)
    125 {
    126   // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
    127   // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
    128   // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
    129   // (EdgeinSPLevel) of this tree ...
    130   // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
    131   // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
    132   int AtomKeyNr = -1;
    133   atom *Walker = NULL;
    134   atom *OtherWalker = NULL;
    135   atom *Predecessor = NULL;
    136   bond *Binder = NULL;
    137   int RootKeyNr = Root->GetTrueFather()->getNr();
    138   int RemainingWalkers = -1;
    139   int SP = -1;
    140 
    141   DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
    142   for (SP = 0; SP < (Order-1); SP++) {
    143     DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)");
    144     if (SP > 0) {
    145       DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s)." << endl);
    146       BondsPerSPCount[SP] = 0;
    147     } else
    148       DoLog(0) && (Log() << Verbose(0) << "." << endl);
    149 
    150     RemainingWalkers = BondsPerSPCount[SP];
    151     for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
    152         CurrentEdge != BondsPerSPList[SP].end();
    153         ++CurrentEdge) { /// start till end of this SP level's list
    154       RemainingWalkers--;
    155       Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
    156       Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
    157       AtomKeyNr = Walker->getNr();
    158       DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
    159       // check for new sp level
    160       // go through all its bonds
    161       DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
    162       const BondList& ListOfBonds = Walker->getListOfBonds();
    163       for (BondList::const_iterator Runner = ListOfBonds.begin();
    164           Runner != ListOfBonds.end();
    165           ++Runner) {
    166         OtherWalker = (*Runner)->GetOtherAtom(Walker);
    167         if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
    168   #ifdef ADDHYDROGEN
    169          && (OtherWalker->getType()->getAtomicNumber() != 1)
    170   #endif
    171                                                               ) {  // skip hydrogens and restrict to fragment
    172           DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);
    173           // set the label if not set (and push on root stack as well)
    174           if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
    175             // add the bond in between to the SP list
    176             Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
    177             BondsPerSPList[SP+1].push_back(Binder);
    178             BondsPerSPCount[SP+1]++;
    179             DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s)." << endl);
    180           } else {
    181             if (OtherWalker != Predecessor)
    182               DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);
    183             else
    184               DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
    185           }
    186         } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
    187       }
    188     }
    189   }
    190 };
    191 
    192 /** prints the Bonds per Shortest Path list in UniqueFragments.
    193  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    194  */
    195 void UniqueFragments::OutputSPList(int Order)
    196 {
    197   DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
    198   for(int i=1;i<Order;i++) {    // skip the root edge in the printing
    199     DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
    200     for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
    201         Binder != BondsPerSPList[i].end();
    202         ++Binder) {
    203       DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
    204     }
    205   }
    206 };
    207 
    208 /** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists.
    209  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    210  */
    211 int UniqueFragments::CountNumbersInBondsList(int Order)
    212 {
    213   int SP = -1;  // the Root <-> Root edge must be subtracted!
    214   for(int i=Order;i--;) { // sum up all found edges
    215     for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
    216         Binder != BondsPerSPList[i].end();
    217         ++Binder) {
    218       SP++;
    219     }
    220   }
    221   return SP;
    222 };
    223 
    22460/** Initialization for UniqueFragments.
    22561 *
     
    24783 * @return const ref to root atom.
    24884 */
    249 const atom *UniqueFragments::getRoot() const
     85atom * const UniqueFragments::getRoot() const
    25086{
    25187  return Root;
     
    26096  Root=_root;
    26197}
     98
     99/** Sets initial values before PowerSetGenerator uses this class.
     100 *
     101 * @param _TEFactor total energy factor
     102 * @param _Leaflet current graph to work on
     103 * @param _Root root atom
     104 */
     105void UniqueFragments::PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root)
     106{
     107  TEFactor = _TEFactor;
     108  Leaflet = _Leaflet;
     109  Root = _Root;
     110}
Note: See TracChangeset for help on using the changeset viewer.