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