Changeset a03d25


Ignore:
Timestamp:
Oct 25, 2011, 12:08:03 PM (13 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:
f6d1d0
Parents:
d9a032
git-author:
Frederik Heber <heber@…> (10/18/11 11:53:21)
git-committer:
Frederik Heber <heber@…> (10/25/11 12:08:03)
Message:

Placed all routines working on UniqueFragments struct inside this class.

  • changed struct to class.
Location:
src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Makefile.am

    rd9a032 ra03d25  
    99        Fragmentation/HessianMatrix.cpp \
    1010        Fragmentation/KeySetsContainer.cpp \
    11         Fragmentation/MatrixContainer.cpp
     11        Fragmentation/MatrixContainer.cpp \
     12        Fragmentation/UniqueFragments.cpp
    1213
    1314FRAGMENTATIONHEADER = \
     
    1920        Fragmentation/HessianMatrix.hpp \
    2021        Fragmentation/KeySetsContainer.hpp \
    21         Fragmentation/MatrixContainer.hpp
     22        Fragmentation/MatrixContainer.hpp \
     23        Fragmentation/UniqueFragments.hpp
    2224
    2325
  • src/Fragmentation/fragmentation_helpers.cpp

    rd9a032 ra03d25  
    546546};
    547547
    548 /** Allocates memory for UniqueFragments::BondsPerSPList.
    549  * \param *out output stream
    550  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    551  * \param FragmentSearch UniqueFragments
    552  * \sa FreeSPList()
    553  */
    554 void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
    555 {
    556   FragmentSearch.BondsPerSPList.resize(Order);
    557   FragmentSearch.BondsPerSPCount = new int[Order];
    558   for (int i=Order;i--;) {
    559     FragmentSearch.BondsPerSPCount[i] = 0;
    560   }
    561 };
    562 
    563 /** Free's memory for for UniqueFragments::BondsPerSPList.
    564  * \param *out output stream
    565  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    566  * \param FragmentSearch UniqueFragments\
    567  * \sa InitialiseSPList()
    568  */
    569 void FreeSPList(int Order, struct UniqueFragments &FragmentSearch)
    570 {
    571   delete[](FragmentSearch.BondsPerSPCount);
    572 };
    573 
    574 /** Sets FragmenSearch to initial value.
    575  * Sets UniqueFragments::ShortestPathList entries to zero, UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and
    576  * adds initial bond UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList
    577  * \param *out output stream
    578  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    579  * \param FragmentSearch UniqueFragments
    580  * \sa FreeSPList()
    581  */
    582 void SetSPList(int Order, struct UniqueFragments &FragmentSearch)
    583 {
    584   // prepare Label and SP arrays of the BFS search
    585   FragmentSearch.ShortestPathList[FragmentSearch.Root->getNr()] = 0;
    586 
    587   // prepare root level (SP = 0) and a loop bond denoting Root
    588   for (int i=Order;i--;)
    589     FragmentSearch.BondsPerSPCount[i] = 0;
    590   FragmentSearch.BondsPerSPCount[0] = 1;
    591   bond *Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);
    592   FragmentSearch.BondsPerSPList[0].push_back(Binder);
    593 };
    594 
    595 /** Resets UniqueFragments::ShortestPathList and cleans bonds from UniqueFragments::BondsPerSPList.
    596  * \param *out output stream
    597  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    598  * \param FragmentSearch UniqueFragments
    599  * \sa InitialiseSPList()
    600  */
    601 void ResetSPList(int Order, struct UniqueFragments &FragmentSearch)
    602 {
    603   DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
    604   for(int i=Order;i--;) {
    605     DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
    606     for (UniqueFragments::BondsPerSP::const_iterator iter = FragmentSearch.BondsPerSPList[i].begin();
    607         iter != FragmentSearch.BondsPerSPList[i].end();
    608         ++iter) {
    609       // Log() << Verbose(0) << "Removing atom " << Binder->leftatom->getNr() << " and " << Binder->rightatom->getNr() << "." << endl; // make sure numbers are local
    610       FragmentSearch.ShortestPathList[(*iter)->leftatom->getNr()] = -1;
    611       FragmentSearch.ShortestPathList[(*iter)->rightatom->getNr()] = -1;
    612     }
    613     // delete added bonds
    614     for (UniqueFragments::BondsPerSP::iterator iter = FragmentSearch.BondsPerSPList[i].begin();
    615         iter != FragmentSearch.BondsPerSPList[i].end();
    616         ++iter) {
    617       delete(*iter);
    618     }
    619     FragmentSearch.BondsPerSPList[i].clear();
    620     // also start and end node
    621     DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
    622   }
    623 };
    624 
    625 
    626 /** Fills the Bonds per Shortest Path List and set the vertex labels.
    627  * \param *out output stream
    628  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    629  * \param FragmentSearch UniqueFragments
    630  * \param *mol molecule with atoms and bonds
    631  * \param RestrictedKeySet Restricted vertex set to use in context of molecule
    632  */
    633 void FillSPListandLabelVertices(int Order, struct UniqueFragments &FragmentSearch, molecule *mol, KeySet RestrictedKeySet)
    634 {
    635   // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
    636   // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
    637   // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
    638   // (EdgeinSPLevel) of this tree ...
    639   // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
    640   // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
    641   int AtomKeyNr = -1;
    642   atom *Walker = NULL;
    643   atom *OtherWalker = NULL;
    644   atom *Predecessor = NULL;
    645   bond *Binder = NULL;
    646   int RootKeyNr = FragmentSearch.Root->GetTrueFather()->getNr();
    647   int RemainingWalkers = -1;
    648   int SP = -1;
    649 
    650   DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
    651   for (SP = 0; SP < (Order-1); SP++) {
    652     DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << FragmentSearch.BondsPerSPCount[SP] << " item(s)");
    653     if (SP > 0) {
    654       DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << FragmentSearch.BondsPerSPCount[SP-1] << " item(s)." << endl);
    655       FragmentSearch.BondsPerSPCount[SP] = 0;
    656     } else
    657       DoLog(0) && (Log() << Verbose(0) << "." << endl);
    658 
    659     RemainingWalkers = FragmentSearch.BondsPerSPCount[SP];
    660     for (UniqueFragments::BondsPerSP::const_iterator CurrentEdge = FragmentSearch.BondsPerSPList[SP].begin();
    661         CurrentEdge != FragmentSearch.BondsPerSPList[SP].end();
    662         ++CurrentEdge) { /// start till end of this SP level's list
    663       RemainingWalkers--;
    664       Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
    665       Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
    666       AtomKeyNr = Walker->getNr();
    667       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);
    668       // check for new sp level
    669       // go through all its bonds
    670       DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
    671       const BondList& ListOfBonds = Walker->getListOfBonds();
    672       for (BondList::const_iterator Runner = ListOfBonds.begin();
    673           Runner != ListOfBonds.end();
    674           ++Runner) {
    675         OtherWalker = (*Runner)->GetOtherAtom(Walker);
    676         if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
    677   #ifdef ADDHYDROGEN
    678          && (OtherWalker->getType()->getAtomicNumber() != 1)
    679   #endif
    680                                                               ) {  // skip hydrogens and restrict to fragment
    681           DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);
    682           // set the label if not set (and push on root stack as well)
    683           if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
    684             FragmentSearch.ShortestPathList[OtherWalker->getNr()] = SP+1;
    685             DoLog(3) && (Log() << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->getNr()] << "." << endl);
    686             // add the bond in between to the SP list
    687             Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
    688             FragmentSearch.BondsPerSPList[SP+1].push_back(Binder);
    689             FragmentSearch.BondsPerSPCount[SP+1]++;
    690             DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl);
    691           } else {
    692             if (OtherWalker != Predecessor)
    693               DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);
    694             else
    695               DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
    696           }
    697         } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
    698       }
    699     }
    700   }
    701 };
    702 
    703 /** prints the Bonds per Shortest Path list in UniqueFragments.
    704  * \param *out output stream
    705  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    706  * \param FragmentSearch UniqueFragments
    707  */
    708 void OutputSPList(int Order, struct UniqueFragments &FragmentSearch)
    709 {
    710   DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
    711   for(int i=1;i<Order;i++) {    // skip the root edge in the printing
    712     DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
    713     for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
    714         Binder != FragmentSearch.BondsPerSPList[i].end();
    715         ++Binder) {
    716       DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
    717     }
    718   }
    719 };
    720 
    721 /** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists.
    722  * \param *out output stream
    723  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    724  * \param FragmentSearch UniqueFragments
    725  */
    726 int CountNumbersInBondsList(int Order, struct UniqueFragments &FragmentSearch)
    727 {
    728   int SP = -1;  // the Root <-> Root edge must be subtracted!
    729   for(int i=Order;i--;) { // sum up all found edges
    730     for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
    731         Binder != FragmentSearch.BondsPerSPList[i].end();
    732         ++Binder) {
    733       SP++;
    734     }
    735   }
    736   return SP;
    737 };
    738548
    739549bool KeyCompare::operator() (const KeySet SubgraphA, const KeySet SubgraphB) const
  • src/Fragmentation/fragmentation_helpers.hpp

    rd9a032 ra03d25  
    4141int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex);
    4242void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex);
    43 void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch);
    44 void FreeSPList(int Order, struct UniqueFragments &FragmentSearch);
    45 void SetSPList(int Order, struct UniqueFragments &FragmentSearch);
    46 void ResetSPList(int Order, struct UniqueFragments &FragmentSearch);
    47 void FillSPListandLabelVertices(int Order, struct UniqueFragments &FragmentSearch, molecule *mol, KeySet RestrictedKeySet);
    48 void OutputSPList(int Order, struct UniqueFragments &FragmentSearch);
    49 int CountNumbersInBondsList(int Order, struct UniqueFragments &FragmentSearch);
     43
    5044int CombineAllOrderListIntoOne(Graph *&FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
    5145void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol);
  • src/graph.cpp

    rd9a032 ra03d25  
    8787//};
    8888
    89 /** Checking whether KeySet is not already present in Graph, if so just adds factor.
    90  * \param *out output stream for debugging
    91  * \param &set KeySet to insert
    92  * \param &graph Graph to insert into
    93  * \param *counter pointer to unique fragment count
    94  * \param factor energy factor for the fragment
    95  */
    96 void InsertFragmentIntoGraph(struct UniqueFragments *Fragment)
    97 {
    98   GraphTestPair testGraphInsert;
    99 
    100   testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,Fragment->TEFactor)));  // store fragment number and current factor
    101   if (testGraphInsert.second) {
    102     DoLog(2) && (Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl);
    103     Fragment->FragmentCounter++;
    104   } else {
    105     DoLog(2) && (Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl);
    106     ((*(testGraphInsert.first)).second).second += Fragment->TEFactor;  // increase the "created" counter
    107     DoLog(2) && (Log() << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl);
    108   }
    109 };
    11089//void inline InsertIntoGraph(KeyStack &stack, Graph &graph, int *counter, double factor)
    11190//{
  • src/graph.hpp

    rd9a032 ra03d25  
    3131class Node;
    3232class Edge;
     33class UniqueFragments;
    3334
    3435/********************************************** definitions *********************************/
     
    5657
    5758//bool operator < (KeySet SubgraphA, KeySet SubgraphB);   //note: this declaration is important, otherwise normal < is used (producing wrong order)
    58 void InsertFragmentIntoGraph(struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
    5959void InsertGraphIntoGraph(Graph &graph1, Graph &graph2, int *counter);  // Insert all KeySet's in a Graph into another Graph
    6060
    61 /** Structure containing all values in power set combination generation.
    62  */
    63 struct UniqueFragments {
    64   typedef std::list<bond*> BondsPerSP;
    65   typedef std::vector< BondsPerSP > AllSPBonds;
    66 
    67   config *configuration;
    68   atom *Root;
    69   Graph *Leaflet;
    70   KeySet *FragmentSet;
    71   int ANOVAOrder;
    72   int FragmentCounter;
    73   int CurrentIndex;
    74   double TEFactor;
    75   int *ShortestPathList;
    76   bool **UsedList;
    77   AllSPBonds BondsPerSPList;
    78   int *BondsPerSPCount;
    79 };
    8061
    8162/********************************************** declarations *******************************/
  • src/molecule_fragmentation.cpp

    rd9a032 ra03d25  
    3131#include "Element/periodentafel.hpp"
    3232#include "Fragmentation/fragmentation_helpers.hpp"
     33#include "Fragmentation/UniqueFragments.hpp"
    3334#include "Graph/BondGraph.hpp"
    3435#include "Graph/CheckAgainstAdjacencyFile.hpp"
     
    732733          DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");
    733734        DoLog(0) && (Log() << Verbose(0) << endl);
    734         InsertFragmentIntoGraph(FragmentSearch);
     735        FragmentSearch->InsertFragmentIntoGraph();
    735736      }
    736737
     
    769770  DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl);
    770771
    771   SetSPList(Order, FragmentSearch);
     772  FragmentSearch.SetSPList(Order);
    772773
    773774  // do a BFS search to fill the SP lists and label the found vertices
    774   FillSPListandLabelVertices(Order, FragmentSearch, this, RestrictedKeySet);
     775  FragmentSearch.FillSPListandLabelVertices(Order, RestrictedKeySet);
    775776
    776777  // outputting all list for debugging
    777   OutputSPList(Order, FragmentSearch);
     778  FragmentSearch.OutputSPList(Order);
    778779
    779780  // creating fragments with the found edge sets  (may be done in reverse order, faster)
    780   int SP = CountNumbersInBondsList(Order, FragmentSearch);
     781  int SP = FragmentSearch.CountNumbersInBondsList(Order);
    781782  DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl);
    782783  if (SP >= (Order-1)) {
     
    804805
    805806  // free'ing the bonds lists
    806   ResetSPList(Order, FragmentSearch);
     807  FragmentSearch.ResetSPList(Order);
    807808
    808809  // return list
     
    856857  }
    857858
    858   // initialise the fragments structure
    859   FragmentSearch.FragmentCounter = 0;
    860   FragmentSearch.FragmentSet = new KeySet;
    861   FragmentSearch.Root = FindAtom(RootKeyNr);
    862   FragmentSearch.ShortestPathList = new int[getAtomCount()];
    863   for (int i=getAtomCount();i--;) {
    864     FragmentSearch.ShortestPathList[i] = -1;
    865   }
     859  FragmentSearch.Init(FindAtom(RootKeyNr), getAtomCount());
    866860
    867861  // Construct the complete KeySet which we need for topmost level only (but for all Roots)
     
    890884
    891885      // initialise Order-dependent entries of UniqueFragments structure
    892       InitialiseSPList(Order, FragmentSearch);
     886      FragmentSearch.InitialiseSPList(Order);
    893887
    894888      // allocate memory for all lower level orders in this 1D-array of ptrs
     
    924918
    925919      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    926       FreeSPList(Order, FragmentSearch);
     920      FragmentSearch.FreeSPList(Order);
    927921    }
    928922  }
     
    932926
    933927  // cleanup FragmentSearch structure
    934   delete[](FragmentSearch.ShortestPathList);
    935   delete(FragmentSearch.FragmentSet);
     928  FragmentSearch.Cleanup();
    936929
    937930  // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein)
Note: See TracChangeset for help on using the changeset viewer.