source: src/Fragmentation/BondsPerShortestPath.cpp@ 246e13

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
Last change on this file since 246e13 was 212c179, checked in by Frederik Heber <heber@…>, 14 years ago

Placed all functions related to BondsPerSPList into own class BondsPerShortestPath.

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