source: src/molecule_graph.cpp@ 458c31

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 458c31 was 458c31, checked in by Frederik Heber <heber@…>, 15 years ago

molecule::BondCount is now Cachable and private.

  • Property mode set to 100644
File size: 67.8 KB
RevLine 
[bcf653]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
[cee0b57]8/*
9 * molecule_graph.cpp
10 *
11 * Created on: Oct 5, 2009
12 * Author: heber
13 */
14
[bf3817]15// include config.h
[aafd77]16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[ad011c]20#include "CodePatterns/MemDebug.hpp"
[112b09]21
[a564be]22#include <stack>
23
[f66195]24#include "atom.hpp"
25#include "bond.hpp"
[b70721]26#include "bondgraph.hpp"
[34c43a]27#include "Box.hpp"
28#include "CodePatterns/Assert.hpp"
29#include "CodePatterns/Info.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/Verbose.hpp"
[cee0b57]32#include "config.hpp"
[f66195]33#include "element.hpp"
[1d5afa5]34#include "Helpers/defs.hpp"
35#include "Helpers/fast_functions.hpp"
[952f38]36#include "Helpers/helpers.hpp"
[1d5afa5]37#include "LinearAlgebra/RealSpaceMatrix.hpp"
[b8b75d]38#include "linkedcell.hpp"
[cee0b57]39#include "molecule.hpp"
[34c43a]40#include "PointCloudAdaptor.hpp"
[b34306]41#include "World.hpp"
[9d83b6]42#include "WorldTime.hpp"
[1d5afa5]43
44#define MAXBONDS 8
45
[9eefda]46struct BFSAccounting
47{
48 atom **PredecessorList;
49 int *ShortestPathList;
50 enum Shading *ColorList;
[a564be]51 std::deque<atom *> *BFSStack;
52 std::deque<atom *> *TouchedStack;
[9eefda]53 int AtomCount;
54 int BondOrder;
55 atom *Root;
56 bool BackStepping;
57 int CurrentGraphNr;
58 int ComponentNr;
59};
[cee0b57]60
[9eefda]61/** Accounting data for Depth First Search.
62 */
63struct DFSAccounting
64{
[a564be]65 std::deque<atom *> *AtomStack;
66 std::deque<bond *> *BackEdgeStack;
[9eefda]67 int CurrentGraphNr;
68 int ComponentNumber;
69 atom *Root;
70 bool BackStepping;
71};
72
73/************************************* Functions for class molecule *********************************/
[cee0b57]74
75/** Creates an adjacency list of the molecule.
76 * We obtain an outside file with the indices of atoms which are bondmembers.
77 */
[e138de]78void molecule::CreateAdjacencyListFromDbondFile(ifstream *input)
[cee0b57]79{
[c68c90]80 Info FunctionInfo(__func__);
[cee0b57]81 // 1 We will parse bonds out of the dbond file created by tremolo.
[44a59b]82 int atom1, atom2;
83 atom *Walker, *OtherWalker;
[c68c90]84 char line[MAXSTRINGSIZE];
[44a59b]85
[c68c90]86 if (input->fail()) {
87 DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n");
88 performCriticalExit();
[44a59b]89 };
[bd6bfa]90 doCountAtoms();
[44a59b]91
[c68c90]92 // skip header
93 input->getline(line,MAXSTRINGSIZE);
94 DoLog(1) && (Log() << Verbose(1) << "Scanning file ... \n");
[44a59b]95 while (!input->eof()) // Check whether we read everything already
96 {
[c68c90]97 input->getline(line,MAXSTRINGSIZE);
98 stringstream zeile(line);
99 zeile >> atom1;
100 zeile >> atom2;
[44a59b]101
[c68c90]102 DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl);
[9eefda]103 if (atom2 < atom1) //Sort indices of atoms in order
[a0064e]104 std::swap(atom1, atom2);
[9eefda]105 Walker = FindAtom(atom1);
[05a97c]106 ASSERT(Walker,"Could not find an atom with the ID given in dbond file");
[9eefda]107 OtherWalker = FindAtom(atom2);
[05a97c]108 ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file");
[44a59b]109 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
110 }
[9eefda]111}
[cee0b57]112
113/** Creates an adjacency list of the molecule.
114 * Generally, we use the CSD approach to bond recognition, that is the the distance
115 * between two atoms A and B must be within [Rcov(A)+Rcov(B)-t,Rcov(A)+Rcov(B)+t] with
116 * a threshold t = 0.4 Angstroem.
117 * To make it O(N log N) the function uses the linked-cell technique as follows:
118 * The procedure is step-wise:
119 * -# Remove every bond in list
120 * -# Count the atoms in the molecule with CountAtoms()
121 * -# partition cell into smaller linked cells of size \a bonddistance
122 * -# put each atom into its corresponding cell
123 * -# go through every cell, check the atoms therein against all possible bond partners in the 27 adjacent cells, add bond if true
124 * -# correct the bond degree iteratively (single->double->triple bond)
125 * -# finally print the bond list to \a *out if desired
126 * \param bonddistance length of linked cells (i.e. maximum minimal length checked)
127 * \param IsAngstroem whether coordinate system is gauged to Angstroem or Bohr radii
[b70721]128 * \param *minmaxdistance function to give upper and lower bound on whether particle is bonded to some other
129 * \param *BG BondGraph with the member function above or NULL, if just standard covalent should be used.
[cee0b57]130 */
[e138de]131void molecule::CreateAdjacencyList(double bonddistance, bool IsAngstroem, void (BondGraph::*minmaxdistance)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG)
[cee0b57]132{
[b8b75d]133 atom *Walker = NULL;
134 atom *OtherWalker = NULL;
135 int n[NDIM];
[b70721]136 double MinDistance, MaxDistance;
[b8b75d]137 LinkedCell *LC = NULL;
[b70721]138 bool free_BG = false;
[014475]139 Box &domain = World::getInstance().getDomain();
[b70721]140
[a67d19]141 DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl);
[cee0b57]142 // remove every bond from the list
[9d83b6]143 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
144 BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
145 for(BondList::iterator BondRunner = ListOfBonds.begin();
146 !ListOfBonds.empty();
147 BondRunner = ListOfBonds.begin())
[e08c46]148 if ((*BondRunner)->leftatom == *AtomRunner)
149 delete((*BondRunner));
[9d83b6]150 }
[cee0b57]151
152 // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
[a7b761b]153 DoLog(1) && (Log() << Verbose(1) << "AtomCount " << getAtomCount() << " and bonddistance is " << bonddistance << "." << endl);
[cee0b57]154
[c66537]155 if ((getAtomCount() > 1) && (bonddistance > 0.1)) {
[a67d19]156 DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
[caa06ef]157 PointCloudAdaptor<molecule> cloud(this, name);
[34c43a]158 LC = new LinkedCell(cloud, bonddistance);
[cee0b57]159
[5309ba]160 // create a list to map Tesselpoint::Nr to atom *
[a67d19]161 DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
[f2bb0f]162
[53731f]163 // set numbers for atoms that can later be used
164 int i=0;
165 for(internal_iterator iter = atoms.begin();iter!= atoms.end(); ++iter){
[a479fa]166 (*iter)->setNr(i++);
[cee0b57]167 }
168
169 // 3a. go through every cell
[a67d19]170 DoLog(2) && (Log() << Verbose(2) << "Celling ... " << endl);
[b8b75d]171 for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++)
172 for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++)
173 for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) {
[34c43a]174 const TesselPointSTLList *List = LC->GetCurrentCell();
[4e855e]175 Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
[b8b75d]176 if (List != NULL) {
[34c43a]177 for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
[f2bb0f]178 Walker = dynamic_cast<atom*>(*Runner);
179 ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode");
[4e855e]180 Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
[cee0b57]181 // 3c. check for possible bond between each atom in this and every one in the 27 cells
[9eefda]182 for (n[0] = -1; n[0] <= 1; n[0]++)
183 for (n[1] = -1; n[1] <= 1; n[1]++)
184 for (n[2] = -1; n[2] <= 1; n[2]++) {
[34c43a]185 const TesselPointSTLList *OtherList = LC->GetRelativeToCurrentCell(n);
[b8b75d]186 if (OtherList != NULL) {
[4e855e]187 Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
[34c43a]188 for (TesselPointSTLList::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
[735b1c]189 if ((*OtherRunner)->getNr() > Walker->getNr()) {
[f2bb0f]190 OtherWalker = dynamic_cast<atom*>(*OtherRunner);
191 ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode");
[e5ad5c]192 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
[d74077]193 const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
[4e855e]194 Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
[b70721]195 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance);
[4e855e]196 Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl;
[735b1c]197 if (OtherWalker->father->getNr() > Walker->father->getNr()) {
[e5ad5c]198 if (status) { // create bond if distance is smaller
[4e855e]199 Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;
[e5ad5c]200 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount
201 } else {
[4e855e]202 Log() << Verbose(1) << "Not Adding: distance too great." << endl;
[e5ad5c]203 }
[b8b75d]204 } else {
[4e855e]205 Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl;
[b8b75d]206 }
[cee0b57]207 }
208 }
209 }
210 }
211 }
212 }
213 }
[9eefda]214 delete (LC);
[458c31]215 DoLog(1) && (Log() << Verbose(1) << "I detected " << getBondCount() << " bonds in the molecule." << endl);
[cee0b57]216
[b8b75d]217 // correct bond degree by comparing valence and bond degree
[a67d19]218 DoLog(2) && (Log() << Verbose(2) << "Correcting bond degree ... " << endl);
[e138de]219 CorrectBondDegree();
[cee0b57]220
[b8b75d]221 // output bonds for debugging (if bond chain list was correctly installed)
[c743f8]222 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::OutputBondOfAtom));
[b8b75d]223 } else
[a7b761b]224 DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << getAtomCount() << ", thus no bonds, no connections!." << endl);
[a67d19]225 DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
[b70721]226 if (free_BG)
227 delete(BG);
[9eefda]228}
229;
[cee0b57]230
[e08c46]231/** Checks for presence of bonds within atom list.
232 * TODO: more sophisticated check for bond structure (e.g. connected subgraph, ...)
233 * \return true - bonds present, false - no bonds
234 */
[e4afb4]235bool molecule::hasBondStructure() const
[e08c46]236{
[9d83b6]237 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
238 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
239 if (!ListOfBonds.empty())
[e08c46]240 return true;
[9d83b6]241 }
[e08c46]242 return false;
243}
244
[b8b75d]245/** Prints a list of all bonds to \a *out.
246 */
[e138de]247void molecule::OutputBondsList() const
[b8b75d]248{
[a67d19]249 DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:");
[9d83b6]250 for(molecule::const_iterator AtomRunner = molecule::begin(); AtomRunner != molecule::end(); ++AtomRunner) {
251 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
252 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
253 BondRunner != ListOfBonds.end();
254 ++BondRunner)
[e08c46]255 if ((*BondRunner)->leftatom == *AtomRunner) {
256 DoLog(0) && (Log() << Verbose(0) << *(*BondRunner) << "\t" << endl);
257 }
[9d83b6]258 }
[a67d19]259 DoLog(0) && (Log() << Verbose(0) << endl);
[9eefda]260}
261;
[cee0b57]262
[b8b75d]263/** correct bond degree by comparing valence and bond degree.
264 * correct Bond degree of each bond by checking both bond partners for a mismatch between valence and current sum of bond degrees,
265 * iteratively increase the one first where the other bond partner has the fewest number of bonds (i.e. in general bonds oxygene
266 * preferred over carbon bonds). Beforehand, we had picked the first mismatching partner, which lead to oxygenes with single instead of
267 * double bonds as was expected.
268 * \return number of bonds that could not be corrected
269 */
[e138de]270int molecule::CorrectBondDegree() const
[b8b75d]271{
[99593f]272 int No = 0, OldNo = -1;
[b8b75d]273
[458c31]274 if (getBondCount() != 0) {
[a67d19]275 DoLog(1) && (Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl);
[b8b75d]276 do {
[99593f]277 OldNo = No;
[00ef5c]278 No=0;
279 BOOST_FOREACH(atom *atom,atoms){
280 No+=atom->CorrectBondDegree();
281 }
[99593f]282 } while (OldNo != No);
[a67d19]283 DoLog(0) && (Log() << Verbose(0) << " done." << endl);
[b8b75d]284 } else {
[458c31]285 DoLog(1) && (Log() << Verbose(1) << "BondCount is " << getBondCount() << ", no bonds between any of the " << getAtomCount() << " atoms." << endl);
[b8b75d]286 }
[a67d19]287 DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);
[cee0b57]288
[266237]289 return (No);
[9eefda]290}
[9d37ac]291
[cee0b57]292
293/** Counts all cyclic bonds and returns their number.
294 * \note Hydrogen bonds can never by cyclic, thus no check for that
[9d37ac]295 * \return number of cyclic bonds
[cee0b57]296 */
[e138de]297int molecule::CountCyclicBonds()
[cee0b57]298{
[266237]299 NoCyclicBonds = 0;
[cee0b57]300 int *MinimumRingSize = NULL;
301 MoleculeLeafClass *Subgraphs = NULL;
[a564be]302 std::deque<bond *> *BackEdgeStack = NULL;
[9d83b6]303 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
304 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
305 if ((!ListOfBonds.empty()) && ((*ListOfBonds.begin())->Type == Undetermined)) {
[e08c46]306 DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);
307 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
308 while (Subgraphs->next != NULL) {
309 Subgraphs = Subgraphs->next;
310 delete (Subgraphs->previous);
311 }
312 delete (Subgraphs);
313 delete[] (MinimumRingSize);
314 break;
[cee0b57]315 }
[9d83b6]316 }
317 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
318 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
319 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
320 BondRunner != ListOfBonds.end();
321 ++BondRunner)
[e08c46]322 if ((*BondRunner)->leftatom == *AtomRunner)
323 if ((*BondRunner)->Cyclic)
324 NoCyclicBonds++;
[9d83b6]325 }
[9eefda]326 delete (BackEdgeStack);
[266237]327 return NoCyclicBonds;
[9eefda]328}
329;
[b8b75d]330
[cee0b57]331/** Returns Shading as a char string.
332 * \param color the Shading
333 * \return string of the flag
334 */
[fa649a]335string molecule::GetColor(enum Shading color) const
[cee0b57]336{
[9eefda]337 switch (color) {
[cee0b57]338 case white:
339 return "white";
340 break;
341 case lightgray:
342 return "lightgray";
343 break;
344 case darkgray:
345 return "darkgray";
346 break;
347 case black:
348 return "black";
349 break;
350 default:
351 return "uncolored";
352 break;
353 };
[9eefda]354}
355;
[cee0b57]356
[9eefda]357/** Sets atom::GraphNr and atom::LowpointNr to BFSAccounting::CurrentGraphNr.
358 * \param *Walker current node
359 * \param &BFS structure with accounting data for BFS
360 */
[e138de]361void DepthFirstSearchAnalysis_SetWalkersGraphNr(atom *&Walker, struct DFSAccounting &DFS)
[174e0e]362{
[9eefda]363 if (!DFS.BackStepping) { // if we don't just return from (8)
364 Walker->GraphNr = DFS.CurrentGraphNr;
365 Walker->LowpointNr = DFS.CurrentGraphNr;
[68f03d]366 DoLog(1) && (Log() << Verbose(1) << "Setting Walker[" << Walker->getName() << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl);
[a564be]367 DFS.AtomStack->push_front(Walker);
[9eefda]368 DFS.CurrentGraphNr++;
[174e0e]369 }
[9eefda]370}
371;
[174e0e]372
[9eefda]373/** During DFS goes along unvisited bond and touches other atom.
374 * Sets bond::type, if
375 * -# BackEdge: set atom::LowpointNr and push on \a BackEdgeStack
376 * -# TreeEgde: set atom::Ancestor and continue with Walker along this edge
377 * Continue until molecule::FindNextUnused() finds no more unused bonds.
378 * \param *mol molecule with atoms and finding unused bonds
379 * \param *&Binder current edge
380 * \param &DFS DFS accounting data
381 */
[e138de]382void DepthFirstSearchAnalysis_ProbeAlongUnusedBond(const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS)
[174e0e]383{
384 atom *OtherAtom = NULL;
385
386 do { // (3) if Walker has no unused egdes, go to (5)
[9eefda]387 DFS.BackStepping = false; // reset backstepping flag for (8)
[174e0e]388 if (Binder == NULL) // if we don't just return from (11), Binder is already set to next unused
389 Binder = mol->FindNextUnused(Walker);
390 if (Binder == NULL)
391 break;
[a67d19]392 DoLog(2) && (Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl);
[174e0e]393 // (4) Mark Binder used, ...
394 Binder->MarkUsed(black);
395 OtherAtom = Binder->GetOtherAtom(Walker);
[68f03d]396 DoLog(2) && (Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->getName() << "." << endl);
[174e0e]397 if (OtherAtom->GraphNr != -1) {
398 // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3)
399 Binder->Type = BackEdge;
[a564be]400 DFS.BackEdgeStack->push_front(Binder);
[9eefda]401 Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr;
[68f03d]402 DoLog(3) && (Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->getName() << "] to " << Walker->LowpointNr << "." << endl);
[174e0e]403 } else {
404 // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2)
405 Binder->Type = TreeEdge;
406 OtherAtom->Ancestor = Walker;
407 Walker = OtherAtom;
[68f03d]408 DoLog(3) && (Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->getName() << "]'s Ancestor is now " << OtherAtom->Ancestor->getName() << ", Walker is OtherAtom " << OtherAtom->getName() << "." << endl);
[174e0e]409 break;
410 }
411 Binder = NULL;
[9eefda]412 } while (1); // (3)
413}
414;
[174e0e]415
[9eefda]416/** Checks whether we have a new component.
417 * if atom::LowpointNr of \a *&Walker is greater than atom::GraphNr of its atom::Ancestor, we have a new component.
418 * Meaning that if we touch upon a node who suddenly has a smaller atom::LowpointNr than its ancestor, then we
419 * have a found a new branch in the graph tree.
420 * \param *mol molecule with atoms and finding unused bonds
421 * \param *&Walker current node
422 * \param &DFS DFS accounting data
423 */
[e138de]424void DepthFirstSearchAnalysis_CheckForaNewComponent(const molecule * const mol, atom *&Walker, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker)
[174e0e]425{
426 atom *OtherAtom = NULL;
427
428 // (5) if Ancestor of Walker is ...
[68f03d]429 DoLog(1) && (Log() << Verbose(1) << "(5) Number of Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "] is " << Walker->Ancestor->GraphNr << "." << endl);
[174e0e]430
[9eefda]431 if (Walker->Ancestor->GraphNr != DFS.Root->GraphNr) {
[174e0e]432 // (6) (Ancestor of Walker is not Root)
433 if (Walker->LowpointNr < Walker->Ancestor->GraphNr) {
434 // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8)
435 Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr;
[68f03d]436 DoLog(2) && (Log() << Verbose(2) << "(6) Setting Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl);
[174e0e]437 } else {
438 // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component
439 Walker->Ancestor->SeparationVertex = true;
[68f03d]440 DoLog(2) && (Log() << Verbose(2) << "(7) Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s is a separating vertex, creating component." << endl);
[9eefda]441 mol->SetNextComponentNumber(Walker->Ancestor, DFS.ComponentNumber);
[68f03d]442 DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl);
[9eefda]443 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
[68f03d]444 DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
[174e0e]445 do {
[a564be]446 ASSERT(!DFS.AtomStack->empty(), "DepthFirstSearchAnalysis_CheckForaNewComponent() - DFS.AtomStack is empty!");
447 OtherAtom = DFS.AtomStack->front();
448 DFS.AtomStack->pop_front();
[174e0e]449 LeafWalker->Leaf->AddCopyAtom(OtherAtom);
[9eefda]450 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
[68f03d]451 DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
[174e0e]452 } while (OtherAtom != Walker);
[9eefda]453 DFS.ComponentNumber++;
[174e0e]454 }
455 // (8) Walker becomes its Ancestor, go to (3)
[68f03d]456 DoLog(2) && (Log() << Verbose(2) << "(8) Walker[" << Walker->getName() << "] is now its Ancestor " << Walker->Ancestor->getName() << ", backstepping. " << endl);
[174e0e]457 Walker = Walker->Ancestor;
[9eefda]458 DFS.BackStepping = true;
[174e0e]459 }
[9eefda]460}
461;
[174e0e]462
[9eefda]463/** Cleans the root stack when we have found a component.
464 * If we are not DFSAccounting::BackStepping, then we clear the root stack by putting everything into a
465 * component down till we meet DFSAccounting::Root.
466 * \param *mol molecule with atoms and finding unused bonds
467 * \param *&Walker current node
468 * \param *&Binder current edge
469 * \param &DFS DFS accounting data
470 */
[e138de]471void DepthFirstSearchAnalysis_CleanRootStackDownTillWalker(const molecule * const mol, atom *&Walker, bond *&Binder, struct DFSAccounting &DFS, MoleculeLeafClass *&LeafWalker)
[174e0e]472{
473 atom *OtherAtom = NULL;
474
[9eefda]475 if (!DFS.BackStepping) { // coming from (8) want to go to (3)
[174e0e]476 // (9) remove all from stack till Walker (including), these and Root form a component
[99593f]477 //DFS.AtomStack->Output(out);
[9eefda]478 mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber);
[68f03d]479 DoLog(3) && (Log() << Verbose(3) << "(9) Root[" << DFS.Root->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);
[9eefda]480 mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
[68f03d]481 DoLog(3) && (Log() << Verbose(3) << "(9) Walker[" << Walker->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);
[174e0e]482 do {
[a564be]483 ASSERT(!DFS.AtomStack->empty(), "DepthFirstSearchAnalysis_CleanRootStackDownTillWalker() - DFS.AtomStack is empty!");
484 OtherAtom = DFS.AtomStack->front();
485 DFS.AtomStack->pop_front();
[174e0e]486 LeafWalker->Leaf->AddCopyAtom(OtherAtom);
[9eefda]487 mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
[a564be]488 DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->getName() << "]'s Component is " << DFS.ComponentNumber << "." << endl);
[174e0e]489 } while (OtherAtom != Walker);
[9eefda]490 DFS.ComponentNumber++;
[174e0e]491
492 // (11) Root is separation vertex, set Walker to Root and go to (4)
[9eefda]493 Walker = DFS.Root;
[174e0e]494 Binder = mol->FindNextUnused(Walker);
[68f03d]495 DoLog(1) && (Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->getName() << "], next Unused Bond is " << Binder << "." << endl);
[174e0e]496 if (Binder != NULL) { // Root is separation vertex
[a67d19]497 DoLog(1) && (Log() << Verbose(1) << "(11) Root is a separation vertex." << endl);
[174e0e]498 Walker->SeparationVertex = true;
499 }
500 }
[9eefda]501}
502;
503
504/** Initializes DFSAccounting structure.
505 * \param &DFS accounting structure to allocate
[7218f8]506 * \param *mol molecule with AtomCount, BondCount and all atoms
[9eefda]507 */
[e138de]508void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol)
[9eefda]509{
[a564be]510 DFS.AtomStack = new std::deque<atom *> (mol->getAtomCount());
[9eefda]511 DFS.CurrentGraphNr = 0;
512 DFS.ComponentNumber = 0;
513 DFS.BackStepping = false;
[7218f8]514 mol->ResetAllBondsToUnused();
[a564be]515 DFS.BackEdgeStack->clear();
[9eefda]516}
517;
[174e0e]518
[9eefda]519/** Free's DFSAccounting structure.
520 * \param &DFS accounting structure to free
521 */
[e138de]522void DepthFirstSearchAnalysis_Finalize(struct DFSAccounting &DFS)
[9eefda]523{
524 delete (DFS.AtomStack);
[7218f8]525 // delete (DFS.BackEdgeStack); // DON'T free, see DepthFirstSearchAnalysis(), is returned as allocated
[9eefda]526}
527;
[174e0e]528
[00ef5c]529void molecule::init_DFS(struct DFSAccounting &DFS) const{
530 DepthFirstSearchAnalysis_Init(DFS, this);
531 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::resetGraphNr));
532 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::InitComponentNr));
533}
534
[cee0b57]535/** Performs a Depth-First search on this molecule.
536 * Marks bonds in molecule as cyclic, bridge, ... and atoms as
537 * articulations points, ...
538 * We use the algorithm from [Even, Graph Algorithms, p.62].
[a564be]539 * \param *&BackEdgeStack NULL pointer to std::deque<bond *> with all the found back edges, allocated and filled on return
[cee0b57]540 * \return list of each disconnected subgraph as an individual molecule class structure
541 */
[a564be]542MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const
[cee0b57]543{
[9eefda]544 struct DFSAccounting DFS;
[458c31]545 BackEdgeStack = new std::deque<bond *> (getBondCount());
[9eefda]546 DFS.BackEdgeStack = BackEdgeStack;
[cee0b57]547 MoleculeLeafClass *SubGraphs = new MoleculeLeafClass(NULL);
548 MoleculeLeafClass *LeafWalker = SubGraphs;
[9eefda]549 int OldGraphNr = 0;
[174e0e]550 atom *Walker = NULL;
[cee0b57]551 bond *Binder = NULL;
552
[a7b761b]553 if (getAtomCount() == 0)
[046783]554 return SubGraphs;
[a67d19]555 DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl);
[00ef5c]556 init_DFS(DFS);
[cee0b57]557
[9879f6]558 for (molecule::const_iterator iter = begin(); iter != end();) {
559 DFS.Root = *iter;
[7218f8]560 // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
[a564be]561 DFS.AtomStack->clear();
[cee0b57]562
563 // put into new subgraph molecule and add this to list of subgraphs
564 LeafWalker = new MoleculeLeafClass(LeafWalker);
[5f612ee]565 LeafWalker->Leaf = World::getInstance().createMolecule();
[9eefda]566 LeafWalker->Leaf->AddCopyAtom(DFS.Root);
[cee0b57]567
[9eefda]568 OldGraphNr = DFS.CurrentGraphNr;
569 Walker = DFS.Root;
[cee0b57]570 do { // (10)
571 do { // (2) set number and Lowpoint of Atom to i, increase i, push current atom
[e138de]572 DepthFirstSearchAnalysis_SetWalkersGraphNr(Walker, DFS);
[174e0e]573
[e138de]574 DepthFirstSearchAnalysis_ProbeAlongUnusedBond(this, Walker, Binder, DFS);
[174e0e]575
[cee0b57]576 if (Binder == NULL) {
[a67d19]577 DoLog(2) && (Log() << Verbose(2) << "No more Unused Bonds." << endl);
[cee0b57]578 break;
579 } else
580 Binder = NULL;
[9eefda]581 } while (1); // (2)
[cee0b57]582
583 // if we came from backstepping, yet there were no more unused bonds, we end up here with no Ancestor, because Walker is Root! Then we are finished!
[9eefda]584 if ((Walker == DFS.Root) && (Binder == NULL))
[cee0b57]585 break;
586
[e138de]587 DepthFirstSearchAnalysis_CheckForaNewComponent(this, Walker, DFS, LeafWalker);
[174e0e]588
[e138de]589 DepthFirstSearchAnalysis_CleanRootStackDownTillWalker(this, Walker, Binder, DFS, LeafWalker);
[174e0e]590
[9eefda]591 } while ((DFS.BackStepping) || (Binder != NULL)); // (10) halt only if Root has no unused edges
[cee0b57]592
593 // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph
[a67d19]594 DoLog(0) && (Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl);
[986ed3]595 LeafWalker->Leaf->Output((ofstream *)&(Log() << Verbose(0)));
[a67d19]596 DoLog(0) && (Log() << Verbose(0) << endl);
[cee0b57]597
598 // step on to next root
[9879f6]599 while ((iter != end()) && ((*iter)->GraphNr != -1)) {
600 //Log() << Verbose(1) << "Current next subgraph root candidate is " << (*iter)->Name << "." << endl;
601 if ((*iter)->GraphNr != -1) // if already discovered, step on
602 iter++;
[cee0b57]603 }
604 }
605 // set cyclic bond criterium on "same LP" basis
[266237]606 CyclicBondAnalysis();
607
[e138de]608 OutputGraphInfoPerAtom();
[266237]609
[e138de]610 OutputGraphInfoPerBond();
[266237]611
612 // free all and exit
[e138de]613 DepthFirstSearchAnalysis_Finalize(DFS);
[a67d19]614 DoLog(0) && (Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl);
[266237]615 return SubGraphs;
[9eefda]616}
617;
[266237]618
619/** Scans through all bonds and set bond::Cyclic to true where atom::LowpointNr of both ends is equal: LP criterion.
620 */
[fa649a]621void molecule::CyclicBondAnalysis() const
[266237]622{
623 NoCyclicBonds = 0;
[9d83b6]624 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
625 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
626 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
627 BondRunner != ListOfBonds.end();
628 ++BondRunner)
[e08c46]629 if ((*BondRunner)->leftatom == *AtomRunner)
630 if ((*BondRunner)->rightatom->LowpointNr == (*BondRunner)->leftatom->LowpointNr) { // cyclic ??
631 (*BondRunner)->Cyclic = true;
632 NoCyclicBonds++;
633 }
[9d83b6]634 }
[9eefda]635}
636;
[cee0b57]637
[266237]638/** Output graph information per atom.
639 */
[e138de]640void molecule::OutputGraphInfoPerAtom() const
[266237]641{
[a67d19]642 DoLog(1) && (Log() << Verbose(1) << "Final graph info for each atom is:" << endl);
[c743f8]643 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::OutputGraphInfo));
[9eefda]644}
645;
[cee0b57]646
[266237]647/** Output graph information per bond.
648 */
[e138de]649void molecule::OutputGraphInfoPerBond() const
[266237]650{
[a67d19]651 DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl);
[9d83b6]652 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
653 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
654 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
655 BondRunner != ListOfBonds.end();
656 ++BondRunner)
[e08c46]657 if ((*BondRunner)->leftatom == *AtomRunner) {
[9d83b6]658 const bond *Binder = *BondRunner;
[f9183b]659 if (DoLog(2)) {
660 ostream &out = (Log() << Verbose(2));
661 out << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";
662 out << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";
663 Binder->leftatom->OutputComponentNumber(&out);
664 out << " === ";
665 out << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
666 Binder->rightatom->OutputComponentNumber(&out);
667 out << ">." << endl;
668 }
[e08c46]669 if (Binder->Cyclic) // cyclic ??
670 DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);
671 }
[9d83b6]672 }
[9eefda]673}
674;
675
676/** Initialise each vertex as white with no predecessor, empty queue, color Root lightgray.
677 * \param &BFS accounting structure
678 * \param AtomCount number of entries in the array to allocate
679 */
[e138de]680void InitializeBFSAccounting(struct BFSAccounting &BFS, int AtomCount)
[9eefda]681{
682 BFS.AtomCount = AtomCount;
[920c70]683 BFS.PredecessorList = new atom*[AtomCount];
684 BFS.ShortestPathList = new int[AtomCount];
685 BFS.ColorList = new enum Shading[AtomCount];
[a564be]686 BFS.BFSStack = new std::deque<atom *> (AtomCount);
687 BFS.TouchedStack = new std::deque<atom *> (AtomCount);
[9eefda]688
[920c70]689 for (int i = AtomCount; i--;) {
[9eefda]690 BFS.ShortestPathList[i] = -1;
[920c70]691 BFS.PredecessorList[i] = 0;
[c27778]692 BFS.ColorList[i] = white;
[920c70]693 }
[cee0b57]694};
695
[9eefda]696/** Free's accounting structure.
697 * \param &BFS accounting structure
698 */
[e138de]699void FinalizeBFSAccounting(struct BFSAccounting &BFS)
[9eefda]700{
[920c70]701 delete[](BFS.PredecessorList);
702 delete[](BFS.ShortestPathList);
703 delete[](BFS.ColorList);
[9eefda]704 delete (BFS.BFSStack);
[c27778]705 delete (BFS.TouchedStack);
[9eefda]706 BFS.AtomCount = 0;
707};
708
709/** Clean the accounting structure.
710 * \param &BFS accounting structure
[ef9aae]711 */
[e138de]712void CleanBFSAccounting(struct BFSAccounting &BFS)
[ef9aae]713{
[9eefda]714 atom *Walker = NULL;
[a564be]715 while (!BFS.TouchedStack->empty()) {
716 Walker = BFS.TouchedStack->front();
717 BFS.TouchedStack->pop_front();
[735b1c]718 BFS.PredecessorList[Walker->getNr()] = NULL;
719 BFS.ShortestPathList[Walker->getNr()] = -1;
720 BFS.ColorList[Walker->getNr()] = white;
[ef9aae]721 }
722};
723
[9eefda]724/** Resets shortest path list and BFSStack.
725 * \param *&Walker current node, pushed onto BFSAccounting::BFSStack and BFSAccounting::TouchedStack
726 * \param &BFS accounting structure
727 */
[e138de]728void ResetBFSAccounting(atom *&Walker, struct BFSAccounting &BFS)
[ef9aae]729{
[735b1c]730 BFS.ShortestPathList[Walker->getNr()] = 0;
[a564be]731 BFS.BFSStack->clear(); // start with empty BFS stack
732 BFS.BFSStack->push_front(Walker);
733 BFS.TouchedStack->push_front(Walker);
[ef9aae]734};
735
[9eefda]736/** Performs a BFS from \a *Root, trying to find the same node and hence a cycle.
737 * \param *&BackEdge the edge from root that we don't want to move along
738 * \param &BFS accounting structure
739 */
[e138de]740void CyclicStructureAnalysis_CyclicBFSFromRootToRoot(bond *&BackEdge, struct BFSAccounting &BFS)
[ef9aae]741{
742 atom *Walker = NULL;
743 atom *OtherAtom = NULL;
[9eefda]744 do { // look for Root
[a564be]745 ASSERT(!BFS.BFSStack->empty(), "CyclicStructureAnalysis_CyclicBFSFromRootToRoot() - BFS.BFSStack is empty!");
746 Walker = BFS.BFSStack->front();
747 BFS.BFSStack->pop_front();
[a67d19]748 DoLog(2) && (Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl);
[9d83b6]749 const BondList& ListOfBonds = Walker->getListOfBonds();
750 for (BondList::const_iterator Runner = ListOfBonds.begin();
751 Runner != ListOfBonds.end();
752 ++Runner) {
[ef9aae]753 if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder)
754 OtherAtom = (*Runner)->GetOtherAtom(Walker);
[9eefda]755#ifdef ADDHYDROGEN
[83f176]756 if (OtherAtom->getType()->getAtomicNumber() != 1) {
[9eefda]757#endif
[68f03d]758 DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);
[735b1c]759 if (BFS.ColorList[OtherAtom->getNr()] == white) {
[a564be]760 BFS.TouchedStack->push_front(OtherAtom);
[735b1c]761 BFS.ColorList[OtherAtom->getNr()] = lightgray;
762 BFS.PredecessorList[OtherAtom->getNr()] = Walker; // Walker is the predecessor
763 BFS.ShortestPathList[OtherAtom->getNr()] = BFS.ShortestPathList[Walker->getNr()] + 1;
764 DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " lightgray, its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->getNr()] << " egde(s) long." << endl);
765 //if (BFS.ShortestPathList[OtherAtom->getNr()] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance
[a67d19]766 DoLog(3) && (Log() << Verbose(3) << "Putting OtherAtom into queue." << endl);
[a564be]767 BFS.BFSStack->push_front(OtherAtom);
[9eefda]768 //}
[ef9aae]769 } else {
[a67d19]770 DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
[ef9aae]771 }
[9eefda]772 if (OtherAtom == BFS.Root)
773 break;
774#ifdef ADDHYDROGEN
775 } else {
[a67d19]776 DoLog(2) && (Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl);
[735b1c]777 BFS.ColorList[OtherAtom->getNr()] = black;
[9eefda]778 }
779#endif
[ef9aae]780 } else {
[a67d19]781 DoLog(2) && (Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl);
[ef9aae]782 }
783 }
[735b1c]784 BFS.ColorList[Walker->getNr()] = black;
[68f03d]785 DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);
[9eefda]786 if (OtherAtom == BFS.Root) { // if we have found the root, check whether this cycle wasn't already found beforehand
[ef9aae]787 // step through predecessor list
788 while (OtherAtom != BackEdge->rightatom) {
[9eefda]789 if (!OtherAtom->GetTrueFather()->IsCyclic) // if one bond in the loop is not marked as cyclic, we haven't found this cycle yet
[ef9aae]790 break;
791 else
[735b1c]792 OtherAtom = BFS.PredecessorList[OtherAtom->getNr()];
[ef9aae]793 }
794 if (OtherAtom == BackEdge->rightatom) { // if each atom in found cycle is cyclic, loop's been found before already
[a67d19]795 DoLog(3) && (Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl);
[ef9aae]796 do {
[a564be]797 ASSERT(!BFS.TouchedStack->empty(), "CyclicStructureAnalysis_CyclicBFSFromRootToRoot() - BFS.TouchedStack is empty!");
798 OtherAtom = BFS.TouchedStack->front();
799 BFS.TouchedStack->pop_front();
[735b1c]800 if (BFS.PredecessorList[OtherAtom->getNr()] == Walker) {
[a67d19]801 DoLog(4) && (Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl);
[735b1c]802 BFS.PredecessorList[OtherAtom->getNr()] = NULL;
803 BFS.ShortestPathList[OtherAtom->getNr()] = -1;
804 BFS.ColorList[OtherAtom->getNr()] = white;
[a564be]805 // rats ... deque has no find()
806 std::deque<atom *>::iterator iter = find(
807 BFS.BFSStack->begin(),
808 BFS.BFSStack->end(),
809 OtherAtom);
810 ASSERT(iter != BFS.BFSStack->end(),
811 "CyclicStructureAnalysis_CyclicBFSFromRootToRoot() - can't find "+toString(*OtherAtom)+" on stack!");
812 BFS.BFSStack->erase(iter);
[ef9aae]813 }
[735b1c]814 } while ((!BFS.TouchedStack->empty()) && (BFS.PredecessorList[OtherAtom->getNr()] == NULL));
[a564be]815 BFS.TouchedStack->push_front(OtherAtom); // last was wrongly popped
[ef9aae]816 OtherAtom = BackEdge->rightatom; // set to not Root
817 } else
[9eefda]818 OtherAtom = BFS.Root;
[ef9aae]819 }
[735b1c]820 } while ((!BFS.BFSStack->empty()) && (OtherAtom != BFS.Root) && (OtherAtom != NULL)); // || (ShortestPathList[OtherAtom->getNr()] < MinimumRingSize[Walker->GetTrueFather()->getNr()])));
[ef9aae]821};
822
[9eefda]823/** Climb back the BFSAccounting::PredecessorList and find cycle members.
824 * \param *&OtherAtom
825 * \param *&BackEdge denotes the edge we did not want to travel along when doing CyclicBFSFromRootToRoot()
826 * \param &BFS accounting structure
827 * \param *&MinimumRingSize minimum distance from this node possible without encountering oneself, set on return for each atom
828 * \param &MinRingSize global minimum distance from one node without encountering oneself, set on return
829 */
[e138de]830void CyclicStructureAnalysis_RetrieveCycleMembers(atom *&OtherAtom, bond *&BackEdge, struct BFSAccounting &BFS, int *&MinimumRingSize, int &MinRingSize)
[ef9aae]831{
832 atom *Walker = NULL;
833 int NumCycles = 0;
834 int RingSize = -1;
835
[9eefda]836 if (OtherAtom == BFS.Root) {
[ef9aae]837 // now climb back the predecessor list and thus find the cycle members
838 NumCycles++;
839 RingSize = 1;
[9eefda]840 BFS.Root->GetTrueFather()->IsCyclic = true;
[a67d19]841 DoLog(1) && (Log() << Verbose(1) << "Found ring contains: ");
[9eefda]842 Walker = BFS.Root;
[ef9aae]843 while (Walker != BackEdge->rightatom) {
[68f03d]844 DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " <-> ");
[735b1c]845 Walker = BFS.PredecessorList[Walker->getNr()];
[ef9aae]846 Walker->GetTrueFather()->IsCyclic = true;
847 RingSize++;
848 }
[68f03d]849 DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " with a length of " << RingSize << "." << endl << endl);
[ef9aae]850 // walk through all and set MinimumRingSize
[9eefda]851 Walker = BFS.Root;
[735b1c]852 MinimumRingSize[Walker->GetTrueFather()->getNr()] = RingSize;
[ef9aae]853 while (Walker != BackEdge->rightatom) {
[735b1c]854 Walker = BFS.PredecessorList[Walker->getNr()];
855 if (RingSize < MinimumRingSize[Walker->GetTrueFather()->getNr()])
856 MinimumRingSize[Walker->GetTrueFather()->getNr()] = RingSize;
[ef9aae]857 }
858 if ((RingSize < MinRingSize) || (MinRingSize == -1))
859 MinRingSize = RingSize;
860 } else {
[735b1c]861 DoLog(1) && (Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[BFS.Root->GetTrueFather()->getNr()] << " found." << endl);
[ef9aae]862 }
863};
864
[9eefda]865/** From a given node performs a BFS to touch the next cycle, for whose nodes \a *&MinimumRingSize is set and set it accordingly.
866 * \param *&Root node to look for closest cycle from, i.e. \a *&MinimumRingSize is set for this node
867 * \param *&MinimumRingSize minimum distance from this node possible without encountering oneself, set on return for each atom
868 * \param AtomCount number of nodes in graph
869 */
[e138de]870void CyclicStructureAnalysis_BFSToNextCycle(atom *&Root, atom *&Walker, int *&MinimumRingSize, int AtomCount)
[ef9aae]871{
[9eefda]872 struct BFSAccounting BFS;
[ef9aae]873 atom *OtherAtom = Walker;
874
[e138de]875 InitializeBFSAccounting(BFS, AtomCount);
[ef9aae]876
[e138de]877 ResetBFSAccounting(Walker, BFS);
[9eefda]878 while (OtherAtom != NULL) { // look for Root
[a564be]879 ASSERT(!BFS.BFSStack->empty(), "CyclicStructureAnalysis_BFSToNextCycle() - BFS.BFSStack is empty!");
880 Walker = BFS.BFSStack->front();
881 BFS.BFSStack->pop_front();
[e138de]882 //Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *Root << "." << endl;
[9d83b6]883 const BondList& ListOfBonds = Walker->getListOfBonds();
884 for (BondList::const_iterator Runner = ListOfBonds.begin();
885 Runner != ListOfBonds.end();
886 ++Runner) {
[9eefda]887 // "removed (*Runner) != BackEdge) || " from next if, is u
[9d83b6]888 if ((ListOfBonds.size() == 1)) { // only walk along DFS spanning tree (otherwise we always find SP of 1 being backedge Binder), but terminal hydrogens may be connected via backedge, hence extra check
[ef9aae]889 OtherAtom = (*Runner)->GetOtherAtom(Walker);
[e138de]890 //Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl;
[735b1c]891 if (BFS.ColorList[OtherAtom->getNr()] == white) {
[a564be]892 BFS.TouchedStack->push_front(OtherAtom);
[735b1c]893 BFS.ColorList[OtherAtom->getNr()] = lightgray;
894 BFS.PredecessorList[OtherAtom->getNr()] = Walker; // Walker is the predecessor
895 BFS.ShortestPathList[OtherAtom->getNr()] = BFS.ShortestPathList[Walker->getNr()] + 1;
896 //Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->getNr()] << " egde(s) long." << endl;
[ef9aae]897 if (OtherAtom->GetTrueFather()->IsCyclic) { // if the other atom is connected to a ring
[735b1c]898 MinimumRingSize[Root->GetTrueFather()->getNr()] = BFS.ShortestPathList[OtherAtom->getNr()] + MinimumRingSize[OtherAtom->GetTrueFather()->getNr()];
[ef9aae]899 OtherAtom = NULL; //break;
900 break;
901 } else
[a564be]902 BFS.BFSStack->push_front(OtherAtom);
[ef9aae]903 } else {
[e138de]904 //Log() << Verbose(3) << "Not Adding, has already been visited." << endl;
[ef9aae]905 }
906 } else {
[e138de]907 //Log() << Verbose(3) << "Not Visiting, is a back edge." << endl;
[ef9aae]908 }
909 }
[735b1c]910 BFS.ColorList[Walker->getNr()] = black;
[e138de]911 //Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
[ef9aae]912 }
913 //CleanAccountingLists(TouchedStack, PredecessorList, ShortestPathList, ColorList);
914
[e138de]915 FinalizeBFSAccounting(BFS);
[9eefda]916}
917;
[ef9aae]918
[9eefda]919/** All nodes that are not in cycles get assigned a \a *&MinimumRingSizeby BFS to next cycle.
920 * \param *&MinimumRingSize array with minimum distance without encountering onself for each atom
921 * \param &MinRingSize global minium distance
922 * \param &NumCyles number of cycles in graph
923 * \param *mol molecule with atoms
924 */
[e138de]925void CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers(int *&MinimumRingSize, int &MinRingSize, int &NumCycles, const molecule * const mol)
[ef9aae]926{
[9eefda]927 atom *Root = NULL;
[ef9aae]928 atom *Walker = NULL;
929 if (MinRingSize != -1) { // if rings are present
930 // go over all atoms
[9879f6]931 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
932 Root = *iter;
[ef9aae]933
[735b1c]934 if (MinimumRingSize[Root->GetTrueFather()->getNr()] == mol->getAtomCount()) { // check whether MinimumRingSize is set, if not BFS to next where it is
[ef9aae]935 Walker = Root;
936
[e138de]937 //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;
[ea7176]938 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->getAtomCount());
[ef9aae]939
940 }
[735b1c]941 DoLog(1) && (Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->getNr()] << "." << endl);
[ef9aae]942 }
[a67d19]943 DoLog(1) && (Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl);
[ef9aae]944 } else
[a67d19]945 DoLog(1) && (Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl);
[9eefda]946}
947;
[ef9aae]948
[cee0b57]949/** Analyses the cycles found and returns minimum of all cycle lengths.
950 * We begin with a list of Back edges found during DepthFirstSearchAnalysis(). We go through this list - one end is the Root,
951 * the other our initial Walker - and do a Breadth First Search for the Root. We mark down each Predecessor and as soon as
952 * we have found the Root via BFS, we may climb back the closed cycle via the Predecessors. Thereby we mark atoms and bonds
953 * as cyclic and print out the cycles.
954 * \param *BackEdgeStack stack with all back edges found during DFS scan. Beware: This stack contains the bonds from the total molecule, not from the subgraph!
955 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found, if set is maximum search distance
956 * \todo BFS from the not-same-LP to find back to starting point of tributary cycle over more than one bond
957 */
[9d37ac]958void molecule::CyclicStructureAnalysis(
959 std::deque<bond *> * BackEdgeStack,
960 int *&MinimumRingSize
961 ) const
[cee0b57]962{
[9eefda]963 struct BFSAccounting BFS;
[ef9aae]964 atom *Walker = NULL;
965 atom *OtherAtom = NULL;
966 bond *BackEdge = NULL;
967 int NumCycles = 0;
968 int MinRingSize = -1;
[cee0b57]969
[ea7176]970 InitializeBFSAccounting(BFS, getAtomCount());
[cee0b57]971
[e138de]972 //Log() << Verbose(1) << "Back edge list - ";
[99593f]973 //BackEdgeStack->Output(out);
[cee0b57]974
[a67d19]975 DoLog(1) && (Log() << Verbose(1) << "Analysing cycles ... " << endl);
[cee0b57]976 NumCycles = 0;
[a564be]977 while (!BackEdgeStack->empty()) {
978 BackEdge = BackEdgeStack->front();
979 BackEdgeStack->pop_front();
[cee0b57]980 // this is the target
[9eefda]981 BFS.Root = BackEdge->leftatom;
[cee0b57]982 // this is the source point
983 Walker = BackEdge->rightatom;
984
[e138de]985 ResetBFSAccounting(Walker, BFS);
[cee0b57]986
[a67d19]987 DoLog(1) && (Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl);
[ef9aae]988 OtherAtom = NULL;
[e138de]989 CyclicStructureAnalysis_CyclicBFSFromRootToRoot(BackEdge, BFS);
[cee0b57]990
[e138de]991 CyclicStructureAnalysis_RetrieveCycleMembers(OtherAtom, BackEdge, BFS, MinimumRingSize, MinRingSize);
[cee0b57]992
[e138de]993 CleanBFSAccounting(BFS);
[ef9aae]994 }
[e138de]995 FinalizeBFSAccounting(BFS);
[ef9aae]996
[e138de]997 CyclicStructureAnalysis_AssignRingSizetoNonCycleMembers(MinimumRingSize, MinRingSize, NumCycles, this);
[fa649a]998};
[cee0b57]999
1000/** Sets the next component number.
1001 * This is O(N) as the number of bonds per atom is bound.
1002 * \param *vertex atom whose next atom::*ComponentNr is to be set
[5309ba]1003 * \param Nr number to use
[cee0b57]1004 */
[fa649a]1005void molecule::SetNextComponentNumber(atom *vertex, int nr) const
[cee0b57]1006{
[9eefda]1007 size_t i = 0;
[cee0b57]1008 if (vertex != NULL) {
[9d83b6]1009 const BondList& ListOfBonds = vertex->getListOfBonds();
1010 for (; i < ListOfBonds.size(); i++) {
[9eefda]1011 if (vertex->ComponentNr[i] == -1) { // check if not yet used
[cee0b57]1012 vertex->ComponentNr[i] = nr;
1013 break;
[9eefda]1014 } else if (vertex->ComponentNr[i] == nr) // if number is already present, don't add another time
1015 break; // breaking here will not cause error!
[cee0b57]1016 }
[9d83b6]1017 if (i == ListOfBonds.size()) {
[58ed4a]1018 DoeLog(0) && (eLog()<< Verbose(0) << "Error: All Component entries are already occupied!" << endl);
[e359a8]1019 performCriticalExit();
1020 }
1021 } else {
[58ed4a]1022 DoeLog(0) && (eLog()<< Verbose(0) << "Error: Given vertex is NULL!" << endl);
[e359a8]1023 performCriticalExit();
1024 }
[9eefda]1025}
1026;
[cee0b57]1027
1028/** Returns next unused bond for this atom \a *vertex or NULL of none exists.
1029 * \param *vertex atom to regard
1030 * \return bond class or NULL
1031 */
[fa649a]1032bond * molecule::FindNextUnused(atom *vertex) const
[cee0b57]1033{
[9d83b6]1034 const BondList& ListOfBonds = vertex->getListOfBonds();
1035 for (BondList::const_iterator Runner = ListOfBonds.begin();
1036 Runner != ListOfBonds.end();
1037 ++Runner)
[266237]1038 if ((*Runner)->IsUsed() == white)
[9eefda]1039 return ((*Runner));
[cee0b57]1040 return NULL;
[9eefda]1041}
1042;
[cee0b57]1043
1044/** Resets bond::Used flag of all bonds in this molecule.
1045 * \return true - success, false - -failure
1046 */
[fa649a]1047void molecule::ResetAllBondsToUnused() const
[cee0b57]1048{
[9d83b6]1049 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
1050 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
1051 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
1052 BondRunner != ListOfBonds.end();
1053 ++BondRunner)
[e08c46]1054 if ((*BondRunner)->leftatom == *AtomRunner)
1055 (*BondRunner)->ResetUsed();
[9d83b6]1056 }
[9eefda]1057}
1058;
[cee0b57]1059
1060/** Output a list of flags, stating whether the bond was visited or not.
[9d37ac]1061 * \param *list list to print
[cee0b57]1062 */
[e138de]1063void OutputAlreadyVisited(int *list)
[cee0b57]1064{
[a67d19]1065 DoLog(4) && (Log() << Verbose(4) << "Already Visited Bonds:\t");
[9eefda]1066 for (int i = 1; i <= list[0]; i++)
[a67d19]1067 DoLog(0) && (Log() << Verbose(0) << list[i] << " ");
1068 DoLog(0) && (Log() << Verbose(0) << endl);
[9eefda]1069}
1070;
[cee0b57]1071
1072/** Storing the bond structure of a molecule to file.
[5309ba]1073 * Simply stores Atom::Nr and then the Atom::Nr of all bond partners per line.
[35b698]1074 * \param &filename name of file
1075 * \param path path to file, defaults to empty
[cee0b57]1076 * \return true - file written successfully, false - writing failed
1077 */
[e4afb4]1078bool molecule::StoreAdjacencyToFile(std::string filename, std::string path)
[cee0b57]1079{
1080 ofstream AdjacencyFile;
[35b698]1081 string line;
[cee0b57]1082 bool status = true;
1083
[35b698]1084 if (path != "")
1085 line = path + "/" + filename;
[8ab0407]1086 else
[35b698]1087 line = filename;
1088 AdjacencyFile.open(line.c_str(), ios::out);
[acf800]1089 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl);
[35b698]1090 if (AdjacencyFile.good()) {
[1f1b23]1091 AdjacencyFile << "m\tn" << endl;
[00ef5c]1092 for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputAdjacency),&AdjacencyFile));
[cee0b57]1093 AdjacencyFile.close();
[acf800]1094 DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl);
[cee0b57]1095 } else {
[35b698]1096 DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line << "." << endl);
[cee0b57]1097 status = false;
1098 }
1099
1100 return status;
[9eefda]1101}
1102;
[cee0b57]1103
[1f1b23]1104/** Storing the bond structure of a molecule to file.
[5309ba]1105 * Simply stores Atom::Nr and then the Atom::Nr of all bond partners, one per line.
[35b698]1106 * \param &filename name of file
1107 * \param path path to file, defaults to empty
[1f1b23]1108 * \return true - file written successfully, false - writing failed
1109 */
[e4afb4]1110bool molecule::StoreBondsToFile(std::string filename, std::string path)
[1f1b23]1111{
1112 ofstream BondFile;
[35b698]1113 string line;
[1f1b23]1114 bool status = true;
1115
[35b698]1116 if (path != "")
1117 line = path + "/" + filename;
[8ab0407]1118 else
[35b698]1119 line = filename;
1120 BondFile.open(line.c_str(), ios::out);
[acf800]1121 DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... " << endl);
[35b698]1122 if (BondFile.good()) {
[1f1b23]1123 BondFile << "m\tn" << endl;
[00ef5c]1124 for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputBonds),&BondFile));
[1f1b23]1125 BondFile.close();
[acf800]1126 DoLog(1) && (Log() << Verbose(1) << "\t... done." << endl);
[1f1b23]1127 } else {
[35b698]1128 DoLog(1) && (Log() << Verbose(1) << "\t... failed to open file " << line << "." << endl);
[1f1b23]1129 status = false;
1130 }
1131
1132 return status;
1133}
1134;
1135
[35b698]1136bool CheckAdjacencyFileAgainstMolecule_Init(std::string &path, ifstream &File, int *&CurrentBonds)
[ba4170]1137{
[35b698]1138 string filename;
1139 filename = path + ADJACENCYFILE;
1140 File.open(filename.c_str(), ios::out);
[0de7e8]1141 DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl);
[35b698]1142 if (File.fail())
[ba4170]1143 return false;
1144
1145 // allocate storage structure
[1d5afa5]1146 CurrentBonds = new int[MAXBONDS]; // contains parsed bonds of current atom
1147 for(int i=0;i<MAXBONDS;i++)
[920c70]1148 CurrentBonds[i] = 0;
[ba4170]1149 return true;
[9eefda]1150}
1151;
[ba4170]1152
[e138de]1153void CheckAdjacencyFileAgainstMolecule_Finalize(ifstream &File, int *&CurrentBonds)
[ba4170]1154{
1155 File.close();
1156 File.clear();
[920c70]1157 delete[](CurrentBonds);
[9eefda]1158}
1159;
[ba4170]1160
[e138de]1161void CheckAdjacencyFileAgainstMolecule_CompareBonds(bool &status, int &NonMatchNumber, atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, int *&CurrentBonds, atom **ListOfAtoms)
[ba4170]1162{
1163 size_t j = 0;
1164 int id = -1;
1165
[e138de]1166 //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
[9d83b6]1167 const BondList& ListOfBonds = Walker->getListOfBonds();
1168 if (CurrentBondsOfAtom == ListOfBonds.size()) {
1169 for (BondList::const_iterator Runner = ListOfBonds.begin();
1170 Runner != ListOfBonds.end();
1171 ++Runner) {
[735b1c]1172 id = (*Runner)->GetOtherAtom(Walker)->getNr();
[ba4170]1173 j = 0;
[9eefda]1174 for (; (j < CurrentBondsOfAtom) && (CurrentBonds[j++] != id);)
[ba4170]1175 ; // check against all parsed bonds
[9eefda]1176 if (CurrentBonds[j - 1] != id) { // no match ? Then mark in ListOfAtoms
[ba4170]1177 ListOfAtoms[AtomNr] = NULL;
1178 NonMatchNumber++;
1179 status = false;
[0de7e8]1180 DoeLog(2) && (eLog() << Verbose(2) << id << " can not be found in list." << endl);
[ba4170]1181 } else {
[0de7e8]1182 //Log() << Verbose(0) << "[" << id << "]\t";
[ba4170]1183 }
1184 }
[e138de]1185 //Log() << Verbose(0) << endl;
[ba4170]1186 } else {
[9d83b6]1187 DoLog(0) && (Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << ListOfBonds.size() << "." << endl);
[ba4170]1188 status = false;
1189 }
[9eefda]1190}
1191;
[ba4170]1192
[cee0b57]1193/** Checks contents of adjacency file against bond structure in structure molecule.
1194 * \param *path path to file
[5309ba]1195 * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::Nr) to *Atom
[cee0b57]1196 * \return true - structure is equal, false - not equivalence
1197 */
[35b698]1198bool molecule::CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms)
[cee0b57]1199{
1200 ifstream File;
1201 bool status = true;
[266237]1202 atom *Walker = NULL;
[ba4170]1203 int *CurrentBonds = NULL;
[9eefda]1204 int NonMatchNumber = 0; // will number of atoms with differing bond structure
[ba4170]1205 size_t CurrentBondsOfAtom = -1;
[0de7e8]1206 const int AtomCount = getAtomCount();
[cee0b57]1207
[e138de]1208 if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) {
[a67d19]1209 DoLog(1) && (Log() << Verbose(1) << "Adjacency file not found." << endl);
[ba4170]1210 return true;
1211 }
1212
[920c70]1213 char buffer[MAXSTRINGSIZE];
[1d5afa5]1214 int tmp;
[ba4170]1215 // Parse the file line by line and count the bonds
1216 while (!File.eof()) {
1217 File.getline(buffer, MAXSTRINGSIZE);
1218 stringstream line;
1219 line.str(buffer);
1220 int AtomNr = -1;
1221 line >> AtomNr;
1222 CurrentBondsOfAtom = -1; // we count one too far due to line end
1223 // parse into structure
[0de7e8]1224 if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
[ba4170]1225 Walker = ListOfAtoms[AtomNr];
[1d5afa5]1226 while (line >> ws >> tmp) {
1227 std::cout << "Recognized bond partner " << tmp << std::endl;
1228 CurrentBonds[++CurrentBondsOfAtom] = tmp;
1229 ASSERT(CurrentBondsOfAtom < MAXBONDS,
1230 "molecule::CheckAdjacencyFileAgainstMolecule() - encountered more bonds than allowed: "
1231 +toString(CurrentBondsOfAtom)+" >= "+toString(MAXBONDS)+"!");
1232 }
[ba4170]1233 // compare against present bonds
[e138de]1234 CheckAdjacencyFileAgainstMolecule_CompareBonds(status, NonMatchNumber, Walker, CurrentBondsOfAtom, AtomNr, CurrentBonds, ListOfAtoms);
[0de7e8]1235 } else {
1236 if (AtomNr != -1)
1237 DoeLog(2) && (eLog() << Verbose(2) << AtomNr << " is not valid in the range of ids [" << 0 << "," << AtomCount << ")." << endl);
[ba4170]1238 }
[cee0b57]1239 }
[e138de]1240 CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds);
[cee0b57]1241
[ba4170]1242 if (status) { // if equal we parse the KeySetFile
[a67d19]1243 DoLog(1) && (Log() << Verbose(1) << "done: Equal." << endl);
[ba4170]1244 } else
[a67d19]1245 DoLog(1) && (Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl);
[cee0b57]1246 return status;
[9eefda]1247}
1248;
[cee0b57]1249
1250/** Picks from a global stack with all back edges the ones in the fragment.
[5309ba]1251 * \param **ListOfLocalAtoms array of father atom::Nr to local atom::Nr (reverse of atom::father)
[cee0b57]1252 * \param *ReferenceStack stack with all the back egdes
1253 * \param *LocalStack stack to be filled
1254 * \return true - everything ok, false - ReferenceStack was empty
1255 */
[a564be]1256bool molecule::PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const
[cee0b57]1257{
1258 bool status = true;
[a564be]1259 if (ReferenceStack->empty()) {
[a67d19]1260 DoLog(1) && (Log() << Verbose(1) << "ReferenceStack is empty!" << endl);
[cee0b57]1261 return false;
1262 }
[a564be]1263 bond *Binder = ReferenceStack->front();
1264 ReferenceStack->pop_front();
[9eefda]1265 bond *FirstBond = Binder; // mark the first bond, so that we don't loop through the stack indefinitely
[cee0b57]1266 atom *Walker = NULL, *OtherAtom = NULL;
[a564be]1267 ReferenceStack->push_front(Binder);
[cee0b57]1268
[9eefda]1269 do { // go through all bonds and push local ones
[735b1c]1270 Walker = ListOfLocalAtoms[Binder->leftatom->getNr()]; // get one atom in the reference molecule
[9d83b6]1271 if (Walker != NULL) { // if this Walker exists in the subgraph ...
1272 const BondList& ListOfBonds = Walker->getListOfBonds();
1273 for (BondList::const_iterator Runner = ListOfBonds.begin();
1274 Runner != ListOfBonds.end();
1275 ++Runner) {
[266237]1276 OtherAtom = (*Runner)->GetOtherAtom(Walker);
[735b1c]1277 if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->getNr()]) { // found the bond
[a564be]1278 LocalStack->push_front((*Runner));
[a67d19]1279 DoLog(3) && (Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl);
[cee0b57]1280 break;
1281 }
1282 }
[9d83b6]1283 }
[a564be]1284 ASSERT(!ReferenceStack->empty(), "molecule::PickLocalBackEdges() - ReferenceStack is empty!");
1285 Binder = ReferenceStack->front(); // loop the stack for next item
1286 ReferenceStack->pop_front();
[a67d19]1287 DoLog(3) && (Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl);
[a564be]1288 ReferenceStack->push_front(Binder);
[cee0b57]1289 } while (FirstBond != Binder);
1290
1291 return status;
[9eefda]1292}
1293;
[ce7cc5]1294
1295void BreadthFirstSearchAdd_Init(struct BFSAccounting &BFS, atom *&Root, int AtomCount, int BondOrder, atom **AddedAtomList = NULL)
1296{
1297 BFS.AtomCount = AtomCount;
1298 BFS.BondOrder = BondOrder;
[920c70]1299 BFS.PredecessorList = new atom*[AtomCount];
1300 BFS.ShortestPathList = new int[AtomCount];
1301 BFS.ColorList = new enum Shading[AtomCount];
[a564be]1302 BFS.BFSStack = new std::deque<atom *> (AtomCount);
[ce7cc5]1303
1304 BFS.Root = Root;
[a564be]1305 BFS.BFSStack->clear();
1306 BFS.BFSStack->push_front(Root);
[ce7cc5]1307
1308 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
[9eefda]1309 for (int i = AtomCount; i--;) {
[920c70]1310 BFS.PredecessorList[i] = NULL;
[ce7cc5]1311 BFS.ShortestPathList[i] = -1;
1312 if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
1313 BFS.ColorList[i] = lightgray;
1314 else
1315 BFS.ColorList[i] = white;
1316 }
[735b1c]1317 //BFS.ShortestPathList[Root->getNr()] = 0; // done by Calloc
[9eefda]1318}
1319;
[ce7cc5]1320
1321void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS)
1322{
[920c70]1323 delete[](BFS.PredecessorList);
1324 delete[](BFS.ShortestPathList);
1325 delete[](BFS.ColorList);
[9eefda]1326 delete (BFS.BFSStack);
[ce7cc5]1327 BFS.AtomCount = 0;
[9eefda]1328}
1329;
[ce7cc5]1330
[e138de]1331void BreadthFirstSearchAdd_UnvisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)
[ce7cc5]1332{
1333 if (Binder != Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem)
[735b1c]1334 BFS.ColorList[OtherAtom->getNr()] = lightgray;
1335 BFS.PredecessorList[OtherAtom->getNr()] = Walker; // Walker is the predecessor
1336 BFS.ShortestPathList[OtherAtom->getNr()] = BFS.ShortestPathList[Walker->getNr()] + 1;
1337 DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->getName() << " " << ((BFS.ColorList[OtherAtom->getNr()] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->getName() << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->getNr()] << " egde(s) long." << endl);
1338 if ((((BFS.ShortestPathList[OtherAtom->getNr()] < BFS.BondOrder) && (Binder != Bond)))) { // Check for maximum distance
[a67d19]1339 DoLog(3) && (Log() << Verbose(3));
[735b1c]1340 if (AddedAtomList[OtherAtom->getNr()] == NULL) { // add if it's not been so far
1341 AddedAtomList[OtherAtom->getNr()] = Mol->AddCopyAtom(OtherAtom);
[68f03d]1342 DoLog(0) && (Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->getName());
[735b1c]1343 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->getNr()], AddedAtomList[OtherAtom->getNr()], Binder);
[a67d19]1344 DoLog(0) && (Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ");
[9eefda]1345 } else { // this code should actually never come into play (all white atoms are not yet present in BondMolecule, that's why they are white in the first place)
[68f03d]1346 DoLog(0) && (Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->getName());
[ce7cc5]1347 if (AddedBondList[Binder->nr] == NULL) {
[735b1c]1348 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->getNr()], AddedAtomList[OtherAtom->getNr()], Binder);
[a67d19]1349 DoLog(0) && (Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]));
[ce7cc5]1350 } else
[a67d19]1351 DoLog(0) && (Log() << Verbose(0) << ", not added Bond ");
[ce7cc5]1352 }
[a67d19]1353 DoLog(0) && (Log() << Verbose(0) << ", putting OtherAtom into queue." << endl);
[a564be]1354 BFS.BFSStack->push_front(OtherAtom);
[ce7cc5]1355 } else { // out of bond order, then replace
[735b1c]1356 if ((AddedAtomList[OtherAtom->getNr()] == NULL) && (Binder->Cyclic))
1357 BFS.ColorList[OtherAtom->getNr()] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic)
[ce7cc5]1358 if (Binder == Bond)
[a67d19]1359 DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is the Root bond");
[735b1c]1360 else if (BFS.ShortestPathList[OtherAtom->getNr()] >= BFS.BondOrder)
[a67d19]1361 DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder);
[ce7cc5]1362 if (!Binder->Cyclic)
[a67d19]1363 DoLog(0) && (Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl);
[ce7cc5]1364 if (AddedBondList[Binder->nr] == NULL) {
[735b1c]1365 if ((AddedAtomList[OtherAtom->getNr()] != NULL)) { // .. whether we add or saturate
1366 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->getNr()], AddedAtomList[OtherAtom->getNr()], Binder);
[ce7cc5]1367 } else {
[9eefda]1368#ifdef ADDHYDROGEN
[735b1c]1369 if (!Mol->AddHydrogenReplacementAtom(Binder, AddedAtomList[Walker->getNr()], Walker, OtherAtom, IsAngstroem))
[9eefda]1370 exit(1);
1371#endif
[ce7cc5]1372 }
1373 }
1374 }
[9eefda]1375}
1376;
[ce7cc5]1377
[e138de]1378void BreadthFirstSearchAdd_VisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)
[ce7cc5]1379{
[a67d19]1380 DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
[ce7cc5]1381 // This has to be a cyclic bond, check whether it's present ...
1382 if (AddedBondList[Binder->nr] == NULL) {
[735b1c]1383 if ((Binder != Bond) && (Binder->Cyclic) && (((BFS.ShortestPathList[Walker->getNr()] + 1) < BFS.BondOrder))) {
1384 AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->getNr()], AddedAtomList[OtherAtom->getNr()], Binder);
[ce7cc5]1385 } else { // if it's root bond it has to broken (otherwise we would not create the fragments)
[9eefda]1386#ifdef ADDHYDROGEN
[735b1c]1387 if(!Mol->AddHydrogenReplacementAtom(Binder, AddedAtomList[Walker->getNr()], Walker, OtherAtom, IsAngstroem))
[9eefda]1388 exit(1);
1389#endif
[ce7cc5]1390 }
1391 }
[9eefda]1392}
1393;
[cee0b57]1394
1395/** Adds atoms up to \a BondCount distance from \a *Root and notes them down in \a **AddedAtomList.
[a564be]1396 * Gray vertices are always enqueued in an std::deque<atom *> FIFO queue, the rest is usual BFS with adding vertices found was
[cee0b57]1397 * white and putting into queue.
1398 * \param *Mol Molecule class to add atoms to
1399 * \param **AddedAtomList list with added atom pointers, index is atom father's number
1400 * \param **AddedBondList list with added bond pointers, index is bond father's number
1401 * \param *Root root vertex for BFS
1402 * \param *Bond bond not to look beyond
1403 * \param BondOrder maximum distance for vertices to add
1404 * \param IsAngstroem lengths are in angstroem or bohrradii
1405 */
[e138de]1406void molecule::BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
[cee0b57]1407{
[ce7cc5]1408 struct BFSAccounting BFS;
[cee0b57]1409 atom *Walker = NULL, *OtherAtom = NULL;
[ce7cc5]1410 bond *Binder = NULL;
[cee0b57]1411
1412 // add Root if not done yet
[735b1c]1413 if (AddedAtomList[Root->getNr()] == NULL) // add Root if not yet present
1414 AddedAtomList[Root->getNr()] = Mol->AddCopyAtom(Root);
[cee0b57]1415
[ea7176]1416 BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, getAtomCount(), AddedAtomList);
[cee0b57]1417
1418 // and go on ... Queue always contains all lightgray vertices
[a564be]1419 while (!BFS.BFSStack->empty()) {
[cee0b57]1420 // we have to pop the oldest atom from stack. This keeps the atoms on the stack always of the same ShortestPath distance.
1421 // e.g. if current atom is 2, push to end of stack are of length 3, but first all of length 2 would be popped. They again
1422 // append length of 3 (their neighbours). Thus on stack we have always atoms of a certain length n at bottom of stack and
1423 // followed by n+1 till top of stack.
[a564be]1424 Walker = BFS.BFSStack->front(); // pop oldest added
1425 BFS.BFSStack->pop_front();
[9d83b6]1426 const BondList& ListOfBonds = Walker->getListOfBonds();
1427 DoLog(1) && (Log() << Verbose(1) << "Current Walker is: " << Walker->getName() << ", and has " << ListOfBonds.size() << " bonds." << endl);
1428 for (BondList::const_iterator Runner = ListOfBonds.begin();
1429 Runner != ListOfBonds.end();
1430 ++Runner) {
[266237]1431 if ((*Runner) != NULL) { // don't look at bond equal NULL
[ce7cc5]1432 Binder = (*Runner);
[266237]1433 OtherAtom = (*Runner)->GetOtherAtom(Walker);
[68f03d]1434 DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->getName() << " for bond " << *(*Runner) << "." << endl);
[735b1c]1435 if (BFS.ColorList[OtherAtom->getNr()] == white) {
[e138de]1436 BreadthFirstSearchAdd_UnvisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);
[cee0b57]1437 } else {
[e138de]1438 BreadthFirstSearchAdd_VisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);
[cee0b57]1439 }
1440 }
1441 }
[735b1c]1442 BFS.ColorList[Walker->getNr()] = black;
[68f03d]1443 DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->getName() << " black." << endl);
[cee0b57]1444 }
[ce7cc5]1445 BreadthFirstSearchAdd_Free(BFS);
[9eefda]1446}
1447;
[cee0b57]1448
[266237]1449/** Adds a bond as a copy to a given one
1450 * \param *left leftatom of new bond
1451 * \param *right rightatom of new bond
1452 * \param *CopyBond rest of fields in bond are copied from this
1453 * \return pointer to new bond
1454 */
1455bond * molecule::CopyBond(atom *left, atom *right, bond *CopyBond)
1456{
1457 bond *Binder = AddBond(left, right, CopyBond->BondDegree);
1458 Binder->Cyclic = CopyBond->Cyclic;
1459 Binder->Type = CopyBond->Type;
1460 return Binder;
[9eefda]1461}
1462;
[266237]1463
[e138de]1464void BuildInducedSubgraph_Init(atom **&ParentList, int AtomCount)
[cee0b57]1465{
1466 // reset parent list
[920c70]1467 ParentList = new atom*[AtomCount];
1468 for (int i=0;i<AtomCount;i++)
1469 ParentList[i] = NULL;
[a67d19]1470 DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
[9eefda]1471}
1472;
[cee0b57]1473
[e138de]1474void BuildInducedSubgraph_FillParentList(const molecule *mol, const molecule *Father, atom **&ParentList)
[43587e]1475{
[cee0b57]1476 // fill parent list with sons
[a67d19]1477 DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);
[9879f6]1478 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
[735b1c]1479 ParentList[(*iter)->father->getNr()] = (*iter);
[cee0b57]1480 // Outputting List for debugging
[735b1c]1481 DoLog(4) && (Log() << Verbose(4) << "Son[" << (*iter)->father->getNr() << "] of " << (*iter)->father << " is " << ParentList[(*iter)->father->getNr()] << "." << endl);
[cee0b57]1482 }
[a7b761b]1483};
[43587e]1484
[e138de]1485void BuildInducedSubgraph_Finalize(atom **&ParentList)
[43587e]1486{
[920c70]1487 delete[](ParentList);
[9eefda]1488}
1489;
[43587e]1490
[e138de]1491bool BuildInducedSubgraph_CreateBondsFromParent(molecule *mol, const molecule *Father, atom **&ParentList)
[43587e]1492{
1493 bool status = true;
1494 atom *OtherAtom = NULL;
[cee0b57]1495 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
[a67d19]1496 DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);
[9879f6]1497 for (molecule::const_iterator iter = Father->begin(); iter != Father->end(); ++iter) {
[735b1c]1498 if (ParentList[(*iter)->getNr()] != NULL) {
1499 if (ParentList[(*iter)->getNr()]->father != (*iter)) {
[cee0b57]1500 status = false;
1501 } else {
[9d83b6]1502 const BondList& ListOfBonds = (*iter)->getListOfBonds();
1503 for (BondList::const_iterator Runner = ListOfBonds.begin();
1504 Runner != ListOfBonds.end();
1505 ++Runner) {
[9879f6]1506 OtherAtom = (*Runner)->GetOtherAtom((*iter));
[735b1c]1507 if (ParentList[OtherAtom->getNr()] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
1508 DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[(*iter)->getNr()]->getName() << " and " << ParentList[OtherAtom->getNr()]->getName() << "." << endl);
1509 mol->AddBond(ParentList[(*iter)->getNr()], ParentList[OtherAtom->getNr()], (*Runner)->BondDegree);
[cee0b57]1510 }
1511 }
1512 }
1513 }
1514 }
[43587e]1515 return status;
[9eefda]1516}
1517;
[cee0b57]1518
[43587e]1519/** Adds bond structure to this molecule from \a Father molecule.
1520 * This basically causes this molecule to become an induced subgraph of the \a Father, i.e. for every bond in Father
1521 * with end points present in this molecule, bond is created in this molecule.
1522 * Special care was taken to ensure that this is of complexity O(N), where N is the \a Father's molecule::AtomCount.
1523 * \param *Father father molecule
1524 * \return true - is induced subgraph, false - there are atoms with fathers not in \a Father
1525 * \todo not checked, not fully working probably
1526 */
[9d37ac]1527bool molecule::BuildInducedSubgraph(const molecule *Father){
[43587e]1528 bool status = true;
1529 atom **ParentList = NULL;
[a67d19]1530 DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);
[ea7176]1531 BuildInducedSubgraph_Init(ParentList, Father->getAtomCount());
[e138de]1532 BuildInducedSubgraph_FillParentList(this, Father, ParentList);
1533 status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
1534 BuildInducedSubgraph_Finalize(ParentList);
[a67d19]1535 DoLog(2) && (Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl);
[cee0b57]1536 return status;
[9eefda]1537}
1538;
[cee0b57]1539
1540/** For a given keyset \a *Fragment, checks whether it is connected in the current molecule.
1541 * \param *Fragment Keyset of fragment's vertices
1542 * \return true - connected, false - disconnected
1543 * \note this is O(n^2) for it's just a bug checker not meant for permanent use!
1544 */
[e138de]1545bool molecule::CheckForConnectedSubgraph(KeySet *Fragment)
[cee0b57]1546{
1547 atom *Walker = NULL, *Walker2 = NULL;
1548 bool BondStatus = false;
1549 int size;
1550
[a67d19]1551 DoLog(1) && (Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl);
1552 DoLog(2) && (Log() << Verbose(2) << "Disconnected atom: ");
[cee0b57]1553
1554 // count number of atoms in graph
1555 size = 0;
[9eefda]1556 for (KeySet::iterator runner = Fragment->begin(); runner != Fragment->end(); runner++)
[cee0b57]1557 size++;
1558 if (size > 1)
[9eefda]1559 for (KeySet::iterator runner = Fragment->begin(); runner != Fragment->end(); runner++) {
[cee0b57]1560 Walker = FindAtom(*runner);
1561 BondStatus = false;
[9eefda]1562 for (KeySet::iterator runners = Fragment->begin(); runners != Fragment->end(); runners++) {
[cee0b57]1563 Walker2 = FindAtom(*runners);
[9d83b6]1564 const BondList& ListOfBonds = Walker->getListOfBonds();
1565 for (BondList::const_iterator Runner = ListOfBonds.begin();
1566 Runner != ListOfBonds.end();
1567 ++Runner) {
[266237]1568 if ((*Runner)->GetOtherAtom(Walker) == Walker2) {
[cee0b57]1569 BondStatus = true;
1570 break;
1571 }
1572 if (BondStatus)
1573 break;
1574 }
1575 }
1576 if (!BondStatus) {
[a67d19]1577 DoLog(0) && (Log() << Verbose(0) << (*Walker) << endl);
[cee0b57]1578 return false;
1579 }
1580 }
1581 else {
[a67d19]1582 DoLog(0) && (Log() << Verbose(0) << "none." << endl);
[cee0b57]1583 return true;
1584 }
[a67d19]1585 DoLog(0) && (Log() << Verbose(0) << "none." << endl);
[cee0b57]1586
[a67d19]1587 DoLog(1) && (Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl);
[cee0b57]1588
1589 return true;
1590}
Note: See TracBrowser for help on using the repository browser.