| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [94d5ac6] | 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/>. | 
|---|
| [bcf653] | 21 | */ | 
|---|
|  | 22 |  | 
|---|
| [cee0b57] | 23 | /* | 
|---|
|  | 24 | * molecule_graph.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Oct 5, 2009 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [bf3817] | 30 | // include config.h | 
|---|
| [aafd77] | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [112b09] | 36 |  | 
|---|
| [a564be] | 37 | #include <stack> | 
|---|
|  | 38 |  | 
|---|
| [6f0841] | 39 | #include "Atom/atom.hpp" | 
|---|
| [129204] | 40 | #include "Bond/bond.hpp" | 
|---|
| [34c43a] | 41 | #include "Box.hpp" | 
|---|
|  | 42 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 43 | #include "CodePatterns/Info.hpp" | 
|---|
|  | 44 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 45 | #include "CodePatterns/Verbose.hpp" | 
|---|
| [cee0b57] | 46 | #include "config.hpp" | 
|---|
| [49c059] | 47 | #include "Graph/DepthFirstSearchAnalysis.hpp" | 
|---|
| [3bdb6d] | 48 | #include "Element/element.hpp" | 
|---|
| [129204] | 49 | #include "Graph/BondGraph.hpp" | 
|---|
| [1d5afa5] | 50 | #include "Helpers/defs.hpp" | 
|---|
| [246e13] | 51 | #include "Helpers/helpers.hpp" | 
|---|
| [1d5afa5] | 52 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| [53c7fc] | 53 | #include "LinkedCell/linkedcell.hpp" | 
|---|
|  | 54 | #include "LinkedCell/PointCloudAdaptor.hpp" | 
|---|
| [cee0b57] | 55 | #include "molecule.hpp" | 
|---|
| [b34306] | 56 | #include "World.hpp" | 
|---|
| [9d83b6] | 57 | #include "WorldTime.hpp" | 
|---|
| [1d5afa5] | 58 |  | 
|---|
| [cee0b57] | 59 |  | 
|---|
| [99752a] | 60 | /** Fills the bond structure of this chain list subgraphs that are derived from a complete \a *reference molecule. | 
|---|
|  | 61 | * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL. | 
|---|
|  | 62 | * \param *reference reference molecule with the bond structure to be copied | 
|---|
|  | 63 | * \param **&ListOfLocalAtoms Lookup table for this subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled | 
|---|
|  | 64 | * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not | 
|---|
|  | 65 | * \return true - success, false - failure | 
|---|
|  | 66 | */ | 
|---|
|  | 67 | bool molecule::FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList) | 
|---|
|  | 68 | { | 
|---|
|  | 69 | bool status = true; | 
|---|
|  | 70 |  | 
|---|
| [47d041] | 71 | LOG(1, "Begin of FillBondStructureFromReference."); | 
|---|
| [99752a] | 72 | // fill ListOfLocalAtoms if NULL was given | 
|---|
|  | 73 | if (!FillListOfLocalAtoms(ListOfLocalAtoms, reference->getAtomCount())) { | 
|---|
| [47d041] | 74 | LOG(1, "Filling of ListOfLocalAtoms failed."); | 
|---|
| [99752a] | 75 | return false; | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | if (status) { | 
|---|
| [47d041] | 79 | LOG(1, "Creating adjacency list for molecule " << getName() << "."); | 
|---|
| [99752a] | 80 | // remove every bond from the list | 
|---|
|  | 81 | for_each(begin(), end(), | 
|---|
|  | 82 | boost::bind(&BondedParticle::ClearBondsAtStep,_1,WorldTime::getTime())); | 
|---|
|  | 83 |  | 
|---|
|  | 84 |  | 
|---|
| [59fff1] | 85 | for(molecule::iterator iter = begin(); iter != end(); ++iter) { | 
|---|
|  | 86 | const atom * const Father = (*iter)->GetTrueFather(); | 
|---|
| [c9cafa] | 87 | //const int AtomNo = Father->getNr(); // global id of the current walker | 
|---|
| [99752a] | 88 | const BondList& ListOfBonds = Father->getListOfBonds(); | 
|---|
|  | 89 | for (BondList::const_iterator Runner = ListOfBonds.begin(); | 
|---|
|  | 90 | Runner != ListOfBonds.end(); | 
|---|
|  | 91 | ++Runner) { | 
|---|
| [59fff1] | 92 | atom * const OtherAtom = (*Runner)->GetOtherAtom((*iter)->GetTrueFather()); | 
|---|
|  | 93 | atom * const OtherWalker = ListOfLocalAtoms[OtherAtom->getNr()]; // local copy of current bond partner of walker | 
|---|
| [99752a] | 94 | if (OtherWalker != NULL) { | 
|---|
|  | 95 | if (OtherWalker->getNr() > (*iter)->getNr()) | 
|---|
|  | 96 | AddBond((*iter), OtherWalker, (*Runner)->BondDegree); | 
|---|
|  | 97 | } else { | 
|---|
| [59fff1] | 98 | LOG(1, "OtherWalker = ListOfLocalAtoms[" << OtherAtom->getNr() << "] is NULL!"); | 
|---|
| [99752a] | 99 | status = false; | 
|---|
|  | 100 | } | 
|---|
|  | 101 | } | 
|---|
|  | 102 | } | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | if ((FreeList) && (ListOfLocalAtoms != NULL)) { | 
|---|
|  | 106 | // free the index lookup list | 
|---|
|  | 107 | delete[](ListOfLocalAtoms); | 
|---|
|  | 108 | } | 
|---|
| [47d041] | 109 | LOG(1, "End of FillBondStructureFromReference."); | 
|---|
| [99752a] | 110 | return status; | 
|---|
|  | 111 | }; | 
|---|
|  | 112 |  | 
|---|
| [e08c46] | 113 | /** Checks for presence of bonds within atom list. | 
|---|
|  | 114 | * TODO: more sophisticated check for bond structure (e.g. connected subgraph, ...) | 
|---|
|  | 115 | * \return true - bonds present, false - no bonds | 
|---|
|  | 116 | */ | 
|---|
| [e4afb4] | 117 | bool molecule::hasBondStructure() const | 
|---|
| [e08c46] | 118 | { | 
|---|
| [9d83b6] | 119 | for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) { | 
|---|
| [5e2f80] | 120 | //LOG(0, "molecule::hasBondStructure() - checking bond list of atom " << (*AtomRunner)->getId() << "."); | 
|---|
| [9d83b6] | 121 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 122 | if (!ListOfBonds.empty()) | 
|---|
| [e08c46] | 123 | return true; | 
|---|
| [9d83b6] | 124 | } | 
|---|
| [e08c46] | 125 | return false; | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
| [b8b75d] | 128 | /** Prints a list of all bonds to \a *out. | 
|---|
|  | 129 | */ | 
|---|
| [e138de] | 130 | void molecule::OutputBondsList() const | 
|---|
| [b8b75d] | 131 | { | 
|---|
| [47d041] | 132 | if (DoLog(1)) { | 
|---|
|  | 133 | std::stringstream output; | 
|---|
|  | 134 | output << std::endl << "From contents of bond chain list:"; | 
|---|
|  | 135 | for(molecule::const_iterator AtomRunner = molecule::begin(); AtomRunner != molecule::end(); ++AtomRunner) { | 
|---|
|  | 136 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 137 | for(BondList::const_iterator BondRunner = ListOfBonds.begin(); | 
|---|
|  | 138 | BondRunner != ListOfBonds.end(); | 
|---|
|  | 139 | ++BondRunner) | 
|---|
|  | 140 | if ((*BondRunner)->leftatom == *AtomRunner) { | 
|---|
|  | 141 | output << *(*BondRunner) << "\t"; | 
|---|
|  | 142 | } | 
|---|
|  | 143 | } | 
|---|
|  | 144 | LOG(1, output.str()); | 
|---|
| [9d83b6] | 145 | } | 
|---|
| [9eefda] | 146 | } | 
|---|
| [cee0b57] | 147 |  | 
|---|
|  | 148 |  | 
|---|
|  | 149 | /** Storing the bond structure of a molecule to file. | 
|---|
| [5309ba] | 150 | * Simply stores Atom::Nr and then the Atom::Nr of all bond partners per line. | 
|---|
| [35b698] | 151 | * \param &filename name of file | 
|---|
|  | 152 | * \param path path to file, defaults to empty | 
|---|
| [cee0b57] | 153 | * \return true - file written successfully, false - writing failed | 
|---|
|  | 154 | */ | 
|---|
| [e4afb4] | 155 | bool molecule::StoreAdjacencyToFile(std::string filename, std::string path) | 
|---|
| [cee0b57] | 156 | { | 
|---|
|  | 157 | ofstream AdjacencyFile; | 
|---|
| [35b698] | 158 | string line; | 
|---|
| [cee0b57] | 159 | bool status = true; | 
|---|
|  | 160 |  | 
|---|
| [35b698] | 161 | if (path != "") | 
|---|
|  | 162 | line = path + "/" + filename; | 
|---|
| [8ab0407] | 163 | else | 
|---|
| [35b698] | 164 | line = filename; | 
|---|
|  | 165 | AdjacencyFile.open(line.c_str(), ios::out); | 
|---|
| [47d041] | 166 | LOG(1, "Saving adjacency list ... "); | 
|---|
| [35b698] | 167 | if (AdjacencyFile.good()) { | 
|---|
| [1f1b23] | 168 | AdjacencyFile << "m\tn" << endl; | 
|---|
| [30c753] | 169 | for_each(begin(),end(),bind2nd(mem_fun(&atom::OutputAdjacency),&AdjacencyFile)); | 
|---|
| [cee0b57] | 170 | AdjacencyFile.close(); | 
|---|
| [47d041] | 171 | LOG(1, "\t... done."); | 
|---|
| [cee0b57] | 172 | } else { | 
|---|
| [47d041] | 173 | LOG(1, "\t... failed to open file " << line << "."); | 
|---|
| [cee0b57] | 174 | status = false; | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 | return status; | 
|---|
| [9eefda] | 178 | } | 
|---|
|  | 179 | ; | 
|---|
| [cee0b57] | 180 |  | 
|---|
| [1f1b23] | 181 | /** Storing the bond structure of a molecule to file. | 
|---|
| [5309ba] | 182 | * Simply stores Atom::Nr and then the Atom::Nr of all bond partners, one per line. | 
|---|
| [35b698] | 183 | * \param &filename name of file | 
|---|
|  | 184 | * \param path path to file, defaults to empty | 
|---|
| [1f1b23] | 185 | * \return true - file written successfully, false - writing failed | 
|---|
|  | 186 | */ | 
|---|
| [e4afb4] | 187 | bool molecule::StoreBondsToFile(std::string filename, std::string path) | 
|---|
| [1f1b23] | 188 | { | 
|---|
|  | 189 | ofstream BondFile; | 
|---|
| [35b698] | 190 | string line; | 
|---|
| [1f1b23] | 191 | bool status = true; | 
|---|
|  | 192 |  | 
|---|
| [35b698] | 193 | if (path != "") | 
|---|
|  | 194 | line = path + "/" + filename; | 
|---|
| [8ab0407] | 195 | else | 
|---|
| [35b698] | 196 | line = filename; | 
|---|
|  | 197 | BondFile.open(line.c_str(), ios::out); | 
|---|
| [47d041] | 198 | LOG(1, "Saving adjacency list ... "); | 
|---|
| [35b698] | 199 | if (BondFile.good()) { | 
|---|
| [1f1b23] | 200 | BondFile << "m\tn" << endl; | 
|---|
| [30c753] | 201 | for_each(begin(),end(),bind2nd(mem_fun(&atom::OutputBonds),&BondFile)); | 
|---|
| [1f1b23] | 202 | BondFile.close(); | 
|---|
| [47d041] | 203 | LOG(1, "\t... done."); | 
|---|
| [1f1b23] | 204 | } else { | 
|---|
| [47d041] | 205 | LOG(1, "\t... failed to open file " << line << "."); | 
|---|
| [1f1b23] | 206 | status = false; | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
|  | 209 | return status; | 
|---|
|  | 210 | } | 
|---|
|  | 211 | ; | 
|---|
|  | 212 |  | 
|---|
| [266237] | 213 | /** Adds a bond as a copy to a given one | 
|---|
|  | 214 | * \param *left leftatom of new bond | 
|---|
|  | 215 | * \param *right rightatom of new bond | 
|---|
|  | 216 | * \param *CopyBond rest of fields in bond are copied from this | 
|---|
|  | 217 | * \return pointer to new bond | 
|---|
|  | 218 | */ | 
|---|
|  | 219 | bond * molecule::CopyBond(atom *left, atom *right, bond *CopyBond) | 
|---|
|  | 220 | { | 
|---|
|  | 221 | bond *Binder = AddBond(left, right, CopyBond->BondDegree); | 
|---|
|  | 222 | Binder->Cyclic = CopyBond->Cyclic; | 
|---|
|  | 223 | Binder->Type = CopyBond->Type; | 
|---|
|  | 224 | return Binder; | 
|---|
| [9eefda] | 225 | } | 
|---|
|  | 226 | ; | 
|---|
| [266237] | 227 |  | 
|---|
| [49c059] | 228 | /** Fills a lookup list of father's Atom::nr -> atom for each subgraph. | 
|---|
| [c6123b] | 229 | * \param **&ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled | 
|---|
|  | 230 | * \param GlobalAtomCount number of atoms in the complete molecule | 
|---|
|  | 231 | * \return true - success, false - failure (ListOfLocalAtoms != NULL) | 
|---|
|  | 232 | */ | 
|---|
|  | 233 | bool molecule::FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount) | 
|---|
|  | 234 | { | 
|---|
|  | 235 | bool status = true; | 
|---|
|  | 236 |  | 
|---|
|  | 237 | if (ListOfLocalAtoms == NULL) { // allocate and fill list of this fragment/subgraph | 
|---|
|  | 238 | status = status && CreateFatherLookupTable(ListOfLocalAtoms, GlobalAtomCount); | 
|---|
|  | 239 | } else | 
|---|
|  | 240 | return false; | 
|---|
|  | 241 |  | 
|---|
|  | 242 | return status; | 
|---|
|  | 243 | } | 
|---|
|  | 244 |  | 
|---|
| [246e13] | 245 |  | 
|---|
|  | 246 | /** Creates a lookup table for true father's Atom::Nr -> atom ptr. | 
|---|
|  | 247 | * \param *start begin of list (STL iterator, i.e. first item) | 
|---|
|  | 248 | * \paran *end end of list (STL iterator, i.e. one past last item) | 
|---|
|  | 249 | * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start) | 
|---|
|  | 250 | * \param count optional predetermined size for table (otherwise we set the count to highest true father id) | 
|---|
|  | 251 | * \return true - success, false - failure | 
|---|
|  | 252 | */ | 
|---|
|  | 253 | bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count) | 
|---|
|  | 254 | { | 
|---|
|  | 255 | bool status = true; | 
|---|
|  | 256 | int AtomNo; | 
|---|
|  | 257 |  | 
|---|
|  | 258 | if (LookupTable != NULL) { | 
|---|
| [47d041] | 259 | ELOG(1, "Pointer for Lookup table is not NULL! Aborting ..."); | 
|---|
| [246e13] | 260 | return false; | 
|---|
|  | 261 | } | 
|---|
|  | 262 |  | 
|---|
|  | 263 | // count them | 
|---|
|  | 264 | if (count == 0) { | 
|---|
|  | 265 | for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::Nr -> atom) used as a marker table lateron | 
|---|
|  | 266 | count = (count < (*iter)->GetTrueFather()->getNr()) ? (*iter)->GetTrueFather()->getNr() : count; | 
|---|
|  | 267 | } | 
|---|
|  | 268 | } | 
|---|
|  | 269 | if (count <= 0) { | 
|---|
| [47d041] | 270 | ELOG(1, "Count of lookup list is 0 or less."); | 
|---|
| [246e13] | 271 | return false; | 
|---|
|  | 272 | } | 
|---|
|  | 273 |  | 
|---|
|  | 274 | // allocate and fill | 
|---|
| [52ed5b] | 275 | LookupTable = new atom *[count+1]; | 
|---|
| [246e13] | 276 | if (LookupTable == NULL) { | 
|---|
| [47d041] | 277 | ELOG(0, "LookupTable memory allocation failed!"); | 
|---|
| [246e13] | 278 | performCriticalExit(); | 
|---|
|  | 279 | status = false; | 
|---|
|  | 280 | } else { | 
|---|
| [52ed5b] | 281 | for (int i=0;i<=count;i++) | 
|---|
| [246e13] | 282 | LookupTable[i] = NULL; | 
|---|
|  | 283 | for (molecule::iterator iter = begin(); iter != end(); ++iter) { | 
|---|
|  | 284 | AtomNo = (*iter)->GetTrueFather()->getNr(); | 
|---|
| [52ed5b] | 285 | if ((AtomNo >= 0) && (AtomNo <= count)) { | 
|---|
|  | 286 | LOG(3, "DEBUG: Setting LookupTable[" << AtomNo << "] to " << *(*iter)); | 
|---|
| [246e13] | 287 | LookupTable[AtomNo] = (*iter); | 
|---|
|  | 288 | } else { | 
|---|
| [52ed5b] | 289 | ELOG(1, "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << "]."); | 
|---|
| [246e13] | 290 | status = false; | 
|---|
|  | 291 | break; | 
|---|
|  | 292 | } | 
|---|
|  | 293 | } | 
|---|
|  | 294 | } | 
|---|
|  | 295 |  | 
|---|
|  | 296 | return status; | 
|---|
|  | 297 | }; | 
|---|
|  | 298 |  | 
|---|
|  | 299 |  | 
|---|
|  | 300 |  | 
|---|
|  | 301 | /** Corrects the nuclei position if the fragment was created over the cell borders. | 
|---|
|  | 302 | * Scans all bonds, checks the distance, if greater than typical, we have a candidate for the correction. | 
|---|
|  | 303 | * We remove the bond whereafter the graph probably separates. Then, we translate the one component periodically | 
|---|
|  | 304 | * and re-add the bond. Looping on the distance check. | 
|---|
|  | 305 | * \param *out ofstream for debugging messages | 
|---|
|  | 306 | */ | 
|---|
|  | 307 | bool molecule::ScanForPeriodicCorrection() | 
|---|
|  | 308 | { | 
|---|
|  | 309 | bond *Binder = NULL; | 
|---|
|  | 310 | //bond *OtherBinder = NULL; | 
|---|
|  | 311 | atom *Walker = NULL; | 
|---|
|  | 312 | atom *OtherWalker = NULL; | 
|---|
|  | 313 | RealSpaceMatrix matrix = World::getInstance().getDomain().getM(); | 
|---|
|  | 314 | enum GraphEdge::Shading *ColorList = NULL; | 
|---|
|  | 315 | double tmp; | 
|---|
|  | 316 | //bool LastBond = true; // only needed to due list construct | 
|---|
|  | 317 | Vector Translationvector; | 
|---|
|  | 318 | //std::deque<atom *> *CompStack = NULL; | 
|---|
|  | 319 | std::deque<atom *> *AtomStack = new std::deque<atom *>; // (getAtomCount()); | 
|---|
|  | 320 | bool flag = true; | 
|---|
|  | 321 | BondGraph *BG = World::getInstance().getBondGraph(); | 
|---|
|  | 322 |  | 
|---|
| [47d041] | 323 | LOG(2, "Begin of ScanForPeriodicCorrection."); | 
|---|
| [246e13] | 324 |  | 
|---|
|  | 325 | ColorList = new enum GraphEdge::Shading[getAtomCount()]; | 
|---|
|  | 326 | for (int i=0;i<getAtomCount();i++) | 
|---|
|  | 327 | ColorList[i] = (enum GraphEdge::Shading)0; | 
|---|
|  | 328 | if (flag) { | 
|---|
|  | 329 | // remove bonds that are beyond bonddistance | 
|---|
|  | 330 | Translationvector.Zero(); | 
|---|
|  | 331 | // scan all bonds | 
|---|
|  | 332 | flag = false; | 
|---|
|  | 333 | for(molecule::iterator AtomRunner = begin(); (!flag) && (AtomRunner != end()); ++AtomRunner) { | 
|---|
|  | 334 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 335 | for(BondList::const_iterator BondRunner = ListOfBonds.begin(); | 
|---|
|  | 336 | (!flag) && (BondRunner != ListOfBonds.end()); | 
|---|
|  | 337 | ++BondRunner) { | 
|---|
|  | 338 | Binder = (*BondRunner); | 
|---|
|  | 339 | for (int i=NDIM;i--;) { | 
|---|
|  | 340 | tmp = fabs(Binder->leftatom->at(i) - Binder->rightatom->at(i)); | 
|---|
| [47d041] | 341 | //LOG(3, "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "."); | 
|---|
| [246e13] | 342 | const range<double> MinMaxDistance( | 
|---|
|  | 343 | BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom)); | 
|---|
|  | 344 | if (!MinMaxDistance.isInRange(tmp)) { | 
|---|
| [47d041] | 345 | LOG(2, "Correcting at bond " << *Binder << "."); | 
|---|
| [246e13] | 346 | flag = true; | 
|---|
|  | 347 | break; | 
|---|
|  | 348 | } | 
|---|
|  | 349 | } | 
|---|
|  | 350 | } | 
|---|
|  | 351 | } | 
|---|
|  | 352 | //if (flag) { | 
|---|
|  | 353 | if (0) { | 
|---|
|  | 354 | // create translation vector from their periodically modified distance | 
|---|
|  | 355 | for (int i=NDIM;i--;) { | 
|---|
|  | 356 | tmp = Binder->leftatom->at(i) - Binder->rightatom->at(i); | 
|---|
|  | 357 | const range<double> MinMaxDistance( | 
|---|
|  | 358 | BG->getMinMaxDistance(Binder->leftatom, Binder->rightatom)); | 
|---|
|  | 359 | if (fabs(tmp) > MinMaxDistance.last)  // check against Min is not useful for components | 
|---|
|  | 360 | Translationvector[i] = (tmp < 0) ? +1. : -1.; | 
|---|
|  | 361 | } | 
|---|
|  | 362 | Translationvector *= matrix; | 
|---|
| [47d041] | 363 | LOG(3, "INFO: Translation vector is " << Translationvector << "."); | 
|---|
| [246e13] | 364 | // apply to all atoms of first component via BFS | 
|---|
|  | 365 | for (int i=getAtomCount();i--;) | 
|---|
|  | 366 | ColorList[i] = GraphEdge::white; | 
|---|
|  | 367 | AtomStack->push_front(Binder->leftatom); | 
|---|
|  | 368 | while (!AtomStack->empty()) { | 
|---|
|  | 369 | Walker = AtomStack->front(); | 
|---|
|  | 370 | AtomStack->pop_front(); | 
|---|
| [47d041] | 371 | //LOG(3, "INFO: Current Walker is: " << *Walker << "."); | 
|---|
| [246e13] | 372 | ColorList[Walker->getNr()] = GraphEdge::black;    // mark as explored | 
|---|
|  | 373 | *Walker += Translationvector; // translate | 
|---|
|  | 374 | const BondList& ListOfBonds = Walker->getListOfBonds(); | 
|---|
|  | 375 | for (BondList::const_iterator Runner = ListOfBonds.begin(); | 
|---|
|  | 376 | Runner != ListOfBonds.end(); | 
|---|
|  | 377 | ++Runner) { | 
|---|
|  | 378 | if ((*Runner) != Binder) { | 
|---|
|  | 379 | OtherWalker = (*Runner)->GetOtherAtom(Walker); | 
|---|
|  | 380 | if (ColorList[OtherWalker->getNr()] == GraphEdge::white) { | 
|---|
|  | 381 | AtomStack->push_front(OtherWalker); // push if yet unexplored | 
|---|
|  | 382 | } | 
|---|
|  | 383 | } | 
|---|
|  | 384 | } | 
|---|
|  | 385 | } | 
|---|
|  | 386 | //      // re-add bond | 
|---|
|  | 387 | //      if (OtherBinder == NULL) { // is the only bond? | 
|---|
|  | 388 | //        //Do nothing | 
|---|
|  | 389 | //      } else { | 
|---|
|  | 390 | //        if (!LastBond) { | 
|---|
|  | 391 | //          link(Binder, OtherBinder); // no more implemented bond::previous ... | 
|---|
|  | 392 | //        } else { | 
|---|
|  | 393 | //          link(OtherBinder, Binder); // no more implemented bond::previous ... | 
|---|
|  | 394 | //        } | 
|---|
|  | 395 | //      } | 
|---|
|  | 396 | } else { | 
|---|
| [47d041] | 397 | LOG(3, "No corrections for this fragment."); | 
|---|
| [246e13] | 398 | } | 
|---|
|  | 399 | //delete(CompStack); | 
|---|
|  | 400 | } | 
|---|
|  | 401 | // free allocated space from ReturnFullMatrixforSymmetric() | 
|---|
|  | 402 | delete(AtomStack); | 
|---|
|  | 403 | delete[](ColorList); | 
|---|
| [47d041] | 404 | LOG(2, "End of ScanForPeriodicCorrection."); | 
|---|
| [246e13] | 405 |  | 
|---|
|  | 406 | return flag; | 
|---|
|  | 407 | }; | 
|---|