Changeset a03d25 for src/Fragmentation


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/Fragmentation
Files:
2 added
3 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);
Note: See TracChangeset for help on using the changeset viewer.