source: src/Fragmentation/BondsPerShortestPath.cpp@ dcbb5d

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 dcbb5d was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.4 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 *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(0, "Free'ing all found lists. and resetting index lists");
102 std::stringstream output;
103 for(int i=Order;i--;) {
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 delete(*iter);
110 }
111 BondsPerSPList[i].clear();
112 // also start and end node
113 output << "cleaned.";
114 }
115 LOG(1, output.str());
116};
117
118
119/** Fills the Bonds per Shortest Path List and set the vertex labels.
120 * \param _RootKeyNr index of root node
121 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
122 * \param saturation this tells whether to treat hydrogen special or not.
123 */
124void BondsPerShortestPath::FillSPListandLabelVertices(int _RootKeyNr, KeySet &RestrictedKeySet, const enum HydrogenSaturation saturation)
125{
126 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
127 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
128 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
129 // (EdgeinSPLevel) of this tree ...
130 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
131 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
132 int AtomKeyNr = -1;
133 atom *Walker = NULL;
134 atom *OtherWalker = NULL;
135 atom *Predecessor = NULL;
136 bond *Binder = NULL;
137 int RootKeyNr = _RootKeyNr;
138 int RemainingWalkers = -1;
139 int SP = -1;
140
141 LOG(0, "Starting BFS analysis ...");
142 for (SP = 0; SP < (Order-1); SP++) {
143 {
144 std::stringstream output;
145 output << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)";
146 if (SP > 0) {
147 output << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s).";
148 BondsPerSPCount[SP] = 0;
149 } else
150 output << ".";
151 LOG(1, output.str());
152 }
153
154 RemainingWalkers = BondsPerSPCount[SP];
155 for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();
156 CurrentEdge != BondsPerSPList[SP].end();
157 ++CurrentEdge) { /// start till end of this SP level's list
158 RemainingWalkers--;
159 Walker = (*CurrentEdge)->rightatom; // rightatom is always the one more distant
160 Predecessor = (*CurrentEdge)->leftatom; // ... and leftatom is predecessor
161 AtomKeyNr = Walker->getNr();
162 LOG(0, "Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level.");
163 // check for new sp level
164 // go through all its bonds
165 LOG(1, "Going through all bonds of Walker.");
166 const BondList& ListOfBonds = Walker->getListOfBonds();
167 for (BondList::const_iterator Runner = ListOfBonds.begin();
168 Runner != ListOfBonds.end();
169 ++Runner) {
170 OtherWalker = (*Runner)->GetOtherAtom(Walker);
171 if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())
172 // skip hydrogens if desired and restrict to fragment
173 && ((saturation == DontSaturate) || (OtherWalker->getType()->getAtomicNumber() != 1))) {
174 LOG(2, "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << ".");
175 // set the label if not set (and push on root stack as well)
176 if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
177 // add the bond in between to the SP list
178 Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
179 BondsPerSPList[SP+1].push_back(Binder);
180 BondsPerSPCount[SP+1]++;
181 LOG(3, "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s).");
182 } else {
183 if (OtherWalker != Predecessor)
184 LOG(3, "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << ".");
185 else
186 LOG(3, "This is my predecessor " << *Predecessor << ".");
187 }
188 } else LOG(2, "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << ".");
189 }
190 }
191 }
192};
193
194/** prints the Bonds per Shortest Path list in BondsPerShortestPath.
195 */
196void BondsPerShortestPath::OutputSPList()
197{
198 LOG(0, "Printing all found lists.");
199 for(int i=1;i<Order;i++) { // skip the root edge in the printing
200 LOG(1, "Current SP level is " << i << ".");
201 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
202 Binder != BondsPerSPList[i].end();
203 ++Binder) {
204 LOG(2, *Binder);
205 }
206 }
207};
208
209/** Simply counts all bonds in all BondsPerShortestPath::BondsPerSPList lists.
210 */
211int BondsPerShortestPath::CountNumbersInBondsList()
212{
213 int SP = -1; // the Root <-> Root edge must be subtracted!
214 for(int i=Order;i--;) { // sum up all found edges
215 for (BondsPerShortestPath::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();
216 Binder != BondsPerSPList[i].end();
217 ++Binder) {
218 SP++;
219 }
220 }
221 return SP;
222};
223
224/** Getter for BondsPerShortestPath::Order.
225 *
226 * @return returns BondsPerShortestPath::Order
227 */
228int BondsPerShortestPath::getOrder() const
229{
230 return Order;
231}
Note: See TracBrowser for help on using the repository browser.