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