| [a3427f] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [16893f] | 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [a3427f] | 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/>.
 | 
|---|
 | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | /*
 | 
|---|
 | 25 |  * AnalyseFragmentationResultsAction.cpp
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  *  Created on: Mar 8, 2013
 | 
|---|
 | 28 |  *      Author: heber
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | // include config.h
 | 
|---|
 | 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 33 | #include <config.h>
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | // include headers that implement a archive in simple text format
 | 
|---|
 | 37 | // and before MemDebug due to placement new
 | 
|---|
 | 38 | #include <boost/archive/text_oarchive.hpp>
 | 
|---|
 | 39 | #include <boost/archive/text_iarchive.hpp>
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 42 | 
 | 
|---|
| [e5ebaf] | 43 | #include <boost/foreach.hpp>
 | 
|---|
| [0588e9] | 44 | #include <boost/lambda/lambda.hpp>
 | 
|---|
| [a3427f] | 45 | #include <boost/mpl/remove.hpp>
 | 
|---|
 | 46 | 
 | 
|---|
| [0588e9] | 47 | #include <algorithm>
 | 
|---|
| [a3427f] | 48 | #include <fstream>
 | 
|---|
 | 49 | #include <iostream>
 | 
|---|
| [e355b31] | 50 | //#include <numeric>
 | 
|---|
| [a3427f] | 51 | #include <string>
 | 
|---|
 | 52 | #include <vector>
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 55 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | #ifdef HAVE_JOBMARKET
 | 
|---|
 | 58 | #include "JobMarket/types.hpp"
 | 
|---|
 | 59 | #else
 | 
|---|
 | 60 | typedef size_t JobId_t;
 | 
|---|
 | 61 | #endif
 | 
|---|
 | 62 | 
 | 
|---|
| [e5ebaf] | 63 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [666e9e] | 64 | #include "Atom/atom.hpp"
 | 
|---|
 | 65 | #include "Element/element.hpp"
 | 
|---|
| [a3427f] | 66 | #include "Fragmentation/Summation/Containers/FragmentationChargeDensity.hpp"
 | 
|---|
 | 67 | #include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
 | 
|---|
 | 68 | #include "Fragmentation/Summation/Containers/FragmentationShortRangeResults.hpp"
 | 
|---|
 | 69 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
 | 
|---|
 | 70 | #include "Fragmentation/Summation/Containers/MPQCData_printKeyNames.hpp"
 | 
|---|
 | 71 | #include "Fragmentation/Homology/HomologyContainer.hpp"
 | 
|---|
 | 72 | #include "Fragmentation/Homology/HomologyGraph.hpp"
 | 
|---|
 | 73 | #include "Fragmentation/KeySetsContainer.hpp"
 | 
|---|
| [5c867e] | 74 | #include "Fragmentation/Summation/SetValues/Eigenvalues.hpp"
 | 
|---|
| [a3427f] | 75 | #include "Fragmentation/Summation/SetValues/Fragment.hpp"
 | 
|---|
| [d200ae] | 76 | #include "Fragmentation/Summation/SetValues/FragmentForces.hpp"
 | 
|---|
| [a3427f] | 77 | #include "Fragmentation/Summation/SetValues/Histogram.hpp"
 | 
|---|
 | 78 | #include "Fragmentation/Summation/SetValues/IndexedVectors.hpp"
 | 
|---|
 | 79 | #include "Fragmentation/Summation/IndexSetContainer.hpp"
 | 
|---|
| [47cee7] | 80 | #include "Fragmentation/Summation/writeIndexedTable.hpp"
 | 
|---|
| [a3427f] | 81 | #include "Fragmentation/Summation/writeTable.hpp"
 | 
|---|
| [18ed8c] | 82 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
 | 83 | #include "Fragmentation/Summation/Containers/FragmentationLongRangeResults.hpp"
 | 
|---|
| [a3427f] | 84 | #include "Fragmentation/Summation/Containers/VMGData.hpp"
 | 
|---|
 | 85 | #include "Fragmentation/Summation/Containers/VMGDataFused.hpp"
 | 
|---|
 | 86 | #include "Fragmentation/Summation/Containers/VMGDataMap.hpp"
 | 
|---|
 | 87 | #include "Fragmentation/Summation/Containers/VMGData_printKeyNames.hpp"
 | 
|---|
 | 88 | #endif
 | 
|---|
| [e5ebaf] | 89 | #include "Helpers/defs.hpp"
 | 
|---|
| [666e9e] | 90 | #include "Potentials/Particles/ParticleRegistry.hpp"
 | 
|---|
| [a3427f] | 91 | #include "World.hpp"
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | #include "Actions/FragmentationAction/AnalyseFragmentationResultsAction.hpp"
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | using namespace MoleCuilder;
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | // and construct the stuff
 | 
|---|
 | 98 | #include "AnalyseFragmentationResultsAction.def"
 | 
|---|
 | 99 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 100 | /** =========== define the function ====================== */
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | void writeToFile(const std::string &filename, const std::string contents)
 | 
|---|
 | 103 | {
 | 
|---|
 | 104 |   std::ofstream tablefile(filename.c_str());
 | 
|---|
 | 105 |   tablefile << contents;
 | 
|---|
 | 106 |   tablefile.close();
 | 
|---|
 | 107 | }
 | 
|---|
 | 108 | 
 | 
|---|
| [0588e9] | 109 | /** Print cycle correction from received results.
 | 
|---|
 | 110 |  *
 | 
|---|
 | 111 |  * @param results summed up results container
 | 
|---|
 | 112 |  */
 | 
|---|
 | 113 | void printReceivedCycleResults(
 | 
|---|
 | 114 |     const FragmentationShortRangeResults &results)
 | 
|---|
 | 115 | {
 | 
|---|
 | 116 |   typedef boost::mpl::remove<
 | 
|---|
 | 117 |         boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type,
 | 
|---|
 | 118 |       MPQCDataFused::energy_eigenhistogram>::type
 | 
|---|
 | 119 |     MPQCDataEnergyVector_noeigenvalues_t;
 | 
|---|
 | 120 |   const std::string energyresult =
 | 
|---|
 | 121 |       writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
 | 
|---|
 | 122 |           results.Result_Energy_fused, results.getMaxLevel());
 | 
|---|
 | 123 |   LOG(2, "DEBUG: Energy table is \n" << energyresult);
 | 
|---|
 | 124 |   std::string filename;
 | 
|---|
 | 125 |   filename += FRAGMENTPREFIX + std::string("_CycleEnergy.dat");
 | 
|---|
 | 126 |   writeToFile(filename, energyresult);
 | 
|---|
 | 127 | }
 | 
|---|
 | 128 | 
 | 
|---|
| [47cee7] | 129 | /** Print (short range) energy, forces, and timings from received results per index set.
 | 
|---|
 | 130 |  *
 | 
|---|
 | 131 |  * @param results summed up results container
 | 
|---|
 | 132 |  */
 | 
|---|
 | 133 | void printReceivedShortResultsPerIndex(
 | 
|---|
 | 134 |     const FragmentationShortRangeResults &results)
 | 
