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