source: src/Fragmentation/BondsPerShortestPath.cpp@ 0cd8cf

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 0cd8cf was 8ac66b4, checked in by Frederik Heber <heber@…>, 12 years ago

VERBOSE: Lots of changes to verbosity of fragmentation process.

  • Property mode set to 100644
File size: 8.5 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * BondsPerShortestPath.cpp
25 *
26 * Created on: Oct 18, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "BondsPerShortestPath.hpp"
38
39#include <sstream>
40
41#include "CodePatterns/Log.hpp"
42
43#include "Atom/atom.hpp"
44#include "Bond/bond.hpp"
45#include "Element/element.hpp"
46#include "Fragmentation/KeySet.hpp"
47
48BondsPerShortestPath::BondsPerShortestPath(int _Order) :
49 Order(_Order)
50{
51 InitialiseSPList();
52}
53
54BondsPerShortestPath::~BondsPerShortestPath()
55{
56 // free Order-dependent entries of UniqueFragments structure for next loop cycle
57 FreeSPList();
58}
59
60/** Allocates memory for BondsPerShortestPath::BondsPerSPList.
61 * \sa BondsPerShortestPath::FreeSPList()
62 */
63void BondsPerShortestPath::InitialiseSPList()
64{
65 BondsPerSPList.resize(Order);
66 BondsPerSPCount = new int[Order];
67 for (int i=Order;i--;) {
68 BondsPerSPCount[i] = 0;
69 }
70};
71
72/** Free's memory for for BondsPerShortestPath::BondsPerSPList.
73 * \sa BondsPerShortestPath::InitialiseSPList()
74 */
75void BondsPerShortestPath::FreeSPList()
76{
77 delete[](BondsPerSPCount);
78};
79
80/** Sets FragmenSearch to initial value.
81 * Sets BondsPerShortestPath::ShortestPathList entries to zero, BondsPerShortestPath::BondsPerSPCount to zero (except zero level to 1) and
82 * adds initial bond BondsPerShortestPath::Root to BondsPerShortestPath::Root to BondsPerShortestPath::BondsPerSPList
83 * \param *_Root root node, self loop becomes first bond
84 * \sa BondsPerShortestPath::FreeSPList()
85 */
86void BondsPerShortestPath::SetSPList(atom *_Root)
87{
88 // prepare root level (SP = 0) and a loop bond denoting Root
89 for (int i=Order;i--;)
90 BondsPerSPCount[i] = 0;
91 BondsPerSPCount[0] = 1;
92 bond::ptr Binder(new bond(_Root, _Root));
93 BondsPerSPList[0].push_back(Binder);
94};
95
96/** Resets BondsPerShortestPath::ShortestPathList and cleans bonds from BondsPerShortestPath::BondsPerSPList.
97 * \sa BondsPerShortestPath::InitialiseSPList()
98 */
99void BondsPerShortestPath::ResetSPList()
100{
101 LOG(1, "INFO: Free'ing all found lists and resetting index lists");
102 for(int i=Order;i--;) {
103 std::stringstream output;
104 output << "Current SP level is " << i << ": ";
105 // delete added bonds
106 for (BondsPerSP::iterator iter = BondsPerSPList[i].begin();
107 iter != BondsPerSPList[i].end();
108 ++iter) {
109 // TODO: Hack because we have not registered bond's in BondsPerSPList with atoms
110 (*iter)->leftatom = NULL;
111 (*iter)->rightatom = NULL;
112 }
113 BondsPerSPList[i].clear();
114 // also start and end node
115 output << "cleaned.";
116 LOG(1, output.str());
117 }
118};
119
120
121/** Fills the Bonds per Shortest Path List and set the vertex labels.
122 * \param _RootKeyNr index of root node
123 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
124 * \param treatment this tells whether to treat hydrogen special or not.
125 */
126void BondsPerShortestPath::FillSPListandLabelVertices(int _RootKeyNr, KeySet &RestrictedKeySet, const enum HydrogenTreatment treatment)
127{
128 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
129 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
130 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
131 // (EdgeinSPLevel) of this tree ...
132 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
133 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
134 int AtomKeyNr = -1;
135 atom *Walker = NULL;
136 atom *OtherWalker = NULL;
137 atom *Predecessor = NULL;
138 bond::ptr Binder;
139 int RootKeyNr = _RootKeyNr;
140 int RemainingWalkers = -1;
141 int SP = -1;
142
143 LOG(0, "INFO: Starting BFS analysis ...");
144 for (SP = 0; SP < (Order-1); SP++) {
145 {
146 std::stringstream output;
147 output << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)";
148 if (SP > 0) {
149 output << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s).";
150 BondsPerSPCount[SP] = 0;
151 } else
152 output << ".";
153 LOG(1, output.str());
154 }
155
156 RemainingWalkers = BondsPerSPCount[SP];
157 for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
158 CurrentEdge != BondsPerSPList[SP].end();
159 ++CurrentEdge) { /// start till end of this SP level's list
160 RemainingWalkers--;
161 Walker = (*CurrentEdge)->rightatom; // rightatom is always the one more distant
162 Predecessor = (*CurrentEdge)->leftatom; // ... and leftatom is predecessor
163 AtomKeyNr = Walker->getNr();
164 LOG(1, "INFO: Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level.");
165 // check for new sp level
166 // go through all its bonds
167// LOG(2, "Going through all bonds of Walker.");
168 const BondList& ListOfBonds = Walker->getListOfBonds();
169 for (BondList::const_iterator Runner = ListOfBonds.begin();
170 Runner != ListOfBonds.end();
171 ++Runner) {
172 OtherWalker = (*Runner)->GetOtherAtom(Walker);
173 if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
174 // skip hydrogens if desired and restrict to fragment
175 && ((treatment == IncludeHydrogen) || (OtherWalker->getType()->getAtomicNumber() != 1))) {
176 LOG(2, "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << ".");
177 // set the label if not set (and push on root stack as well)
178 if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
179 // add the bond in between to the SP list
180 Binder.reset(new bond(Walker, OtherWalker)); // create a new bond in such a manner, that bond::rightatom is always the one more distant
181 BondsPerSPList[SP+1].push_back(Binder);
182 BondsPerSPCount[SP+1]++;
183 LOG(3, "DEBUG: Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s).");
184 } else {
185 if (OtherWalker != Predecessor)
186 LOG(3, "DEBUG: Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << ".");
187 else
188 LOG(3, "DEBUG: This is my predecessor " << *Predecessor << ".");
189 }
190 } else LOG(2, "DEBUG: Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << ".");
191 }
192 }
193 }
194};
195
196/** prints the Bonds per Shortest Path list in BondsPerShortestPath.
197 */
198void BondsPerShortestPath::OutputSPList()
199{
200 LOG(2, "DEBUG: Printing all found lists.");
201 for(int i=1;i<Order;i++) { // skip the root edge in the printing
202 LOG(2, "\tCurrent SP level is " << i << ".");
203 std::stringstream output;
204 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
205 Binder != BondsPerSPList[i].end();
206 ++Binder) {
207 output << "\t" << *Binder;
208 }
209 output << std::endl;
210 LOG(2, output.str());
211 }
212};
213
214/** Simply counts all bonds in all BondsPerShortestPath::BondsPerSPList lists.
215 */
216int BondsPerShortestPath::CountNumbersInBondsList()
217{
218 int SP = -1; // the Root <-> Root edge must be subtracted!
219 for(int i=Order;i--;) { // sum up all found edges
220 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
221 Binder != BondsPerSPList[i].end();
222 ++Binder) {
223 SP++;
224 }
225 }
226 return SP;
227};
Note: See TracBrowser for help on using the repository browser.