|---|
 | 135 | {
 | 
|---|
 | 136 |   // print tables  per keyset(without eigenvalues, they go extra)
 | 
|---|
 | 137 |   typedef boost::mpl::remove<
 | 
|---|
 | 138 |         boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type,
 | 
|---|
 | 139 |       MPQCDataFused::energy_eigenhistogram>::type
 | 
|---|
 | 140 |     MPQCDataEnergyVector_noeigenvalues_t;
 | 
|---|
 | 141 |   const std::string energyresult =
 | 
|---|
 | 142 |       writeIndexedTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
 | 
|---|
 | 143 |           results.Result_perIndexSet_Energy, results.getMaxLevel());
 | 
|---|
 | 144 |   LOG(2, "DEBUG: Indexed Energy table is \n" << energyresult);
 | 
|---|
 | 145 |   std::string filename;
 | 
|---|
 | 146 |   filename += FRAGMENTPREFIX + std::string("_IndexedEnergy.dat");
 | 
|---|
 | 147 |   writeToFile(filename, energyresult);
 | 
|---|
 | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
| [a3427f] | 150 | /** Print (short range) energy, forces, and timings from received results.
 | 
|---|
 | 151 |  *
 | 
|---|
 | 152 |  * @param results summed up results container
 | 
|---|
 | 153 |  */
 | 
|---|
 | 154 | void printReceivedShortResults(
 | 
|---|
 | 155 |     const FragmentationShortRangeResults &results)
 | 
