source: src/Fragmentation/BondsPerShortestPath.cpp@ 30438f

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 30438f was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

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