| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [94d5ac6] | 6 |  * 
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 13 |  *    (at your option) any later version.
 | 
|---|
 | 14 |  *
 | 
|---|
 | 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 18 |  *    GNU General Public License for more details.
 | 
|---|
 | 19 |  *
 | 
|---|
 | 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
| [97ebf8] | 24 | /*
 | 
|---|
 | 25 |  * FragmentationAction.cpp
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  *  Created on: May 9, 2010
 | 
|---|
 | 28 |  *      Author: heber
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
| [bf3817] | 31 | // include config.h
 | 
|---|
 | 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 33 | #include <config.h>
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
| [ad011c] | 36 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 37 | 
 | 
|---|
| [6f0841] | 38 | #include "Atom/atom.hpp"
 | 
|---|
| [c7c615] | 39 | #include "CodePatterns/IteratorAdaptors.hpp"
 | 
|---|
| [ad011c] | 40 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [79d0b9] | 41 | #include "Descriptors/AtomSelectionDescriptor.hpp"
 | 
|---|
| [270bdf] | 42 | #include "Descriptors/MoleculeIdDescriptor.hpp"
 | 
|---|
| [ca8bea] | 43 | #include "Fragmentation/Exporters/ExportGraph_ToFiles.hpp"
 | 
|---|
| [ac9ca4] | 44 | #include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
 | 
|---|
| [5d5550] | 45 | #include "Fragmentation/Exporters/SaturatedBond.hpp"
 | 
|---|
| [98a293b] | 46 | #include "Fragmentation/Exporters/SaturatedFragment.hpp"
 | 
|---|
| [5d5550] | 47 | #include "Fragmentation/Exporters/SaturationDistanceMaximizer.hpp"
 | 
|---|
| [246e13] | 48 | #include "Fragmentation/Fragmentation.hpp"
 | 
|---|
| [b4f72c] | 49 | #include "Fragmentation/Graph.hpp"
 | 
|---|
| [07a47e] | 50 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
 | 
|---|
| [13c5c1] | 51 | #include "Fragmentation/Interfragmenter.hpp"
 | 
|---|
| [adb51ab] | 52 | #include "Fragmentation/KeySetsContainer.hpp"
 | 
|---|
 | 53 | #include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
 | 
|---|
| [0fad93] | 54 | #include "Graph/AdjacencyList.hpp"
 | 
|---|
| [79d0b9] | 55 | #include "Graph/BondGraph.hpp"
 | 
|---|
| [fe0cb8] | 56 | #include "Graph/CyclicStructureAnalysis.hpp"
 | 
|---|
| [49c059] | 57 | #include "Graph/DepthFirstSearchAnalysis.hpp"
 | 
|---|
| [9511c7] | 58 | #include "Helpers/defs.hpp"
 | 
|---|
| [97ebf8] | 59 | #include "molecule.hpp"
 | 
|---|
 | 60 | #include "World.hpp"
 | 
|---|
 | 61 | 
 | 
|---|
| [c7c615] | 62 | #include <boost/shared_ptr.hpp>
 | 
|---|
| [3aa8a5] | 63 | #include <boost/filesystem.hpp>
 | 
|---|
| [c7c615] | 64 | #include <algorithm>
 | 
|---|
| [97ebf8] | 65 | #include <iostream>
 | 
|---|
| [2a0eb0] | 66 | #include <map>
 | 
|---|
| [97ebf8] | 67 | #include <string>
 | 
|---|
| [2a0eb0] | 68 | #include <vector>
 | 
|---|
| [97ebf8] | 69 | 
 | 
|---|
| [1fd675] | 70 | #include "Actions/FragmentationAction/FragmentationAction.hpp"
 | 
|---|
| [70d9b9] | 71 | 
 | 
|---|
| [ce7fdc] | 72 | using namespace MoleCuilder;
 | 
|---|
 | 73 | 
 | 
|---|
| [1fd675] | 74 | // and construct the stuff
 | 
|---|
 | 75 | #include "FragmentationAction.def"
 | 
|---|
 | 76 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 77 | /** =========== define the function ====================== */
 | 