|---|
 | 156 | {
 | 
|---|
 | 157 |   // print tables (without eigenvalues, they go extra)
 | 
|---|
 | 158 |   {
 | 
|---|
| [5c867e] | 159 |     typedef boost::mpl::remove<
 | 
|---|
 | 160 |           boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type,
 | 
|---|
 | 161 |         MPQCDataFused::energy_eigenhistogram>::type
 | 
|---|
| [a3427f] | 162 |       MPQCDataEnergyVector_noeigenvalues_t;
 | 
|---|
 | 163 |     const std::string energyresult =
 | 
|---|
 | 164 |         writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
 | 
|---|
 | 165 |             results.Result_Energy_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 166 |     LOG(2, "DEBUG: Energy table is \n" << energyresult);
 | 
|---|
| [a3427f] | 167 |     std::string filename;
 | 
|---|
 | 168 |     filename += FRAGMENTPREFIX + std::string("_Energy.dat");
 | 
|---|
 | 169 |     writeToFile(filename, energyresult);
 | 
|---|
 | 170 |   }
 | 
|---|
 | 171 | 
 | 
|---|
| [5c867e] | 172 |   {
 | 
|---|
 | 173 |     typedef boost::mpl::list<
 | 
|---|
 | 174 |         MPQCDataFused::energy_eigenvalues
 | 
|---|
 | 175 |     > MPQCDataEigenvalues_t;
 | 
|---|
 | 176 |     const std::string eigenvalueresult =
 | 
|---|
 | 177 |         writeTable<MPQCDataEnergyMap_t, MPQCDataEigenvalues_t >()(
 | 
|---|
 | 178 |             results.Result_Energy_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 179 |     LOG(2, "DEBUG: Eigenvalue table is \n" << eigenvalueresult);
 | 
|---|
| [5c867e] | 180 |     std::string filename;
 | 
|---|
 | 181 |     filename += FRAGMENTPREFIX + std::string("_Eigenvalues.dat");
 | 
|---|
 | 182 |     writeToFile(filename, eigenvalueresult);
 | 
|---|
 | 183 |   }
 | 
|---|
 | 184 | 
 | 
|---|
 | 185 |   {
 | 
|---|
 | 186 |     typedef boost::mpl::list<
 | 
|---|
 | 187 |         MPQCDataFused::energy_eigenhistogram
 | 
|---|
 | 188 |     > MPQCDataEigenhistogram_t;
 | 
|---|
 | 189 |     const std::string eigenhistogramresult =
 | 
|---|
 | 190 |         writeTable<MPQCDataEnergyMap_t, MPQCDataEigenhistogram_t >()(
 | 
|---|
 | 191 |             results.Result_Energy_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 192 |     LOG(2, "DEBUG: Eigenhistogram table is \n" << eigenhistogramresult);
 | 
|---|
| [5c867e] | 193 |     std::string filename;
 | 
|---|
 | 194 |     filename += FRAGMENTPREFIX + std::string("_Eigenhistogram.dat");
 | 
|---|
 | 195 |     writeToFile(filename, eigenhistogramresult);
 | 
|---|
 | 196 |   }
 | 
|---|
 | 197 | 
 | 
|---|
| [a3427f] | 198 |   {
 | 
|---|
 | 199 |     typedef boost::mpl::list<
 | 
|---|
 | 200 |         MPQCDataFused::energy_eigenvalues
 | 
|---|
 | 201 |     > MPQCDataEigenvalues_t;
 | 
|---|
 | 202 |     const std::string eigenvalueresult =
 | 
|---|
 | 203 |         writeTable<MPQCDataEnergyMap_t, MPQCDataEigenvalues_t >()(
 | 
|---|
 | 204 |             results.Result_Energy_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 205 |     LOG(2, "DEBUG: Eigenvalue table is \n" << eigenvalueresult);
 | 
|---|
| [a3427f] | 206 |     std::string filename;
 | 
|---|
 | 207 |     filename += FRAGMENTPREFIX + std::string("_Eigenvalues.dat");
 | 
|---|
 | 208 |     writeToFile(filename, eigenvalueresult);
 | 
|---|
 | 209 |   }
 | 
|---|
 | 210 | 
 | 
|---|
 | 211 |   {
 | 
|---|
 | 212 |     const std::string forceresult =
 | 
|---|
 | 213 |         writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
 | 
|---|
 | 214 |             results.Result_Force_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 215 |     LOG(2, "DEBUG: Force table is \n" << forceresult);
 | 
|---|
| [a3427f] | 216 |     std::string filename;
 | 
|---|
 | 217 |     filename += FRAGMENTPREFIX + std::string("_Forces.dat");
 | 
|---|
 | 218 |     writeToFile(filename, forceresult);
 | 
|---|
 | 219 |   }
 | 
|---|
 | 220 |   // we don't want to print grid to a table
 | 
|---|
 | 221 |   {
 | 
|---|
 | 222 |     // print times (without flops for now)
 | 
|---|
 | 223 |     typedef boost::mpl::remove<
 | 
|---|
 | 224 |         boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_total_flops>::type,
 | 
|---|
 | 225 |         MPQCDataFused::times_gather_flops>::type
 | 
|---|
 | 226 |         MPQCDataTimeVector_noflops_t;
 | 
|---|
 | 227 |     const std::string timesresult =
 | 
|---|
 | 228 |         writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
 | 
|---|
 | 229 |             results.Result_Time_fused, results.getMaxLevel());
 | 
|---|
| [1b5a40] | 230 |     LOG(2, "DEBUG: Times table is \n" << timesresult);
 | 
|---|
| [a3427f] | 231 |     std::string filename;
 | 
|---|
 | 232 |     filename += FRAGMENTPREFIX + std::string("_Times.dat");
 | 
|---|
 | 233 |     writeToFile(filename, timesresult);
 | 
|---|
 | 234 |   }
 | 
|---|
 | 235 | }
 | 
|---|
 | 236 | 
 | 
|---|
 | 237 | 
 | 
|---|
| [18ed8c] | 238 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 239 | /** Print long range energy from received results.
 | 
|---|
 | 240 |  *
 | 
|---|
 | 241 |  * @param results summed up results container
 | 
|---|
 | 242 |  */
 | 
|---|
 | 243 | void printReceivedFullResults(
 | 
|---|
 | 244 |     const FragmentationLongRangeResults &results)
 | 
|---|
 | 245 | {
 | 
|---|
| [83a425] | 246 |   // print tables per keyset(without grids, they go extra)
 | 
|---|
| [a3427f] | 247 | 
 | 
|---|
 | 248 |   {
 | 
|---|
 | 249 |     const std::string gridresult =
 | 
|---|
 | 250 |         writeTable<VMGDataMap_t, VMGDataVector_t >()(
 | 
|---|
| [d29b31] | 251 |             results.Result_LongRange_fused, results.getMaxLevel(), 1);
 | 
|---|
| [1b5a40] | 252 |     LOG(2, "DEBUG: VMG table is \n" << gridresult);
 | 
|---|
| [a3427f] | 253 |     std::string filename;
 | 
|---|
 | 254 |     filename += FRAGMENTPREFIX + std::string("_VMGEnergy.dat");
 | 
|---|
 | 255 |     writeToFile(filename, gridresult);
 | 
|---|
 | 256 |   }
 | 
|---|
 | 257 | 
 | 
|---|
| [94db13] | 258 |   if (results.hasLongRangeForces()) {
 | 
|---|
 | 259 |     const std::string forceresult =
 | 
|---|
 | 260 |         writeTable<VMGDataForceMap_t, VMGDataForceVector_t>()(
 | 
|---|
 | 261 |             results.Result_ForceLongRange_fused, results.getMaxLevel());
 | 
|---|
 | 262 |     LOG(2, "DEBUG: Force table is \n" << forceresult);
 | 
|---|
 | 263 |     std::string filename;
 | 
|---|
 | 264 |     filename += FRAGMENTPREFIX + std::string("_VMGForces.dat");
 | 
|---|
 | 265 |     writeToFile(filename, forceresult);
 | 
|---|
 | 266 |   }
 | 
|---|
 | 267 | 
 | 
|---|
| [a3427f] | 268 |   {
 | 
|---|
 | 269 |     const std::string gridresult =
 | 
|---|
 | 270 |         writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()(
 | 
|---|
| [d29b31] | 271 |             results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 1);
 | 
|---|
| [1b5a40] | 272 |     LOG(2, "DEBUG: LongRange table is \n" << gridresult);
 | 
|---|
| [a3427f] | 273 |     std::string filename;
 | 
|---|
 | 274 |     filename += FRAGMENTPREFIX + std::string("_LongRangeEnergy.dat");
 | 
|---|
 | 275 |     writeToFile(filename, gridresult);
 | 
|---|
 | 276 |   }
 | 
|---|
| [ff347f] | 277 | 
 | 
|---|
 | 278 |   if (results.hasLongRangeForces()) {
 | 
|---|
 | 279 |     const std::string forceresult =
 | 
|---|
 | 280 |         writeTable<VMGDataLongRangeForceMap_t, VMGDataLongRangeForceVector_t >()(
 | 
|---|
 | 281 |             results.Result_ForcesLongRangeIntegrated_fused, results.getMaxLevel(), 1);
 | 
|---|
 | 282 |     LOG(2, "DEBUG: ForcesLongRange table is \n" << forceresult);
 | 
|---|
 | 283 |     std::string filename;
 | 
|---|
 | 284 |     filename += FRAGMENTPREFIX + std::string("_LongRangeForces.dat");
 | 
|---|
 | 285 |     writeToFile(filename, forceresult);
 | 
|---|
 | 286 |   }
 | 
|---|
| [a3427f] | 287 | }
 | 
|---|
| [18ed8c] | 288 | #endif
 | 
|---|
| [a3427f] | 289 | 
 | 
|---|
| [ce70d25] | 290 | bool appendToHomologies(
 | 
|---|
| [98dbee] | 291 |     const FragmentationShortRangeResults &shortrangeresults,
 | 
|---|
| [18ed8c] | 292 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [bf1d1b] | 293 |     const FragmentationLongRangeResults &longrangeresults,
 | 
|---|
| [18ed8c] | 294 | #endif
 | 
|---|
| [bf1d1b] | 295 |     const bool storeGrids
 | 
|---|
| [98dbee] | 296 |     )
 | 
|---|
 | 297 | {
 | 
|---|
 | 298 |   /// read homology container (if present)
 | 
|---|
 | 299 |   HomologyContainer &homology_container = World::getInstance().getHomologies();
 | 
|---|
| [a3427f] | 300 | 
 | 
|---|
 | 301 |   /// append all fragments to a HomologyContainer
 | 
|---|
 | 302 |   HomologyContainer::container_t values;
 | 
|---|
 | 303 | 
 | 
|---|
 | 304 |   // convert KeySetContainer to IndexSetContainer
 | 
|---|
 | 305 |   IndexSetContainer::ptr ForceContainer(new IndexSetContainer(shortrangeresults.getForceKeySet()));
 | 
|---|
 | 306 |   const IndexSetContainer::Container_t &Indices = shortrangeresults.getContainer();
 | 
|---|
 | 307 |   const IndexSetContainer::Container_t &ForceIndices = ForceContainer->getContainer();
 | 
|---|
| [647148] | 308 |   ASSERT( Indices.size() == ForceIndices.size(),
 | 
|---|
 | 309 |       "appendToHomologies() - Indices ("+toString(Indices.size())
 | 
|---|
 | 310 |       +") and ForceIndices ("+toString(ForceIndices.size())+") sizes differ.");
 | 
|---|
| [a3427f] | 311 |   IndexSetContainer::Container_t::const_iterator iter = Indices.begin();
 | 
|---|
 | 312 |   IndexSetContainer::Container_t::const_iterator forceiter = ForceIndices.begin();
 | 
|---|
| [e5ebaf] | 313 | 
 | 
|---|
| [a3427f] | 314 |   /// go through all fragments
 | 
|---|
 | 315 |   for (;iter != Indices.end(); ++iter, ++forceiter) // go through each IndexSet
 | 
|---|
 | 316 |   {
 | 
|---|
 | 317 |     /// create new graph entry in HomologyContainer which is (key,value) type
 | 
|---|
 | 318 |     LOG(1, "INFO: Creating new graph with " << **forceiter << ".");
 | 
|---|
 | 319 |     HomologyGraph graph(**forceiter);
 | 
|---|
 | 320 |     const IndexSet::ptr &index = *iter;
 | 
|---|
| [ce70d25] | 321 |     if (!(**forceiter).contains(**iter)) {
 | 
|---|
 | 322 |       // this caught an error with faulty KeySetsContainer::insert().
 | 
|---|
 | 323 |       // indexset and forceindexset need to be in same order and differ
 | 
|---|
 | 324 |       // only in forceindexset contains extra indices for saturation hydrogens
 | 
|---|
 | 325 |       ELOG(1, "appendToHomologies() - force index set " << (**forceiter)
 | 
|---|
 | 326 |           << " does not contain index set " << (**iter) << ".");
 | 
|---|
 | 327 |       return false;
 | 
|---|
 | 328 |     }
 | 
|---|
| [a3427f] | 329 | 
 | 
|---|
| [bf1d1b] | 330 |     /// we fill the value structure
 | 
|---|
 | 331 |     HomologyContainer::value_t value;
 | 
|---|
 | 332 |     value.containsGrids = storeGrids;
 | 
|---|
 | 333 |     // obtain fragment
 | 
|---|
| [a3427f] | 334 |     std::map<IndexSet::ptr, std::pair< MPQCDataFragmentMap_t, MPQCDataFragmentMap_t> >::const_iterator fragmentiter
 | 
|---|
| [d76d65] | 335 |         = shortrangeresults.Result_perIndexSet_Fragment.find(index);
 | 
|---|
| [ce70d25] | 336 |     if (fragmentiter == shortrangeresults.Result_perIndexSet_Fragment.end()) {
 | 
|---|
 | 337 |       ELOG(1, "appendToHomologyFile() - cannot find index " << (*index)
 | 
|---|
 | 338 |           << " in FragmentResults.");
 | 
|---|
 | 339 |       return false;
 | 
|---|
 | 340 |     }
 | 
|---|
| [bf1d1b] | 341 |     value.fragment = boost::fusion::at_key<MPQCDataFused::fragment>(fragmentiter->second.first);
 | 
|---|
| [27e6a7] | 342 |     LOG(1, "DEBUG: Created graph " << graph << " to fragment " << value.fragment << ".");
 | 
|---|
| [a3427f] | 343 | 
 | 
|---|
| [bf1d1b] | 344 |     // obtain energy
 | 
|---|
| [a3427f] | 345 |     std::map<IndexSet::ptr, std::pair< MPQCDataEnergyMap_t, MPQCDataEnergyMap_t> >::const_iterator energyiter
 | 
|---|
 | 346 |         = shortrangeresults.Result_perIndexSet_Energy.find(index);
 | 
|---|
| [ce70d25] | 347 |     if (energyiter == shortrangeresults.Result_perIndexSet_Energy.end()) {
 | 
|---|
 | 348 |       ELOG(1, "appendToHomologyFile() - cannot find index " << (*index)
 | 
|---|
 | 349 |           << " in FragmentResults.");
 | 
|---|
 | 350 |       return false;
 | 
|---|
 | 351 |     }
 | 
|---|
| [bf1d1b] | 352 |     value.energy = boost::fusion::at_key<MPQCDataFused::energy_total>(energyiter->second.second); // contributions
 | 
|---|
 | 353 | 
 | 
|---|
 | 354 |     // only store sampled grids if desired
 | 
|---|
 | 355 |     if (storeGrids) {
 | 
|---|
| [18ed8c] | 356 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [bf1d1b] | 357 |       // obtain charge distribution
 | 
|---|
 | 358 |       std::map<IndexSet::ptr, std::pair< MPQCDataGridMap_t, MPQCDataGridMap_t> >::const_iterator chargeiter
 | 
|---|
 | 359 |           = longrangeresults.Result_perIndexSet_Grid.find(index);
 | 
|---|
| [ce70d25] | 360 |       if (chargeiter == longrangeresults.Result_perIndexSet_Grid.end()) {
 | 
|---|
 | 361 |         ELOG(1, "appendToHomologyFile() - cannot find index " << (*index)
 | 
|---|
 | 362 |             << " in FragmentResults.");
 | 
|---|
 | 363 |         return false;
 | 
|---|
 | 364 |       }
 | 
|---|
| [bf1d1b] | 365 |       value.charge_distribution = boost::fusion::at_key<MPQCDataFused::sampled_grid>(chargeiter->second.second); // contributions
 | 
|---|
 | 366 | 
 | 
|---|
 | 367 |       // obtain potential distribution
 | 
|---|
| [83a425] | 368 |       std::map<IndexSet::ptr, std::pair< VMGDataGridMap_t, VMGDataGridMap_t> >::const_iterator potentialiter
 | 
|---|
 | 369 |           = longrangeresults.Result_perIndexSet_LongRange_Grid.find(index);
 | 
|---|
| [ce70d25] | 370 |       if (potentialiter == longrangeresults.Result_perIndexSet_LongRange_Grid.end()) {
 | 
|---|
 | 371 |         ELOG(1, "appendToHomologyFile() - cannot find index " << (*index)
 | 
|---|
 | 372 |             << " in FragmentResults.");
 | 
|---|
 | 373 |         return false;
 | 
|---|
 | 374 |       }
 | 
|---|
| [e355b31] | 375 |       // add e+n potentials
 | 
|---|
| [83a425] | 376 |       value.potential_distribution =
 | 
|---|
 | 377 |           boost::fusion::at_key<VMGDataFused::both_sampled_potential>(potentialiter->second.second); // contributions
 | 
|---|
| [e355b31] | 378 | //      // and re-average to zero (integral is times volume_element which we don't need here)
 | 
|---|
 | 379 | //      const double sum =
 | 
|---|
 | 380 | //          std::accumulate(
 | 
|---|
 | 381 | //              value.potential_distribution.sampled_grid.begin(),
 | 
|---|
 | 382 | //              value.potential_distribution.sampled_grid.end(),
 | 
|---|
 | 383 | //              0.);
 | 
|---|
 | 384 | //      const double offset = sum/(double)value.potential_distribution.sampled_grid.size();
 | 
|---|
 | 385 | //      for (SamplingGrid::sampledvalues_t::iterator iter = value.potential_distribution.sampled_grid.begin();
 | 
|---|
 | 386 | //          iter != value.potential_distribution.sampled_grid.end();
 | 
|---|
 | 387 | //          ++iter)
 | 
|---|
 | 388 | //        *iter -= offset;
 | 
|---|
| [18ed8c] | 389 | #else
 | 
|---|
| [ce70d25] | 390 |       ELOG(2, "Long-range information in homology desired but long-range analysis capability not compiled in.");
 | 
|---|
| [18ed8c] | 391 | #endif
 | 
|---|
| [bf1d1b] | 392 |     }
 | 
|---|
| [a3427f] | 393 |     values.insert( std::make_pair( graph, value) );
 | 
|---|
 | 394 |   }
 | 
|---|
 | 395 |   homology_container.insert(values);
 | 
|---|
 | 396 | 
 | 
|---|
| [1b5a40] | 397 |   if (DoLog(2)) {
 | 
|---|
 | 398 |     LOG(2, "DEBUG: Listing all present atomic ids ...");
 | 
|---|
 | 399 |     std::stringstream output;
 | 
|---|
 | 400 |     for (World::AtomIterator iter = World::getInstance().getAtomIter();
 | 
|---|
 | 401 |         iter != World::getInstance().atomEnd(); ++iter)
 | 
|---|
 | 402 |       output << (*iter)->getId() << " ";
 | 
|---|
 | 403 |     LOG(2, "DEBUG: { " << output.str() << "} .");
 | 
|---|
 | 404 |   }
 | 
|---|
| [a3427f] | 405 | 
 | 
|---|
 | 406 |   // for debugging: print container
 | 
|---|
| [1b5a40] | 407 |   if (DoLog(2)) {
 | 
|---|
 | 408 |     LOG(2, "DEBUG: Listing all present homologies ...");
 | 
|---|
 | 409 |     for (HomologyContainer::container_t::const_iterator iter =
 | 
|---|
 | 410 |         homology_container.begin(); iter != homology_container.end(); ++iter) {
 | 
|---|
| [d76d65] | 411 |       std::stringstream output;
 | 
|---|
 | 412 |       output << "DEBUG: graph " << iter->first
 | 
|---|
| [bf1d1b] | 413 |           << " has Fragment " << iter->second.fragment
 | 
|---|
| [d76d65] | 414 |           << ", associated energy " << iter->second.energy;
 | 
|---|
 | 415 |       if (iter->second.containsGrids)
 | 
|---|
| [18ed8c] | 416 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [d76d65] | 417 |         output  << ", and sampled grid integral " << iter->second.charge_distribution.integral();
 | 
|---|
| [18ed8c] | 418 | #else
 | 
|---|
 | 419 |         output << ", and there are sampled grids but capability not compiled in";
 | 
|---|
 | 420 | #endif
 | 
|---|
| [d76d65] | 421 |       output << ".";
 | 
|---|
 | 422 |       LOG(2, output.str());
 | 
|---|
| [1b5a40] | 423 |     }
 | 
|---|
| [a3427f] | 424 |   }
 | 
|---|
| [ce70d25] | 425 | 
 | 
|---|
 | 426 |   return true;
 | 
|---|
| [98dbee] | 427 | }
 | 
|---|
| [a3427f] | 428 | 
 | 
|---|
| [0588e9] | 429 | // this it taken from
 | 
|---|
 | 430 | // http://stackoverflow.com/questions/2291802/is-there-a-c-iterator-that-can-iterate-over-a-file-line-by-line
 | 
|---|
 | 431 | namespace detail
 | 
|---|
 | 432 | {
 | 
|---|
 | 433 |   /** Extend the string class by a friend function.
 | 
|---|
 | 434 |    *
 | 
|---|
 | 435 |    */
 | 
|---|
 | 436 |   class Line : public std::string
 | 
|---|
 | 437 |   {
 | 
|---|
 | 438 |     friend std::istream & operator>>(std::istream & is, Line & line)
 | 
|---|
 | 439 |     {
 | 
|---|
 | 440 |       return std::getline(is, line);
 | 
|---|
 | 441 |     }
 | 
|---|
 | 442 |   };
 | 
|---|
 | 443 | }
 | 
|---|
 | 444 | 
 | 
|---|
 | 445 | /** Parse the given stream line-by-line, passing each to \a dest.
 | 
|---|
 | 446 |  *
 | 
|---|
 | 447 |  * \param is stream to parse line-wise
 | 
|---|
 | 448 |  * \param dest output iterator
 | 
|---|
 | 449 |  */
 | 
|---|
 | 450 | template<class OutIt>
 | 
|---|
 | 451 | void read_lines(std::istream& is, OutIt dest)
 | 
|---|
 | 452 | {
 | 
|---|
 | 453 |     typedef std::istream_iterator<detail::Line> InIt;
 | 
|---|
 | 454 |     std::copy(InIt(is), InIt(), dest);
 | 
|---|
 | 455 | }
 | 
|---|
 | 456 | 
 | 
|---|
 | 457 | 
 | 
|---|
| [f58e56] | 458 | /** Determines the largest cycle in the container and returns its size.
 | 
|---|
 | 459 |  *
 | 
|---|
 | 460 |  * \param cycles set of cycles
 | 
|---|
 | 461 |  * \return size if largest cycle
 | 
|---|
 | 462 |  */
 | 
|---|
 | 463 | size_t getMaxCycleSize(const KeySetsContainer &cycles)
 | 
|---|
 | 464 | {
 | 
|---|
 | 465 |   // gather cycle sizes
 | 
|---|
 | 466 |   std::vector<size_t> cyclesizes(cycles.KeySets.size());
 | 
|---|
 | 467 |   std::transform(
 | 
|---|
 | 468 |       cycles.KeySets.begin(), cycles.KeySets.end(),
 | 
|---|
 | 469 |       cyclesizes.begin(),
 | 
|---|
 | 470 |       boost::bind(&KeySetsContainer::IntVector::size, boost::lambda::_1)
 | 
|---|
 | 471 |   );
 | 
|---|
 | 472 |   // get maximum
 | 
|---|
 | 473 |   std::vector<size_t>::const_iterator maximum_size =
 | 
|---|
 | 474 |       std::max_element(cyclesizes.begin(), cyclesizes.end());
 | 
|---|
 | 475 |   if (maximum_size != cyclesizes.end())
 | 
|---|
 | 476 |     return *maximum_size;
 | 
|---|
 | 477 |   else
 | 
|---|
 | 478 |     return 0;
 | 
|---|
 | 479 | }
 | 
|---|
 | 480 | 
 | 
|---|
 | 481 | void calculateCycleFullContribution(
 | 
|---|
 | 482 |     const std::map<JobId_t, MPQCData> &shortrangedata,
 | 
|---|
 | 483 |     const KeySetsContainer &keysets,
 | 
|---|
 | 484 |     const KeySetsContainer &forcekeysets,
 | 
|---|
 | 485 |     const KeySetsContainer &cycles,
 | 
|---|
 | 486 |     const FragmentationShortRangeResults &shortrangeresults)
 | 
|---|
 | 487 | {
 | 
|---|
 | 488 |   // copy the shortrangeresults such that private MaxLevel is set in
 | 
|---|
 | 489 |   // FragmentationShortRangeResults
 | 
|---|
 | 490 |   FragmentationShortRangeResults cycleresults(shortrangeresults);
 | 
|---|
 | 491 |   // get largest size
 | 
|---|
 | 492 |   const size_t maximum_size = getMaxCycleSize(cycles);
 | 
|---|
 | 493 | 
 | 
|---|
 | 494 |   /// The idea here is that (Orthogonal)Summation will place a result
 | 
|---|
 | 495 |   /// consisting of level 1,2, and 3 fragment and a level 6 ring nonetheless
 | 
|---|
 | 496 |   /// in level 6. If we want to have this result already at level 3, we
 | 
|---|
 | 497 |   /// have to specifically inhibit all fragments from later levels but the
 | 
|---|
 | 498 |   /// cycles and then pick the result from the last level and placing it at
 | 
|---|
 | 499 |   /// the desired one
 | 
|---|
 | 500 | 
 | 
|---|
 | 501 |   // loop from level 1 to max ring size and gather contributions
 | 
|---|
 | 502 |   for (size_t level = 1; level <= maximum_size; ++level) {
 | 
|---|
 | 503 |     // create ValueMask for this level by stepping through each keyset and checking size
 | 
|---|
 | 504 |     std::vector<bool> localValueMask(shortrangedata.size(), false);
 | 
|---|
 | 505 |     size_t index=0;
 | 
|---|
 | 506 |     // TODO: if only KeySetsContainer was usable as a compliant STL container, might be able to use set_difference or alike.
 | 
|---|
 | 507 |     KeySetsContainer::ArrayOfIntVectors::const_iterator keysetsiter = keysets.KeySets.begin();
 | 
|---|
 | 508 |     KeySetsContainer::ArrayOfIntVectors::const_iterator cyclesiter = cycles.KeySets.begin();
 | 
|---|
 | 509 |     for (; (keysetsiter != keysets.KeySets.end()) && (cyclesiter != cycles.KeySets.end());) {
 | 
|---|
 | 510 |       if (cyclesiter->size() > keysetsiter->size()) {
 | 
|---|
 | 511 |         // add if not greater than level in size
 | 
|---|
 | 512 |         if ((*keysetsiter).size() <= level)
 | 
|---|
 | 513 |           localValueMask[index] = true;
 | 
|---|
 | 514 |         ++keysetsiter;
 | 
|---|
 | 515 |         ++index;
 | 
|---|
 | 516 |       } else if (cyclesiter->size() < keysetsiter->size()) {
 | 
|---|
 | 517 |         ++cyclesiter;
 | 
|---|
 | 518 |       } else { // both sets have same size
 | 
|---|
 | 519 |         if (*cyclesiter > *keysetsiter) {
 | 
|---|
 | 520 |           // add if not greater than level in size
 | 
|---|
 | 521 |           if ((*keysetsiter).size() <= level)
 | 
|---|
 | 522 |             localValueMask[index] = true;
 | 
|---|
 | 523 |           ++keysetsiter;
 | 
|---|
 | 524 |           ++index;
 | 
|---|
 | 525 |         } else if (*cyclesiter < *keysetsiter) {
 | 
|---|
 | 526 |           ++cyclesiter;
 | 
|---|
 | 527 |         } else {
 | 
|---|
 | 528 |           // also always add all cycles
 | 
|---|
 | 529 |           localValueMask[index] = true;
 | 
|---|
 | 530 |           ++cyclesiter;
 | 
|---|
 | 531 |           ++keysetsiter;
 | 
|---|
 | 532 |           ++index;
 | 
|---|
 | 533 |         }
 | 
|---|
 | 534 |       }
 | 
|---|
 | 535 |     }
 | 
|---|
 | 536 |     // activate rest if desired by level
 | 
|---|
 | 537 |     for (; keysetsiter != keysets.KeySets.end(); ++keysetsiter) {
 | 
|---|
 | 538 |       if ((*keysetsiter).size() <= level)
 | 
|---|
 | 539 |         localValueMask[index] = true;
 | 
|---|
 | 540 |       ++index;
 | 
|---|
 | 541 |     }
 | 
|---|
 | 542 |     LOG(2, "DEBUG: ValueMask for cycle correction at level " << level << " is "
 | 
|---|
 | 543 |         << localValueMask << ".");
 | 
|---|
 | 544 |     // create FragmentationShortRangeResults
 | 
|---|
 | 545 |     FragmentationShortRangeResults localresults(shortrangedata, keysets, forcekeysets, localValueMask);
 | 
|---|
 | 546 |     // and perform summation
 | 
|---|
 | 547 |     localresults(shortrangedata);
 | 
|---|
 | 548 |     // finally, extract the corrections from last level
 | 
|---|
 | 549 |     cycleresults.Result_Energy_fused[level-1] =
 | 
|---|
 | 550 |         localresults.Result_Energy_fused.back();
 | 
|---|
 | 551 |     cycleresults.Result_Time_fused[level-1] =
 | 
|---|
 | 552 |         localresults.Result_Time_fused.back();
 | 
|---|
 | 553 |     cycleresults.Result_Force_fused[level-1] =
 | 
|---|
 | 554 |         localresults.Result_Force_fused.back();
 | 
|---|
 | 555 |   }
 | 
|---|
 | 556 |   printReceivedCycleResults(cycleresults);
 | 
|---|
 | 557 | }
 | 
|---|
 | 558 | 
 | 
|---|
| [d93d2c] | 559 | static void AddForces(
 | 
|---|
 | 560 |     const IndexedVectors::indexedvectors_t &_forces,
 | 
|---|
 | 561 |     const bool _IsAngstroem)
 | 
|---|
 | 562 | {
 | 
|---|
 | 563 |   for(IndexedVectors::indexedvectors_t::const_iterator iter = _forces.begin();
 | 
|---|
 | 564 |       iter != _forces.end(); ++iter) {
 | 
|---|
 | 565 |     const IndexedVectors::index_t &index = iter->first;
 | 
|---|
 | 566 |     const IndexedVectors::vector_t &forcevector = iter->second;
 | 
|---|
 | 567 |     ASSERT( forcevector.size() == NDIM,
 | 
|---|
 | 568 |         "printReceivedShortResults() - obtained force vector has incorrect dimension.");
 | 
|---|
 | 569 |     // note that mpqc calculates a gradient, hence force pointing into opposite direction
 | 
|---|
 | 570 |     // we have to mind different units here: MPQC has a_o, while we may have angstroem
 | 
|---|
 | 571 |     Vector ForceVector(-forcevector[0], -forcevector[1], -forcevector[2]);
 | 
|---|
 | 572 |     if (_IsAngstroem)
 | 
|---|
 | 573 |       for (size_t i=0;i<NDIM;++i)
 | 
|---|
 | 574 |         ForceVector[i] *= AtomicLengthToAngstroem;
 | 
|---|
 | 575 |     atom *_atom = World::getInstance().getAtom(AtomById(index));
 | 
|---|
 | 576 |     if(_atom != NULL)
 | 
|---|
 | 577 |       _atom->setAtomicForce(_atom->getAtomicForce() + ForceVector);
 | 
|---|
 | 578 |     else
 | 
|---|
 | 579 |       ELOG(2, "Could not find atom to id " << index << ".");
 | 
|---|
 | 580 |   }
 | 
|---|
 | 581 | }
 | 
|---|
 | 582 | 
 | 
|---|
| [b5b01e] | 583 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performCall() {
 | 
|---|
| [ce70d25] | 584 |   bool status=true;
 | 
|---|
| [a3427f] | 585 | 
 | 
|---|
| [0588e9] | 586 |   /// if file is given, parse from file into ResultsContainer
 | 
|---|
| [a3427f] | 587 |   FragmentationResultContainer& container = FragmentationResultContainer::getInstance();
 | 
|---|
| [55e1bc] | 588 |   if (!params.resultsfile.get().empty()) {
 | 
|---|
 | 589 |     boost::filesystem::path resultsfile = params.resultsfile.get();
 | 
|---|
 | 590 |     if (boost::filesystem::exists(resultsfile)) {
 | 
|---|
 | 591 |       LOG(1, "INFO: Parsing results from " << resultsfile.string() << ".");
 | 
|---|
 | 592 |       std::ifstream returnstream(resultsfile.string().c_str());
 | 
|---|
 | 593 |       if (returnstream.good()) {
 | 
|---|
 | 594 |         boost::archive::text_iarchive ia(returnstream);
 | 
|---|
 | 595 |         ia >> container;
 | 
|---|
 | 596 |       }
 | 
|---|
 | 597 |     } else {
 | 
|---|
 | 598 |       ELOG(1, "Given file" << resultsfile.string() << " does not exist.");
 | 
|---|
| [ce70d25] | 599 |       STATUS("AnalyseFragmentResultsAction failed: missing results file.");
 | 
|---|
 | 600 |       return Action::failure;
 | 
|---|
| [55e1bc] | 601 |     }
 | 
|---|
 | 602 |   }
 | 
|---|
 | 603 | 
 | 
|---|
| [0588e9] | 604 |   /// get data and keysets from ResultsContainer
 | 
|---|
| [a3427f] | 605 |   const std::map<JobId_t, MPQCData> &shortrangedata = container.getShortRangeResults();
 | 
|---|
 | 606 |   const KeySetsContainer &keysets = container.getKeySets();
 | 
|---|
 | 607 |   const KeySetsContainer &forcekeysets = container.getForceKeySets();
 | 
|---|
 | 608 |   const bool DoLongrange = container.areFullRangeResultsPresent();
 | 
|---|
| [e5ebaf] | 609 |   const bool IsAngstroem = true;
 | 
|---|
| [a3427f] | 610 | 
 | 
|---|
| [55e1bc] | 611 |   if (keysets.KeySets.empty()) {
 | 
|---|
| [26b4d62] | 612 |     STATUS("There are no results in the container.");
 | 
|---|
| [55e1bc] | 613 |     return Action::failure;
 | 
|---|
 | 614 |   }
 | 
|---|
 | 615 | 
 | 
|---|
| [0588e9] | 616 |   /// calculate normal contributions with (if present) cycles coming at their
 | 
|---|
 | 617 |   /// respective bond order.
 | 
|---|
| [e0ae58d] | 618 |   std::vector<bool> ValueMask(shortrangedata.size(), true);
 | 
|---|
 | 619 |   FragmentationShortRangeResults shortrangeresults(shortrangedata, keysets, forcekeysets, ValueMask);
 | 
|---|
| [a3427f] | 620 |   shortrangeresults(shortrangedata);
 | 
|---|
 | 621 |   printReceivedShortResults(shortrangeresults);
 | 
|---|
| [47cee7] | 622 |   printReceivedShortResultsPerIndex(shortrangeresults);
 | 
|---|
| [c8d13f5] | 623 |   // add summed results to container
 | 
|---|
 | 624 |   container.addShortRangeSummedResults(shortrangeresults.getSummedShortRangeResults());
 | 
|---|
| [a3427f] | 625 | 
 | 
|---|
| [0588e9] | 626 |   /// now do we need to calculate the cycle contribution
 | 
|---|
 | 627 |   // check whether there are cycles in container or else in file
 | 
|---|
 | 628 |   KeySetsContainer cycles = container.getCycles();
 | 
|---|
 | 629 |   if (cycles.KeySets.empty()) {
 | 
|---|
 | 630 |     // parse from file if cycles is empty
 | 
|---|
 | 631 |     boost::filesystem::path filename(
 | 
|---|
 | 632 |         params.prefix.get() + std::string(CYCLEKEYSETFILE));
 | 
|---|
 | 633 |     if (boost::filesystem::exists(filename)) {
 | 
|---|
 | 634 |       LOG(1, "INFO: Parsing cycles file " << filename.string() << ".");
 | 
|---|
 | 635 |       // parse file line by line
 | 
|---|
 | 636 |       std::ifstream File;
 | 
|---|
 | 637 |       File.open(filename.string().c_str());
 | 
|---|
 | 638 |       typedef std::istream_iterator<detail::Line> InIt;
 | 
|---|
 | 639 |       for (InIt iter = InIt(File); iter != InIt(); ++iter) {
 | 
|---|
 | 640 |         KeySetsContainer::IntVector cycle;
 | 
|---|
 | 641 |         std::stringstream line(*iter);
 | 
|---|
 | 642 |         while (line.good()) {
 | 
|---|
 | 643 |           int id;
 | 
|---|
 | 644 |           line >> id >> ws;
 | 
|---|
 | 645 |           cycle.push_back(id);
 | 
|---|
 | 646 |         }
 | 
|---|
 | 647 |         if (!cycle.empty()) {
 | 
|---|
 | 648 |           LOG(2, "DEBUG: Adding cycle " << cycle << ".");
 | 
|---|
 | 649 |           cycles.insert( cycle, cycle.size());
 | 
|---|
 | 650 |         }
 | 
|---|
 | 651 |       }
 | 
|---|
 | 652 |       File.close();
 | 
|---|
 | 653 |     } else {
 | 
|---|
 | 654 |       LOG(1, "INFO: Cycles file not found at " << filename.string() << ".");
 | 
|---|
 | 655 |     }
 | 
|---|
 | 656 |   }
 | 
|---|
 | 657 | 
 | 
|---|
 | 658 |   // calculate energy if cycles are calculated fully at each level already
 | 
|---|
 | 659 |   if (!cycles.KeySets.empty()) {
 | 
|---|
| [f58e56] | 660 |     calculateCycleFullContribution(
 | 
|---|
 | 661 |         shortrangedata,
 | 
|---|
 | 662 |         keysets,
 | 
|---|
 | 663 |         forcekeysets,
 | 
|---|
 | 664 |         cycles,
 | 
|---|
 | 665 |         shortrangeresults);
 | 
|---|
| [0588e9] | 666 |   }
 | 
|---|
 | 667 | 
 | 
|---|
| [e5ebaf] | 668 |   // adding obtained forces
 | 
|---|
| [a58c16] | 669 |   if ( const_cast<const World &>(World::getInstance()).getAllAtoms().size() != 0) {
 | 
|---|
| [d93d2c] | 670 |     const IndexedVectors::indexedvectors_t shortrange_forces =
 | 
|---|
| [e5ebaf] | 671 |         boost::fusion::at_key<MPQCDataFused::forces>(
 | 
|---|
 | 672 |             shortrangeresults.Result_Force_fused.back()
 | 
|---|
 | 673 |             ).getVectors();
 | 
|---|
| [d93d2c] | 674 |     AddForces(shortrange_forces,IsAngstroem);
 | 
|---|
| [e5ebaf] | 675 |   } else {
 | 
|---|
 | 676 |     LOG(1, "INFO: Full molecule not loaded, hence will not add forces to atoms.");
 | 
|---|
 | 677 |   }
 | 
|---|
 | 678 | 
 | 
|---|
| [18ed8c] | 679 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 680 |   if (DoLongrange) {
 | 
|---|
| [a58c16] | 681 |     if ( const_cast<const World &>(World::getInstance()).getAllAtoms().size() == 0) {
 | 
|---|
| [057c8a] | 682 |       STATUS("Please load the full molecule into std::map<JobId_t, VMGData> longrangeData the world before starting this action.");
 | 
|---|
| [a3427f] | 683 |       return Action::failure;
 | 
|---|
 | 684 |     }
 | 
|---|
 | 685 | 
 | 
|---|
 | 686 |     FragmentationChargeDensity summedChargeDensity(shortrangedata,keysets);
 | 
|---|
 | 687 |     const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
 | 
|---|
 | 688 | 
 | 
|---|
 | 689 |     std::map<JobId_t, VMGData> longrangeData = container.getLongRangeResults();
 | 
|---|
 | 690 |     // remove full solution corresponding to full_sample from map (must be highest ids), has to be treated extra
 | 
|---|
 | 691 |     std::map<JobId_t, VMGData>::iterator iter = longrangeData.end();
 | 
|---|
| [057c8a] | 692 |     std::advance(iter, -full_sample.size());
 | 
|---|
| [a3427f] | 693 |     std::map<JobId_t, VMGData>::iterator remove_iter = iter;
 | 
|---|
 | 694 |     std::vector<VMGData> fullsolutionData;
 | 
|---|
 | 695 |     for (; iter != longrangeData.end(); ++iter)
 | 
|---|
 | 696 |       fullsolutionData.push_back(iter->second);
 | 
|---|
| [057c8a] | 697 |     if (longrangeData.size() > 1) // when there's just a single fragment, it corresponds to full solution
 | 
|---|
 | 698 |       longrangeData.erase(remove_iter, longrangeData.end());
 | 
|---|
| [a3427f] | 699 | 
 | 
|---|
 | 700 |     // Final phase: sum up and print result
 | 
|---|
| [666e9e] | 701 |     IndexedVectors::indices_t implicit_indices;
 | 
|---|
 | 702 |     if (params.UseImplicitCharges.get()) {
 | 
|---|
 | 703 |       // place all in implicit charges that are not selected but contained in ParticleRegistry
 | 
|---|
 | 704 |       const World &world = const_cast<const World &>(World::getInstance());
 | 
|---|
 | 705 |       const ParticleRegistry ®istry = const_cast<const ParticleRegistry &>(ParticleRegistry::getInstance());
 | 
|---|
 | 706 |       const World::ConstAtomComposite &atoms = world.getAllAtoms();
 | 
|---|
 | 707 |       for (World::ConstAtomComposite::const_iterator iter = atoms.begin();
 | 
|---|
 | 708 |           iter != atoms.end(); ++iter) {
 | 
|---|
 | 709 |         const atomId_t atomid = (*iter)->getId();
 | 
|---|
 | 710 |         if (!world.isAtomSelected(atomid)) {
 | 
|---|
 | 711 |           const std::string &symbol = (*iter)->getElement().getSymbol();
 | 
|---|
 | 712 |           if (registry.isPresentByName(symbol))
 | 
|---|
 | 713 |             implicit_indices.push_back(atomid);
 | 
|---|
 | 714 |         }
 | 
|---|
 | 715 |       }
 | 
|---|
 | 716 |       LOG(2, "INFO: We added " << implicit_indices.size() << " indices due to implicit charges.");
 | 
|---|
 | 717 |     }
 | 
|---|
 | 718 | 
 | 
|---|
| [a3427f] | 719 |     FragmentationLongRangeResults longrangeresults(
 | 
|---|
 | 720 |         shortrangedata,longrangeData,keysets, forcekeysets);
 | 
|---|
 | 721 |     longrangeresults(
 | 
|---|
 | 722 |         shortrangedata,
 | 
|---|
 | 723 |         longrangeData,
 | 
|---|
 | 724 |         fullsolutionData,
 | 
|---|
| [666e9e] | 725 |         full_sample,
 | 
|---|
 | 726 |         implicit_indices);
 | 
|---|
| [a3427f] | 727 |     printReceivedFullResults(longrangeresults);
 | 
|---|
 | 728 | 
 | 
|---|
| [d93d2c] | 729 |     // add long-range forces
 | 
|---|
 | 730 |     if ( const_cast<const World &>(World::getInstance()).getAllAtoms().size() != 0) {
 | 
|---|
 | 731 |       const IndexedVectors::indexedvectors_t longrange_forces =
 | 
|---|
 | 732 |           boost::fusion::at_key<VMGDataFused::forces_longrange>(
 | 
|---|
 | 733 |               longrangeresults.Result_ForcesLongRangeIntegrated_fused.back()
 | 
|---|
 | 734 |               ).getVectors();
 | 
|---|
 | 735 |       AddForces(longrange_forces,IsAngstroem);
 | 
|---|
 | 736 |     } else {
 | 
|---|
 | 737 |       LOG(1, "INFO: Full molecule not loaded, hence will not add forces to atoms.");
 | 
|---|
 | 738 |     }
 | 
|---|
 | 739 | 
 | 
|---|
| [a3427f] | 740 |     // append all keysets to homology file
 | 
|---|
| [ce70d25] | 741 |     status = appendToHomologies(shortrangeresults, longrangeresults, params.DoStoreGrids.get());
 | 
|---|
| [d76d65] | 742 |   } else {
 | 
|---|
 | 743 |     // append all keysets to homology file with short-range info only (without grids)
 | 
|---|
 | 744 |     std::map<JobId_t, VMGData> longrangeData;
 | 
|---|
 | 745 |     FragmentationLongRangeResults longrangeresults(
 | 
|---|
| [666e9e] | 746 |         shortrangedata, longrangeData, keysets, forcekeysets);
 | 
|---|
| [ce70d25] | 747 |     status = appendToHomologies(shortrangeresults, longrangeresults, false);
 | 
|---|
| [a3427f] | 748 |   }
 | 
|---|
| [e2925fd] | 749 | #else
 | 
|---|
| [18ed8c] | 750 |   if (DoLongrange) {
 | 
|---|
| [e2925fd] | 751 |     ELOG(2, "File contains long-range information but long-range analysis capability not compiled in.");
 | 
|---|
| [18ed8c] | 752 |   }
 | 
|---|
| [d76d65] | 753 | 
 | 
|---|
 | 754 |   // append all keysets to homology file with short-range info only (without grids)
 | 
|---|
| [ce70d25] | 755 |   status = appendToHomologies(shortrangeresults, false);
 | 
|---|
| [a3427f] | 756 | #endif
 | 
|---|
 | 757 | 
 | 
|---|
| [16893f] | 758 |   // we no longer clear the container
 | 
|---|
 | 759 | //  container.clear();
 | 
|---|
| [a3427f] | 760 | 
 | 
|---|
| [ce70d25] | 761 |   if (status)
 | 
|---|
 | 762 |     return Action::success;
 | 
|---|
 | 763 |   else {
 | 
|---|
 | 764 |     STATUS("AnalyseFragmentResultsAction failed: invalid results, failed to append to homologies.");
 | 
|---|
 | 765 |     return Action::failure;
 | 
|---|
 | 766 |   }
 | 
|---|
| [a3427f] | 767 | }
 | 
|---|
 | 768 | 
 | 
|---|
| [b5b01e] | 769 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performUndo(ActionState::ptr _state) {
 | 
|---|
| [a3427f] | 770 |   return Action::success;
 | 
|---|
 | 771 | }
 | 
|---|
 | 772 | 
 | 
|---|
| [b5b01e] | 773 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performRedo(ActionState::ptr _state){
 | 
|---|
| [a3427f] | 774 |   return Action::success;
 | 
|---|
 | 775 | }
 | 
|---|
 | 776 | 
 | 
|---|
 | 777 | bool FragmentationAnalyseFragmentationResultsAction::canUndo() {
 | 
|---|
 | 778 |   return false;
 | 
|---|
 | 779 | }
 | 
|---|
 | 780 | 
 | 
|---|
 | 781 | bool FragmentationAnalyseFragmentationResultsAction::shouldUndo() {
 | 
|---|
 | 782 |   return false;
 | 
|---|
 | 783 | }
 | 
|---|
 | 784 | /** =========== end of function ====================== */
 | 
|---|