source: src/Fragmentation/BondsPerShortestPath.cpp@ 851be8

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
Last change on this file since 851be8 was f0674a, checked in by Frederik Heber <heber@…>, 14 years ago

Extracted KeySet from graph.hpp and made into distinct class.

  • member function operator<() replaces former KeyCompare struct.
  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * BondsPerShortestPath.cpp
10 *
11 * Created on: Oct 18, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "BondsPerShortestPath.hpp"
23
24#include "CodePatterns/Log.hpp"
25
26#include "atom.hpp"
27#include "Bond/bond.hpp"
28#include "Element/element.hpp"
29#include "Fragmentation/KeySet.hpp"
30
31BondsPerShortestPath::BondsPerShortestPath(int _Order) :
32 Order(_Order)
33{
34 InitialiseSPList();
35}
36
37BondsPerShortestPath::~BondsPerShortestPath()
38{
39 // free Order-dependent entries of UniqueFragments structure for next loop cycle
40 FreeSPList();
41}
42
43/** Allocates memory for BondsPerShortestPath::BondsPerSPList.
44 * \sa BondsPerShortestPath::FreeSPList()
45 */
46void BondsPerShortestPath::InitialiseSPList()
47{
48 BondsPerSPList.resize(Order);
49 BondsPerSPCount = new int[Order];
50 for (int i=Order;i--;) {
51 BondsPerSPCount[i] = 0;
52 }
53};
54
55/** Free's memory for for BondsPerShortestPath::BondsPerSPList.
56 * \sa BondsPerShortestPath::InitialiseSPList()
57 */
58void BondsPerShortestPath::FreeSPList()
59{
60 delete[](BondsPerSPCount);
61};
62
63/** Sets FragmenSearch to initial value.
64 * Sets BondsPerShortestPath::ShortestPathList entries to zero, BondsPerShortestPath::BondsPerSPCount to zero (except zero level to 1) and
65 * adds initial bond BondsPerShortestPath::Root to BondsPerShortestPath::Root to BondsPerShortestPath::BondsPerSPList
66 * \param *_Root root node, self loop becomes first bond
67 * \sa BondsPerShortestPath::FreeSPList()
68 */
69void BondsPerShortestPath::SetSPList(atom *_Root)
70{
71 // prepare root level (SP = 0) and a loop bond denoting Root
72 for (int i=Order;i--;)
73 BondsPerSPCount[i] = 0;
74 BondsPerSPCount[0] = 1;
75 bond *Binder = new bond(_Root, _Root);
76 BondsPerSPList[0].push_back(Binder);
77};
78
79/** Resets BondsPerShortestPath::ShortestPathList and cleans bonds from BondsPerShortestPath::BondsPerSPList.
80 * \sa BondsPerShortestPath::InitialiseSPList()
81 */
82void BondsPerShortestPath::ResetSPList()
83{
84 DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
85 for(int i=Order;i--;) {
86 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
87 // delete added bonds
88 for (BondsPerSP::iterator iter = BondsPerSPList[i].begin();
89 iter != BondsPerSPList[i].end();
90 ++iter) {
91 delete(*iter);
92 }
93 BondsPerSPList[i].clear();
94 // also start and end node
95 DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
96 }
97};
98
99
100/** Fills the Bonds per Shortest Path List and set the vertex labels.
101 * \param _RootKeyNr index of root node
102 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
103 */
104void BondsPerShortestPath::FillSPListandLabelVertices(int _RootKeyNr, KeySet &RestrictedKeySet)
105{
106 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
107 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
108 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
109 // (EdgeinSPLevel) of this tree ...
110 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
111 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
112 int AtomKeyNr = -1;
113 atom *Walker = NULL;
114 atom *OtherWalker = NULL;
115 atom *Predecessor = NULL;
116 bond *Binder = NULL;
117 int RootKeyNr = _RootKeyNr;
118 int RemainingWalkers = -1;
119 int SP = -1;
120
121 DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
122 for (SP = 0; SP < (Order-1); SP++) {
123 DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)");
124 if (SP > 0) {
125 DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s)." << endl);
126 BondsPerSPCount[SP] = 0;
127 } else
128 DoLog(0) && (Log() << Verbose(0) << "." << endl);
129
130 RemainingWalkers = BondsPerSPCount[SP];
131 for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
132 CurrentEdge != BondsPerSPList[SP].end();
133 ++CurrentEdge) { /// start till end of this SP level's list
134 RemainingWalkers--;
135 Walker = (*CurrentEdge)->rightatom; // rightatom is always the one more distant
136 Predecessor = (*CurrentEdge)->leftatom; // ... and leftatom is predecessor
137 AtomKeyNr = Walker->getNr();
138 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);
139 // check for new sp level
140 // go through all its bonds
141 DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
142 const BondList& ListOfBonds = Walker->getListOfBonds();
143 for (BondList::const_iterator Runner = ListOfBonds.begin();
144 Runner != ListOfBonds.end();
145 ++Runner) {
146 OtherWalker = (*Runner)->GetOtherAtom(Walker);
147 if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
148 #ifdef ADDHYDROGEN
149 && (OtherWalker->getType()->getAtomicNumber() != 1)
150 #endif
151 ) { // skip hydrogens and restrict to fragment
152 DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);
153 // set the label if not set (and push on root stack as well)
154 if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
155 // add the bond in between to the SP list
156 Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
157 BondsPerSPList[SP+1].push_back(Binder);
158 BondsPerSPCount[SP+1]++;
159 DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s)." << endl);
160 } else {
161 if (OtherWalker != Predecessor)
162 DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);
163 else
164 DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
165 }
166 } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
167 }
168 }
169 }
170};
171
172/** prints the Bonds per Shortest Path list in BondsPerShortestPath.
173 */
174void BondsPerShortestPath::OutputSPList()
175{
176 DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
177 for(int i=1;i<Order;i++) { // skip the root edge in the printing
178 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
179 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
180 Binder != BondsPerSPList[i].end();
181 ++Binder) {
182 DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
183 }
184 }
185};
186
187/** Simply counts all bonds in all BondsPerShortestPath::BondsPerSPList lists.
188 */
189int BondsPerShortestPath::CountNumbersInBondsList()
190{
191 int SP = -1; // the Root <-> Root edge must be subtracted!
192 for(int i=Order;i--;) { // sum up all found edges
193 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
194 Binder != BondsPerSPList[i].end();
195 ++Binder) {
196 SP++;
197 }
198 }
199 return SP;
200};
201
202/** Getter for BondsPerShortestPath::Order.
203 *
204 * @return returns BondsPerShortestPath::Order
205 */
206int BondsPerShortestPath::getOrder() const
207{
208 return Order;
209}
Note: See TracBrowser for help on using the repository browser.