|---|
| [b5b01e] | 78 | ActionState::ptr FragmentationFragmentationAction::performCall() {
 | 
|---|
| [e4b5de] | 79 |   clock_t start,end;
 | 
|---|
| [2a0eb0] | 80 |   int ExitFlag = -1;
 | 
|---|
 | 81 |   World &world = World::getInstance();
 | 
|---|
| [e4b5de] | 82 | 
 | 
|---|
| [2a0eb0] | 83 |   // inform about used parameters
 | 
|---|
| [13c5c1] | 84 |   LOG(0, "STATUS: Fragmenting molecular system with current connection matrix up to "
 | 
|---|
| [bae7bc] | 85 |       << params.order.get() << " order. ");
 | 
|---|
 | 86 |   if (params.types.get().size() != 0)
 | 
|---|
 | 87 |     LOG(0, "STATUS: Fragment files begin with "
 | 
|---|
 | 88 |         << params.prefix.get() << " and are stored as: "
 | 
|---|
 | 89 |         << params.types.get() << "." << std::endl);
 | 
|---|
| [99b0dc] | 90 | 
 | 
|---|
| [2a0eb0] | 91 |   // check for selected atoms
 | 
|---|
 | 92 |   if (world.beginAtomSelection() == world.endAtomSelection()) {
 | 
|---|
| [26b4d62] | 93 |     STATUS("There are no atoms selected for fragmentation.");
 | 
|---|
| [2a0eb0] | 94 |     return Action::failure;
 | 
|---|
 | 95 |   }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 |   // go through all atoms, note down their molecules and group them
 | 
|---|
| [270bdf] | 98 |   typedef std::multimap<const molecule *, atom *> clusters_t;
 | 
|---|
| [3aa8a5] | 99 |   typedef std::vector<atomId_t> atomids_t;
 | 
|---|
 | 100 |   atomids_t atomids;
 | 
|---|
| [2a0eb0] | 101 |   clusters_t clusters;
 | 
|---|
 | 102 |   for (World::AtomSelectionConstIterator iter = world.beginAtomSelection();
 | 
|---|
 | 103 |       iter != world.endAtomSelection(); ++iter) {
 | 
|---|
 | 104 |     clusters.insert( std::make_pair(iter->second->getMolecule(), iter->second) );
 | 
|---|
| [3aa8a5] | 105 |     atomids.push_back(iter->second->getId());
 | 
|---|
| [2a0eb0] | 106 |   }
 | 
|---|
| [c7c615] | 107 |   {
 | 
|---|
| [270bdf] | 108 |     std::vector<const molecule *> molecules;
 | 
|---|
| [c7c615] | 109 |     molecules.insert( molecules.end(), MapKeyIterator<clusters_t::const_iterator>(clusters.begin()),
 | 
|---|
 | 110 |         MapKeyIterator<clusters_t::const_iterator>(clusters.end()) );
 | 
|---|
 | 111 |     molecules.erase( std::unique(molecules.begin(), molecules.end()), molecules.end() );
 | 
|---|
 | 112 |     LOG(1, "INFO: There are " << molecules.size()  << " molecules to consider.");
 | 
|---|
 | 113 |   }
 | 
|---|
| [2a0eb0] | 114 | 
 | 
|---|
| [9511c7] | 115 |   // parse in Adjacency file
 | 
|---|
| [3aa8a5] | 116 |   boost::shared_ptr<AdjacencyList> FileChecker;
 | 
|---|
 | 117 |   boost::filesystem::path filename(params.prefix.get() + std::string(ADJACENCYFILE));
 | 
|---|
 | 118 |   if (boost::filesystem::exists(filename) && boost::filesystem::is_regular_file(filename)) {
 | 
|---|
 | 119 |     std::ifstream File;
 | 
|---|
 | 120 |     File.open(filename.string().c_str(), ios::out);
 | 
|---|
 | 121 |     FileChecker.reset(new AdjacencyList(File));
 | 
|---|
 | 122 |     File.close();
 | 
|---|
 | 123 |   } else {
 | 
|---|
 | 124 |     LOG(1, "INFO: Could not open default adjacency file " << filename.string() << ".");
 | 
|---|
 | 125 |     FileChecker.reset(new AdjacencyList);
 | 
|---|
 | 126 |   }
 | 
|---|
| [9511c7] | 127 | 
 | 
|---|
| [79d0b9] | 128 |   // make sure bond degree is correct
 | 
|---|
 | 129 |   {
 | 
|---|
 | 130 |     BondGraph *BG = World::getInstance().getBondGraph();
 | 
|---|
 | 131 |     World::AtomComposite Set = World::getInstance().getAllAtoms(AtomsBySelection());
 | 
|---|
| [0763ce] | 132 |     // check whether bond graph is correct
 | 
|---|
 | 133 |     if (!BG->checkBondDegree(Set))
 | 
|---|
 | 134 |       BG->CorrectBondDegree(Set);
 | 
|---|
 | 135 |     else
 | 
|---|
 | 136 |       LOG(1, "INFO: Bond degrees all valid, not correcting.");
 | 
|---|
| [79d0b9] | 137 |   }
 | 
|---|
 | 138 | 
 | 
|---|
| [bfbd4a] | 139 |   // we parse in the keysets from last time if present
 | 
|---|
 | 140 |   Graph StoredGraph;
 | 
|---|
 | 141 |   StoredGraph.ParseKeySetFile(params.prefix.get());
 | 
|---|
 | 142 | 
 | 
|---|
| [2a0eb0] | 143 |   start = clock();
 | 
|---|
 | 144 |   // go through all keys (i.e. all molecules)
 | 
|---|
 | 145 |   clusters_t::const_iterator advanceiter;
 | 
|---|
| [b4f72c] | 146 |   Graph TotalGraph;
 | 
|---|
 | 147 |   int keysetcounter = 0;
 | 
|---|
| [2a0eb0] | 148 |   for (clusters_t::const_iterator iter = clusters.begin();
 | 
|---|
 | 149 |       iter != clusters.end();
 | 
|---|
 | 150 |       iter = advanceiter) {
 | 
|---|
 | 151 |     // get iterator to past last atom in this molecule
 | 
|---|
| [270bdf] | 152 |     const molecule * mol = iter->first;
 | 
|---|
| [2a0eb0] | 153 |     advanceiter = clusters.upper_bound(mol);
 | 
|---|
 | 154 | 
 | 
|---|
 | 155 |     // copy molecule's atoms' ids as parameters to Fragmentation's AtomMask
 | 
|---|
 | 156 |     std::vector<atomId_t> mols_atomids;
 | 
|---|
 | 157 |     std::transform(iter, advanceiter, std::back_inserter(mols_atomids),
 | 
|---|
 | 158 |         boost::bind( &atom::getNr,
 | 
|---|
 | 159 |             boost::bind( &clusters_t::value_type::second, _1 ))
 | 
|---|
 | 160 |     );
 | 
|---|
 | 161 |     LOG(2, "INFO: Fragmenting in molecule " << mol->getName() << " in " << clusters.count(mol) 
 | 
|---|
 | 162 |         << " atoms, out of " << mol->getAtomCount() << ".");
 | 
|---|
| [9291d04] | 163 |     const enum HydrogenTreatment treatment =  params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
 | 
|---|
| [270bdf] | 164 |     molecule * non_const_mol = World::getInstance().getMolecule(MoleculeById(mol->getId()));
 | 
|---|
 | 165 |     Fragmentation Fragmenter(non_const_mol, *FileChecker, treatment);
 | 
|---|
| [2a0eb0] | 166 | 
 | 
|---|
 | 167 |     // perform fragmentation
 | 
|---|
 | 168 |     LOG(0, std::endl << " ========== Fragmentation of molecule " << mol->getName() << " ========================= ");
 | 
|---|
 | 169 |     {
 | 
|---|
| [bfbd4a] | 170 |       Graph StoredLocalGraph(StoredGraph.getLocalGraph(mol));
 | 
|---|
| [fe0cb8] | 171 |       const int tempFlag = Fragmenter.FragmentMolecule(mols_atomids, params.order.get(), params.prefix.get(), StoredLocalGraph);
 | 
|---|
| [2a0eb0] | 172 |       if ((ExitFlag == 2) && (tempFlag != 2))
 | 
|---|
 | 173 |         ExitFlag = tempFlag; // if there is one molecule that needs further fragmentation, it overrides others
 | 
|---|
 | 174 |       if (ExitFlag == -1)
 | 
|---|
 | 175 |         ExitFlag = tempFlag; // if we are the first, we set the standard
 | 
|---|
| [e4b5de] | 176 |     }
 | 
|---|
| [569e42] | 177 |     if (TotalGraph.empty()) {
 | 
|---|
 | 178 |       TotalGraph = Fragmenter.getGraph();
 | 
|---|
 | 179 |       keysetcounter = TotalGraph.size();
 | 
|---|
 | 180 |     } else
 | 
|---|
 | 181 |       TotalGraph.InsertGraph(Fragmenter.getGraph(), keysetcounter);
 | 
|---|
| [ca8bea] | 182 | 
 | 
|---|
| [97ebf8] | 183 |   }
 | 
|---|
| [fe0cb8] | 184 |   // add full cycles if desired
 | 
|---|
 | 185 |   if (params.DoCyclesFull.get()) {
 | 
|---|
 | 186 |     // get the BackEdgeStack from somewhere
 | 
|---|
 | 187 |     DepthFirstSearchAnalysis DFS;
 | 
|---|
 | 188 |     DFS();
 | 
|---|
 | 189 |     std::deque<bond::ptr> BackEdgeStack = DFS.getBackEdgeStack();
 | 
|---|
 | 190 |     // then we analyse the cycles and get them
 | 
|---|
 | 191 |     CyclicStructureAnalysis CycleAnalysis(params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen);
 | 
|---|
 | 192 |     CycleAnalysis(&BackEdgeStack);
 | 
|---|
 | 193 |     CyclicStructureAnalysis::cycles_t cycles = CycleAnalysis.getAllCycles();
 | 
|---|
| [adb51ab] | 194 |     // sort them according to KeySet::operator<()
 | 
|---|
 | 195 |     std::sort(cycles.begin(), cycles.end());
 | 
|---|
 | 196 |     // store all found cycles to file
 | 
|---|
 | 197 |     {
 | 
|---|
 | 198 |       boost::filesystem::path filename(params.prefix.get() + std::string(CYCLEKEYSETFILE));
 | 
|---|
 | 199 |       std::ofstream File;
 | 
|---|
 | 200 |       LOG(1, "INFO: Storing cycle keysets to " << filename.string() << ".");
 | 
|---|
 | 201 |       File.open(filename.string().c_str(), ios::out);
 | 
|---|
 | 202 |       for (CyclicStructureAnalysis::cycles_t::const_iterator iter = cycles.begin();
 | 
|---|
 | 203 |           iter != cycles.end(); ++iter) {
 | 
|---|
 | 204 |         for (CyclicStructureAnalysis::cycle_t::const_iterator cycleiter = (*iter).begin();
 | 
|---|
 | 205 |             cycleiter != (*iter).end(); ++cycleiter) {
 | 
|---|
 | 206 |           File << *cycleiter << "\t";
 | 
|---|
 | 207 |         }
 | 
|---|
 | 208 |         File << "\n";
 | 
|---|
 | 209 |       }
 | 
|---|
 | 210 |       File.close();
 | 
|---|
 | 211 |     }
 | 
|---|
 | 212 |     // ... and to result container
 | 
|---|
 | 213 |     {
 | 
|---|
 | 214 |       KeySetsContainer cyclekeys;
 | 
|---|
 | 215 |       for (CyclicStructureAnalysis::cycles_t::const_iterator iter = cycles.begin();
 | 
|---|
 | 216 |           iter != cycles.end(); ++iter) {
 | 
|---|
 | 217 |         const CyclicStructureAnalysis::cycle_t &cycle = *iter;
 | 
|---|
 | 218 |         const size_t order = cycle.size();
 | 
|---|
 | 219 |         KeySetsContainer::IntVector temp_cycle(cycle.begin(), cycle.end());
 | 
|---|
 | 220 |         cyclekeys.insert(temp_cycle, order);
 | 
|---|
 | 221 |       }
 | 
|---|
 | 222 |       FragmentationResultContainer::getInstance().addCycles(cyclekeys);
 | 
|---|
 | 223 |     }
 | 
|---|
| [fe0cb8] | 224 |     // Create graph and insert into TotalGraph
 | 
|---|
| [adb51ab] | 225 |     LOG(0, "STATUS: Adding " << cycles.size() << " cycles.");
 | 
|---|
| [fe0cb8] | 226 |     {
 | 
|---|
 | 227 |       Graph CycleGraph;
 | 
|---|
 | 228 |       for (CyclicStructureAnalysis::cycles_t::const_iterator iter = cycles.begin();
 | 
|---|
 | 229 |           iter != cycles.end(); ++iter) {
 | 
|---|
 | 230 |         const CyclicStructureAnalysis::cycle_t ¤tcycle = *iter;
 | 
|---|
 | 231 |         LOG(2, "INFO: Inserting cycle " << currentcycle << ".");
 | 
|---|
 | 232 | #ifndef NDEBUG
 | 
|---|
 | 233 |         std::pair< Graph::iterator, bool > inserter =
 | 
|---|
 | 234 | #endif
 | 
|---|
 | 235 |         CycleGraph.insert( std::make_pair(currentcycle, NumberValuePair(1,1.)) );
 | 
|---|
 | 236 |         ASSERT( inserter.second,
 | 
|---|
 | 237 |             "FragmentationFragmentationAction::performCall() - keyset "
 | 
|---|
 | 238 |             +toString(currentcycle)+" inserted twice into CycleGraph.");
 | 
|---|
 | 239 |       }
 | 
|---|
 | 240 |       TotalGraph.InsertGraph(CycleGraph, keysetcounter);
 | 
|---|
 | 241 |     }
 | 
|---|
 | 242 |   }
 | 
|---|
 | 243 | 
 | 
|---|
| [569e42] | 244 |   LOG(0, "STATUS: There are " << TotalGraph.size() << " fragments.");
 | 
|---|
| [3aa8a5] | 245 | 
 | 
|---|
| [321470] | 246 |   {
 | 
|---|
 | 247 |     // remove OrderAtSite file
 | 
|---|
 | 248 |     std::string line;
 | 
|---|
 | 249 |     std::ofstream file;
 | 
|---|
 | 250 |     line = params.prefix.get() + ORDERATSITEFILE;
 | 
|---|
 | 251 |     file.open(line.c_str(), std::ofstream::out | std::ofstream::trunc);
 | 
|---|
 | 252 |     file << "";
 | 
|---|
 | 253 |     file.close();
 | 
|---|
 | 254 |   }
 | 
|---|
 | 255 | 
 | 
|---|
| [13c5c1] | 256 |   // now add interfragments
 | 
|---|
 | 257 |   if (params.InterOrder.get() != 0) {
 | 
|---|
 | 258 |     LOG(0, "STATUS: Putting fragments together up to order "
 | 
|---|
 | 259 |         << params.InterOrder.get() << " and distance of "
 | 
|---|
 | 260 |         << params.distance.get() << ".");
 | 
|---|
 | 261 |     Interfragmenter fragmenter(TotalGraph);
 | 
|---|
 | 262 |     const enum HydrogenTreatment treatment =  params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
 | 
|---|
 | 263 |     fragmenter(params.InterOrder.get(), params.distance.get(), treatment);
 | 
|---|
 | 264 |     LOG(0, "STATUS: There are now " << TotalGraph.size() << " fragments after interfragmenting.");
 | 
|---|
 | 265 |   }
 | 
|---|
 | 266 | 
 | 
|---|
| [bfbd4a] | 267 |   // store keysets to file
 | 
|---|
 | 268 |   {
 | 
|---|
 | 269 |     TotalGraph.StoreKeySetFile(params.prefix.get());
 | 
|---|
 | 270 |   }
 | 
|---|
 | 271 | 
 | 
|---|
| [98a293b] | 272 |   // create global saturation positions map
 | 
|---|
 | 273 |   SaturatedFragment::GlobalSaturationPositions_t globalsaturationpositions;
 | 
|---|
| [5d5550] | 274 |   {
 | 
|---|
 | 275 |     // go through each atom
 | 
|---|
 | 276 |     for (World::AtomSelectionConstIterator iter = world.beginAtomSelection();
 | 
|---|
 | 277 |         iter != world.endAtomSelection(); ++iter) {
 | 
|---|
 | 278 |       const atom * const _atom = iter->second;
 | 
|---|
 | 279 | 
 | 
|---|
 | 280 |       // skip hydrogens if treated special
 | 
|---|
 | 281 |       const enum HydrogenTreatment treatment =  params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
 | 
|---|
 | 282 |       if ((treatment == ExcludeHydrogen) && (_atom->getType()->getAtomicNumber() == 1)) {
 | 
|---|
 | 283 |         LOG(4, "DEBUG: Skipping hydrogen atom " << *_atom);
 | 
|---|
 | 284 |         continue;
 | 
|---|
 | 285 |       }
 | 
|---|
 | 286 | 
 | 
|---|
 | 287 |       // get the valence
 | 
|---|
 | 288 |       unsigned int NumberOfPoints = _atom->getElement().getNoValenceOrbitals();
 | 
|---|
 | 289 |       LOG(3, "DEBUG: There are " << NumberOfPoints
 | 
|---|
 | 290 |           << " places to fill in in total for this atom " << *_atom << ".");
 | 
|---|
 | 291 | 
 | 
|---|
 | 292 |       // check whether there are any bonds with degree larger than 1
 | 
|---|
 | 293 |       unsigned int SumOfDegrees = 0;
 | 
|---|
 | 294 |       bool PresentHigherBonds = false;
 | 
|---|
 | 295 |       const BondList &bondlist = _atom->getListOfBonds();
 | 
|---|
 | 296 |       for (BondList::const_iterator bonditer = bondlist.begin();
 | 
|---|
 | 297 |           bonditer != bondlist.end(); ++bonditer) {
 | 
|---|
 | 298 |         SumOfDegrees += (*bonditer)->getDegree();
 | 
|---|
 | 299 |         PresentHigherBonds |= (*bonditer)->getDegree() > 1;
 | 
|---|
 | 300 |       }
 | 
|---|
 | 301 | 
 | 
|---|
 | 302 |       // check whether there are alphas to maximize the hydrogens distances
 | 
|---|
 | 303 |       SaturationDistanceMaximizer::position_bins_t position_bins;
 | 
|---|
 | 304 |       {
 | 
|---|
 | 305 |         // gather all bonds and convert to SaturatedBonds
 | 
|---|
 | 306 |         SaturationDistanceMaximizer::PositionContainers_t CutBonds;
 | 
|---|
 | 307 |         for (BondList::const_iterator bonditer = bondlist.begin();
 | 
|---|
 | 308 |             bonditer != bondlist.end(); ++bonditer) {
 | 
|---|
 | 309 |           CutBonds.push_back(
 | 
|---|
 | 310 |               SaturatedBond::ptr(new SaturatedBond(*(bonditer->get()), *_atom) )
 | 
|---|
 | 311 |             );
 | 
|---|
 | 312 |         }
 | 
|---|
 | 313 |         SaturationDistanceMaximizer maximizer(CutBonds);
 | 
|---|
 | 314 |         if (PresentHigherBonds) {
 | 
|---|
 | 315 |           // then find best alphas
 | 
|---|
 | 316 |           maximizer();
 | 
|---|
 | 317 |         } else {
 | 
|---|
 | 318 |           // if no higher order bonds, we simply gather the scaled positions
 | 
|---|
 | 319 |         }
 | 
|---|
 | 320 |         position_bins = maximizer.getAllPositionBins();
 | 
|---|
 | 321 |         LOG(4, "DEBUG: Positions for atom " << *_atom << " are " << position_bins);
 | 
|---|
 | 322 |       }
 | 
|---|
 | 323 | 
 | 
|---|
 | 324 |       // convert into the desired entry in the map
 | 
|---|
 | 325 |       SaturatedFragment::SaturationsPositionsPerNeighbor_t positions_per_neighbor;
 | 
|---|
 | 326 |       {
 | 
|---|
 | 327 |         BondList::const_iterator bonditer = bondlist.begin();
 | 
|---|
 | 328 |         SaturationDistanceMaximizer::position_bins_t::const_iterator biniter =
 | 
|---|
 | 329 |             position_bins.begin();
 | 
|---|
 | 330 | 
 | 
|---|
 | 331 |         for (;bonditer != bondlist.end(); ++bonditer, ++biniter) {
 | 
|---|
 | 332 |           const atom * const OtherAtom = (*bonditer)->GetOtherAtom(_atom);
 | 
|---|
 | 333 |           std::pair<
 | 
|---|
 | 334 |               SaturatedFragment::SaturationsPositionsPerNeighbor_t::iterator,
 | 
|---|
 | 335 |               bool
 | 
|---|
 | 336 |               > inserter;
 | 
|---|
 | 337 |           // check whether we treat hydrogen special
 | 
|---|
 | 338 |           if ((treatment == ExcludeHydrogen) && (OtherAtom->getType()->getAtomicNumber() == 1)) {
 | 
|---|
 | 339 |             // if hydrogen, forget rescaled position and use original one
 | 
|---|
 | 340 |             inserter =
 | 
|---|
 | 341 |                 positions_per_neighbor.insert(
 | 
|---|
 | 342 |                     std::make_pair(
 | 
|---|
 | 343 |                         OtherAtom->getId(),
 | 
|---|
 | 344 |                         SaturatedFragment::SaturationsPositions_t(
 | 
|---|
 | 345 |                             1, OtherAtom->getPosition() - _atom->getPosition())
 | 
|---|
 | 346 |                     )
 | 
|---|
 | 347 |                 );
 | 
|---|
 | 348 |           } else {
 | 
|---|
 | 349 |             inserter =
 | 
|---|
 | 350 |                 positions_per_neighbor.insert(
 | 
|---|
 | 351 |                     std::make_pair(
 | 
|---|
 | 352 |                         OtherAtom->getId(),
 | 
|---|
 | 353 |                         SaturatedFragment::SaturationsPositions_t(
 | 
|---|
 | 354 |                             biniter->begin(),
 | 
|---|
 | 355 |                             biniter->end())
 | 
|---|
 | 356 |                     )
 | 
|---|
 | 357 |                 );
 | 
|---|
 | 358 |           }
 | 
|---|
 | 359 |           // if already pressent, add to this present list
 | 
|---|
 | 360 |           ASSERT (inserter.second,
 | 
|---|
 | 361 |               "FragmentationAction::performCall() - other atom "
 | 
|---|
 | 362 |               +toString(*OtherAtom)+" already present?");
 | 
|---|
 | 363 |         }
 | 
|---|
 | 364 |         // bonditer follows nicely
 | 
|---|
 | 365 |         ASSERT( biniter == position_bins.end(),
 | 
|---|
 | 366 |             "FragmentationAction::performCall() - biniter is out of step, it still points at bond "
 | 
|---|
 | 367 |             +toString(*biniter)+".");
 | 
|---|
 | 368 |       }
 | 
|---|
 | 369 |       // and insert
 | 
|---|
 | 370 |       globalsaturationpositions.insert(
 | 
|---|
 | 371 |           std::make_pair( _atom->getId(),
 | 
|---|
 | 372 |               positions_per_neighbor
 | 
|---|
 | 373 |           ));
 | 
|---|
 | 374 |     }
 | 
|---|
 | 375 |   }
 | 
|---|
| [98a293b] | 376 | 
 | 
|---|
| [3aa8a5] | 377 |   {
 | 
|---|
| [9291d04] | 378 |     const enum HydrogenSaturation saturation =  params.DoSaturation.get() ? DoSaturate : DontSaturate;
 | 
|---|
| [276ac6] | 379 |     const enum HydrogenTreatment treatment =  params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
 | 
|---|
| [ac9ca4] | 380 |     if (params.types.get().size() != 0) {
 | 
|---|
 | 381 |       // store molecule's fragment to file
 | 
|---|
| [98a293b] | 382 |       ExportGraph_ToFiles exporter(TotalGraph, treatment, saturation, globalsaturationpositions);
 | 
|---|
| [ac9ca4] | 383 |       exporter.setPrefix(params.prefix.get());
 | 
|---|
 | 384 |       exporter.setOutputTypes(params.types.get());
 | 
|---|
 | 385 |       exporter();
 | 
|---|
 | 386 |     } else {
 | 
|---|
 | 387 |       // store molecule's fragment in FragmentJobQueue
 | 
|---|
| [98a293b] | 388 |       ExportGraph_ToJobs exporter(TotalGraph, treatment, saturation, globalsaturationpositions);
 | 
|---|
| [ac9ca4] | 389 |       exporter.setLevel(params.level.get());
 | 
|---|
 | 390 |       exporter();
 | 
|---|
 | 391 |     }
 | 
|---|
| [3aa8a5] | 392 |   }
 | 
|---|
 | 393 | 
 | 
|---|
 | 394 |   // store Adjacency to file
 | 
|---|
 | 395 |   {
 | 
|---|
 | 396 |     std::string filename = params.prefix.get() + ADJACENCYFILE;
 | 
|---|
 | 397 |     std::ofstream AdjacencyFile;
 | 
|---|
 | 398 |     AdjacencyFile.open(filename.c_str(), ios::out);
 | 
|---|
 | 399 |     AdjacencyList adjacency(atomids);
 | 
|---|
 | 400 |     adjacency.StoreToFile(AdjacencyFile);
 | 
|---|
 | 401 |     AdjacencyFile.close();
 | 
|---|
 | 402 |   }
 | 
|---|
 | 403 | 
 | 
|---|
| [2a0eb0] | 404 |   World::getInstance().setExitFlag(ExitFlag);
 | 
|---|
 | 405 |   end = clock();
 | 
|---|
 | 406 |   LOG(0, "STATUS: Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s.");
 | 
|---|
 | 407 | 
 | 
|---|
| [70d9b9] | 408 |   return Action::success;
 | 
|---|
| [97ebf8] | 409 | }
 | 
|---|
 | 410 | 
 | 
|---|
| [b5b01e] | 411 | ActionState::ptr FragmentationFragmentationAction::performUndo(ActionState::ptr _state) {
 | 
|---|
| [70d9b9] | 412 |   return Action::success;
 | 
|---|
| [97ebf8] | 413 | }
 | 
|---|
 | 414 | 
 | 
|---|
| [b5b01e] | 415 | ActionState::ptr FragmentationFragmentationAction::performRedo(ActionState::ptr _state){
 | 
|---|
| [70d9b9] | 416 |   return Action::success;
 | 
|---|
| [97ebf8] | 417 | }
 | 
|---|
 | 418 | 
 | 
|---|
 | 419 | bool FragmentationFragmentationAction::canUndo() {
 | 
|---|
| [70d9b9] | 420 |   return true;
 | 
|---|
| [97ebf8] | 421 | }
 | 
|---|
 | 422 | 
 | 
|---|
 | 423 | bool FragmentationFragmentationAction::shouldUndo() {
 | 
|---|
| [70d9b9] | 424 |   return true;
 | 
|---|
| [97ebf8] | 425 | }
 | 
|---|
| [1fd675] | 426 | /** =========== end of function ====================== */
 | 
|---|