Changeset a03d25
- Timestamp:
- Oct 25, 2011, 12:08:03 PM (13 years ago)
- 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)
- Location:
- src
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Makefile.am
rd9a032 ra03d25 9 9 Fragmentation/HessianMatrix.cpp \ 10 10 Fragmentation/KeySetsContainer.cpp \ 11 Fragmentation/MatrixContainer.cpp 11 Fragmentation/MatrixContainer.cpp \ 12 Fragmentation/UniqueFragments.cpp 12 13 13 14 FRAGMENTATIONHEADER = \ … … 19 20 Fragmentation/HessianMatrix.hpp \ 20 21 Fragmentation/KeySetsContainer.hpp \ 21 Fragmentation/MatrixContainer.hpp 22 Fragmentation/MatrixContainer.hpp \ 23 Fragmentation/UniqueFragments.hpp 22 24 23 25 -
src/Fragmentation/fragmentation_helpers.cpp
rd9a032 ra03d25 546 546 }; 547 547 548 /** Allocates memory for UniqueFragments::BondsPerSPList.549 * \param *out output stream550 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation551 * \param FragmentSearch UniqueFragments552 * \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 stream565 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation566 * \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) and576 * adds initial bond UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList577 * \param *out output stream578 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation579 * \param FragmentSearch UniqueFragments580 * \sa FreeSPList()581 */582 void SetSPList(int Order, struct UniqueFragments &FragmentSearch)583 {584 // prepare Label and SP arrays of the BFS search585 FragmentSearch.ShortestPathList[FragmentSearch.Root->getNr()] = 0;586 587 // prepare root level (SP = 0) and a loop bond denoting Root588 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 stream597 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation598 * \param FragmentSearch UniqueFragments599 * \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 local610 FragmentSearch.ShortestPathList[(*iter)->leftatom->getNr()] = -1;611 FragmentSearch.ShortestPathList[(*iter)->rightatom->getNr()] = -1;612 }613 // delete added bonds614 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 node621 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 stream628 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation629 * \param FragmentSearch UniqueFragments630 * \param *mol molecule with atoms and bonds631 * \param RestrictedKeySet Restricted vertex set to use in context of molecule632 */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 into636 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning637 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth638 // (EdgeinSPLevel) of this tree ...639 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence640 // 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 } else657 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 list663 RemainingWalkers--;664 Walker = (*CurrentEdge)->rightatom; // rightatom is always the one more distant665 Predecessor = (*CurrentEdge)->leftatom; // ... and leftatom is predecessor666 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 level669 // go through all its bonds670 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 ADDHYDROGEN678 && (OtherWalker->getType()->getAtomicNumber() != 1)679 #endif680 ) { // skip hydrogens and restrict to fragment681 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's684 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 list687 Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant688 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 else695 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 stream705 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation706 * \param FragmentSearch UniqueFragments707 */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 printing712 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 stream723 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation724 * \param FragmentSearch UniqueFragments725 */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 edges730 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 };738 548 739 549 bool KeyCompare::operator() (const KeySet SubgraphA, const KeySet SubgraphB) const -
src/Fragmentation/fragmentation_helpers.hpp
rd9a032 ra03d25 41 41 int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex); 42 42 void 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 50 44 int CombineAllOrderListIntoOne(Graph *&FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol); 51 45 void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol); -
src/graph.cpp
rd9a032 ra03d25 87 87 //}; 88 88 89 /** Checking whether KeySet is not already present in Graph, if so just adds factor.90 * \param *out output stream for debugging91 * \param &set KeySet to insert92 * \param &graph Graph to insert into93 * \param *counter pointer to unique fragment count94 * \param factor energy factor for the fragment95 */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 factor101 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" counter107 DoLog(2) && (Log() << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl);108 }109 };110 89 //void inline InsertIntoGraph(KeyStack &stack, Graph &graph, int *counter, double factor) 111 90 //{ -
src/graph.hpp
rd9a032 ra03d25 31 31 class Node; 32 32 class Edge; 33 class UniqueFragments; 33 34 34 35 /********************************************** definitions *********************************/ … … 56 57 57 58 //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 Graph59 59 void InsertGraphIntoGraph(Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph 60 60 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 };80 61 81 62 /********************************************** declarations *******************************/ -
src/molecule_fragmentation.cpp
rd9a032 ra03d25 31 31 #include "Element/periodentafel.hpp" 32 32 #include "Fragmentation/fragmentation_helpers.hpp" 33 #include "Fragmentation/UniqueFragments.hpp" 33 34 #include "Graph/BondGraph.hpp" 34 35 #include "Graph/CheckAgainstAdjacencyFile.hpp" … … 732 733 DoLog(0) && (Log() << Verbose(0) << (*runner) << " "); 733 734 DoLog(0) && (Log() << Verbose(0) << endl); 734 InsertFragmentIntoGraph(FragmentSearch);735 FragmentSearch->InsertFragmentIntoGraph(); 735 736 } 736 737 … … 769 770 DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl); 770 771 771 SetSPList(Order, FragmentSearch);772 FragmentSearch.SetSPList(Order); 772 773 773 774 // do a BFS search to fill the SP lists and label the found vertices 774 F illSPListandLabelVertices(Order, FragmentSearch, this, RestrictedKeySet);775 FragmentSearch.FillSPListandLabelVertices(Order, RestrictedKeySet); 775 776 776 777 // outputting all list for debugging 777 OutputSPList(Order, FragmentSearch);778 FragmentSearch.OutputSPList(Order); 778 779 779 780 // 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); 781 782 DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl); 782 783 if (SP >= (Order-1)) { … … 804 805 805 806 // free'ing the bonds lists 806 ResetSPList(Order, FragmentSearch);807 FragmentSearch.ResetSPList(Order); 807 808 808 809 // return list … … 856 857 } 857 858 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()); 866 860 867 861 // Construct the complete KeySet which we need for topmost level only (but for all Roots) … … 890 884 891 885 // initialise Order-dependent entries of UniqueFragments structure 892 InitialiseSPList(Order, FragmentSearch);886 FragmentSearch.InitialiseSPList(Order); 893 887 894 888 // allocate memory for all lower level orders in this 1D-array of ptrs … … 924 918 925 919 // free Order-dependent entries of UniqueFragments structure for next loop cycle 926 Fr eeSPList(Order, FragmentSearch);920 FragmentSearch.FreeSPList(Order); 927 921 } 928 922 } … … 932 926 933 927 // cleanup FragmentSearch structure 934 delete[](FragmentSearch.ShortestPathList); 935 delete(FragmentSearch.FragmentSet); 928 FragmentSearch.Cleanup(); 936 929 937 930 // 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.