| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| 5 | * Copyright (C)  2013 Frederik Heber. All rights reserved. | 
|---|
| 6 | * | 
|---|
| 7 | * | 
|---|
| 8 | *   This file is part of MoleCuilder. | 
|---|
| 9 | * | 
|---|
| 10 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
| 11 | *    it under the terms of the GNU General Public License as published by | 
|---|
| 12 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
| 13 | *    (at your option) any later version. | 
|---|
| 14 | * | 
|---|
| 15 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
| 16 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 17 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 18 | *    GNU General Public License for more details. | 
|---|
| 19 | * | 
|---|
| 20 | *    You should have received a copy of the GNU General Public License | 
|---|
| 21 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 22 | */ | 
|---|
| 23 |  | 
|---|
| 24 | /* | 
|---|
| 25 | * AnalyseFragmentationResultsAction.cpp | 
|---|
| 26 | * | 
|---|
| 27 | *  Created on: Mar 8, 2013 | 
|---|
| 28 | *      Author: heber | 
|---|
| 29 | */ | 
|---|
| 30 |  | 
|---|
| 31 | // include config.h | 
|---|
| 32 | #ifdef HAVE_CONFIG_H | 
|---|
| 33 | #include <config.h> | 
|---|
| 34 | #endif | 
|---|
| 35 |  | 
|---|
| 36 | // include headers that implement a archive in simple text format | 
|---|
| 37 | // and before MemDebug due to placement new | 
|---|
| 38 | #include <boost/archive/text_oarchive.hpp> | 
|---|
| 39 | #include <boost/archive/text_iarchive.hpp> | 
|---|
| 40 |  | 
|---|
| 41 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| 42 |  | 
|---|
| 43 | #include <boost/foreach.hpp> | 
|---|
| 44 | #include <boost/lambda/lambda.hpp> | 
|---|
| 45 | #include <boost/mpl/remove.hpp> | 
|---|
| 46 |  | 
|---|
| 47 | #include <algorithm> | 
|---|
| 48 | #include <fstream> | 
|---|
| 49 | #include <iostream> | 
|---|
| 50 | //#include <numeric> | 
|---|
| 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 |  | 
|---|
| 63 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
| 64 | #include "Atom/atom.hpp" | 
|---|
| 65 | #include "Element/element.hpp" | 
|---|
| 66 | #include "Fragmentation/EdgesPerFragment.hpp" | 
|---|
| 67 | #include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp" | 
|---|
| 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" | 
|---|
| 76 | #include "Fragmentation/Summation/SetValues/Eigenvalues.hpp" | 
|---|
| 77 | #include "Fragmentation/Summation/SetValues/Fragment.hpp" | 
|---|
| 78 | #include "Fragmentation/Summation/SetValues/FragmentForces.hpp" | 
|---|
| 79 | #include "Fragmentation/Summation/SetValues/Histogram.hpp" | 
|---|
| 80 | #include "Fragmentation/Summation/SetValues/IndexedVectors.hpp" | 
|---|
| 81 | #include "Fragmentation/Summation/IndexSetContainer.hpp" | 
|---|
| 82 | #include "Fragmentation/Summation/writeIndexedTable.hpp" | 
|---|
| 83 | #include "Fragmentation/Summation/writeTable.hpp" | 
|---|
| 84 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 85 | #include "Fragmentation/Summation/Containers/FragmentationLongRangeResults.hpp" | 
|---|
| 86 | #include "Fragmentation/Summation/Containers/GridDownsampler.hpp" | 
|---|
| 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 | 
|---|
| 92 | #include "Helpers/defs.hpp" | 
|---|
| 93 | #include "Potentials/Particles/ParticleRegistry.hpp" | 
|---|
| 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 |  | 
|---|
| 112 | /** Print cycle correction from received results. | 
|---|
| 113 | * | 
|---|
| 114 | * @param results summed up results container | 
|---|
| 115 | */ | 
|---|
| 116 | void printReceivedCycleResults( | 
|---|
| 117 | const FragmentationShortRangeResults &results, | 
|---|
| 118 | const std::string &_prefix) | 
|---|
| 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()); | 
|---|
| 127 | LOG(2, "DEBUG: Energy table with cycles is \n" << energyresult); | 
|---|
| 128 | std::string filename; | 
|---|
| 129 | filename += _prefix + std::string("_CycleEnergy.dat"); | 
|---|
| 130 | writeToFile(filename, energyresult); | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 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( | 
|---|
| 138 | const FragmentationShortRangeResults &results, | 
|---|
| 139 | const std::string &_prefix) | 
|---|
| 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; | 
|---|
| 151 | filename += _prefix + std::string("_IndexedEnergy.dat"); | 
|---|
| 152 | writeToFile(filename, energyresult); | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | /** Print (short range) energy, forces, and timings from received results. | 
|---|
| 156 | * | 
|---|
| 157 | * @param results summed up results container | 
|---|
| 158 | */ | 
|---|
| 159 | void printReceivedShortResults( | 
|---|
| 160 | const FragmentationShortRangeResults &results, | 
|---|
| 161 | const std::string &_prefix) | 
|---|
| 162 | { | 
|---|
| 163 | // print tables (without eigenvalues, they go extra) | 
|---|
| 164 | { | 
|---|
| 165 | typedef boost::mpl::remove< | 
|---|
| 166 | boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type, | 
|---|
| 167 | MPQCDataFused::energy_eigenhistogram>::type | 
|---|
| 168 | MPQCDataEnergyVector_noeigenvalues_t; | 
|---|
| 169 | const std::string energyresult = | 
|---|
| 170 | writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()( | 
|---|
| 171 | results.Result_Energy_fused, results.getMaxLevel()); | 
|---|
| 172 | LOG(1, "DEBUG: Energy table is \n" << energyresult); | 
|---|
| 173 | std::string filename; | 
|---|
| 174 | filename += _prefix + std::string("_Energy.dat"); | 
|---|
| 175 | writeToFile(filename, energyresult); | 
|---|
| 176 | } | 
|---|
| 177 |  | 
|---|
| 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()); | 
|---|
| 185 | LOG(2, "DEBUG: Eigenvalue table is \n" << eigenvalueresult); | 
|---|
| 186 | std::string filename; | 
|---|
| 187 | filename += _prefix + std::string("_Eigenvalues.dat"); | 
|---|
| 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()); | 
|---|
| 198 | LOG(2, "DEBUG: Eigenhistogram table is \n" << eigenhistogramresult); | 
|---|
| 199 | std::string filename; | 
|---|
| 200 | filename += _prefix + std::string("_Eigenhistogram.dat"); | 
|---|
| 201 | writeToFile(filename, eigenhistogramresult); | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 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()); | 
|---|
| 211 | LOG(2, "DEBUG: Eigenvalue table is \n" << eigenvalueresult); | 
|---|
| 212 | std::string filename; | 
|---|
| 213 | filename += _prefix + std::string("_Eigenvalues.dat"); | 
|---|
| 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()); | 
|---|
| 221 | LOG(2, "DEBUG: Force table is \n" << forceresult); | 
|---|
| 222 | std::string filename; | 
|---|
| 223 | filename += _prefix + std::string("_Forces.dat"); | 
|---|
| 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()); | 
|---|
| 236 | LOG(2, "DEBUG: Times table is \n" << timesresult); | 
|---|
| 237 | std::string filename; | 
|---|
| 238 | filename += _prefix + std::string("_Times.dat"); | 
|---|
| 239 | writeToFile(filename, timesresult); | 
|---|
| 240 | } | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 245 | /** Print long range energy from received results. | 
|---|
| 246 | * | 
|---|
| 247 | * @param results summed up results container | 
|---|
| 248 | */ | 
|---|
| 249 | void printReceivedFullResults( | 
|---|
| 250 | const FragmentationLongRangeResults &results, | 
|---|
| 251 | const std::string &_prefix) | 
|---|
| 252 | { | 
|---|
| 253 | // print tables per keyset(without grids, they go extra) | 
|---|
| 254 |  | 
|---|
| 255 | { | 
|---|
| 256 | const std::string gridresult = | 
|---|
| 257 | writeTable<VMGDataMap_t, VMGDataVector_t >()( | 
|---|
| 258 | results.Result_LongRange_fused, results.getMaxLevel(), 1); | 
|---|
| 259 | LOG(2, "DEBUG: VMG table is \n" << gridresult); | 
|---|
| 260 | std::string filename; | 
|---|
| 261 | filename += _prefix + std::string("_VMGEnergy.dat"); | 
|---|
| 262 | writeToFile(filename, gridresult); | 
|---|
| 263 | } | 
|---|
| 264 |  | 
|---|
| 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; | 
|---|
| 271 | filename += _prefix + std::string("_VMGForces.dat"); | 
|---|
| 272 | writeToFile(filename, forceresult); | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | { | 
|---|
| 276 | const std::string gridresult = | 
|---|
| 277 | writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()( | 
|---|
| 278 | results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 1); | 
|---|
| 279 | LOG(2, "DEBUG: LongRange table is \n" << gridresult); | 
|---|
| 280 | std::string filename; | 
|---|
| 281 | filename += _prefix + std::string("_LongRangeEnergy.dat"); | 
|---|
| 282 | writeToFile(filename, gridresult); | 
|---|
| 283 | } | 
|---|
| 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; | 
|---|
| 291 | filename += _prefix + std::string("_LongRangeForces.dat"); | 
|---|
| 292 | writeToFile(filename, forceresult); | 
|---|
| 293 | } | 
|---|
| 294 | } | 
|---|
| 295 | #endif | 
|---|
| 296 |  | 
|---|
| 297 | bool appendToHomologies( | 
|---|
| 298 | const FragmentationShortRangeResults &shortrangeresults, | 
|---|
| 299 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 300 | const FragmentationLongRangeResults &longrangeresults, | 
|---|
| 301 | #endif | 
|---|
| 302 | const bool storeGrids | 
|---|
| 303 | ) | 
|---|
| 304 | { | 
|---|
| 305 | /// read homology container (if present) | 
|---|
| 306 | HomologyContainer &homology_container = World::getInstance().getHomologies(); | 
|---|
| 307 |  | 
|---|
| 308 | /// append all fragments to a HomologyContainer | 
|---|
| 309 | HomologyContainer::container_t values; | 
|---|
| 310 |  | 
|---|
| 311 | // convert KeySetContainer to IndexSetContainer | 
|---|
| 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(); | 
|---|
| 316 | const FragmentationEdges::edges_per_fragment_t &edges_per_fragment = | 
|---|
| 317 | shortrangeresults.getEdgesPerFragment(); | 
|---|
| 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 | } | 
|---|
| 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 | } | 
|---|
| 328 | KeySetsContainer::ArrayOfIntVectors::const_iterator iter = Indices.KeySets.begin(); | 
|---|
| 329 | KeySetsContainer::ArrayOfIntVectors::const_iterator forceiter = ForceIndices.KeySets.begin(); | 
|---|
| 330 | FragmentationEdges::edges_per_fragment_t::const_iterator edgeiter = edges_per_fragment.begin(); | 
|---|
| 331 |  | 
|---|
| 332 | /// go through all fragments | 
|---|
| 333 | for (;iter != Indices.KeySets.end(); ++iter, ++forceiter, ++edgeiter) // go through each IndexSet | 
|---|
| 334 | { | 
|---|
| 335 | /// create new graph entry in HomologyContainer which is (key,value) type | 
|---|
| 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)) { | 
|---|
| 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 | 
|---|
| 347 | ELOG(1, "appendToHomologies() - force index set " << forceindexset | 
|---|
| 348 | << " does not contain index set " << (*indexset) << "."); | 
|---|
| 349 | return false; | 
|---|
| 350 | } | 
|---|
| 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 |  | 
|---|
| 358 |  | 
|---|
| 359 | /// we fill the value structure | 
|---|
| 360 | HomologyContainer::value_t value; | 
|---|
| 361 | value.containsGrids = storeGrids; | 
|---|
| 362 | // obtain fragment | 
|---|
| 363 | std::map<IndexSet::ptr, std::pair< MPQCDataFragmentMap_t, MPQCDataFragmentMap_t> >::const_iterator fragmentiter | 
|---|
| 364 | = shortrangeresults.Result_perIndexSet_Fragment.find(index); | 
|---|
| 365 | if (fragmentiter == shortrangeresults.Result_perIndexSet_Fragment.end()) { | 
|---|
| 366 | ELOG(1, "appendToHomologyFile() - cannot find index " << (*index) | 
|---|
| 367 | << " in FragmentResults."); | 
|---|
| 368 | return false; | 
|---|
| 369 | } | 
|---|
| 370 | value.fragment = boost::fusion::at_key<MPQCDataFused::fragment>(fragmentiter->second.first); | 
|---|
| 371 | LOG(1, "DEBUG: Created graph " << graph << " to fragment " << value.fragment << "."); | 
|---|
| 372 |  | 
|---|
| 373 | // obtain energy | 
|---|
| 374 | std::map<IndexSet::ptr, std::pair< MPQCDataEnergyMap_t, MPQCDataEnergyMap_t> >::const_iterator energyiter | 
|---|
| 375 | = shortrangeresults.Result_perIndexSet_Energy.find(index); | 
|---|
| 376 | if (energyiter == shortrangeresults.Result_perIndexSet_Energy.end()) { | 
|---|
| 377 | ELOG(1, "appendToHomologyFile() - cannot find index " << (*index) | 
|---|
| 378 | << " in FragmentResults."); | 
|---|
| 379 | return false; | 
|---|
| 380 | } | 
|---|
| 381 | value.edges = *edgeiter; | 
|---|
| 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 | 
|---|
| 384 |  | 
|---|
| 385 | // only store sampled grids if desired | 
|---|
| 386 | if (storeGrids) { | 
|---|
| 387 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 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); | 
|---|
| 391 | if (chargeiter == longrangeresults.Result_perIndexSet_Grid.end()) { | 
|---|
| 392 | ELOG(1, "appendToHomologyFile() - cannot find index " << (*index) | 
|---|
| 393 | << " in FragmentResults."); | 
|---|
| 394 | return false; | 
|---|
| 395 | } | 
|---|
| 396 | value.charge_distribution = boost::fusion::at_key<MPQCDataFused::sampled_grid>(chargeiter->second.second); // contributions | 
|---|
| 397 |  | 
|---|
| 398 | // obtain potential distribution | 
|---|
| 399 | std::map<IndexSet::ptr, std::pair< VMGDataGridMap_t, VMGDataGridMap_t> >::const_iterator potentialiter | 
|---|
| 400 | = longrangeresults.Result_perIndexSet_LongRange_Grid.find(index); | 
|---|
| 401 | if (potentialiter == longrangeresults.Result_perIndexSet_LongRange_Grid.end()) { | 
|---|
| 402 | ELOG(1, "appendToHomologyFile() - cannot find index " << (*index) | 
|---|
| 403 | << " in FragmentResults."); | 
|---|
| 404 | return false; | 
|---|
| 405 | } | 
|---|
| 406 | // add e+n potentials | 
|---|
| 407 | value.potential_distribution = | 
|---|
| 408 | boost::fusion::at_key<VMGDataFused::both_sampled_potential>(potentialiter->second.second); // contributions | 
|---|
| 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; | 
|---|
| 420 | #else | 
|---|
| 421 | ELOG(2, "Long-range information in homology desired but long-range analysis capability not compiled in."); | 
|---|
| 422 | #endif | 
|---|
| 423 | } | 
|---|
| 424 | values.insert( std::make_pair( graph, value) ); | 
|---|
| 425 | } | 
|---|
| 426 | homology_container.insert(values); | 
|---|
| 427 |  | 
|---|
| 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 | } | 
|---|
| 436 |  | 
|---|
| 437 | // for debugging: print container | 
|---|
| 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) { | 
|---|
| 442 | std::stringstream output; | 
|---|
| 443 | output << "DEBUG: graph " << iter->first | 
|---|
| 444 | << " has Fragment " << iter->second.fragment | 
|---|
| 445 | << ", associated energy contribution " << iter->second.contribution; | 
|---|
| 446 | if (iter->second.containsGrids) | 
|---|
| 447 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 448 | output  << ", and sampled grid integral " << iter->second.charge_distribution.integral(); | 
|---|
| 449 | #else | 
|---|
| 450 | output << ", and there are sampled grids but capability not compiled in"; | 
|---|
| 451 | #endif | 
|---|
| 452 | output << "."; | 
|---|
| 453 | LOG(2, output.str()); | 
|---|
| 454 | } | 
|---|
| 455 | } | 
|---|
| 456 |  | 
|---|
| 457 | return true; | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 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 |  | 
|---|
| 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, | 
|---|
| 517 | const FragmentationShortRangeResults::edges_per_fragment_t &edges_per_fragment, | 
|---|
| 518 | const FragmentationShortRangeResults &shortrangeresults, | 
|---|
| 519 | const std::string &_prefix) | 
|---|
| 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 | 
|---|
| 578 | FragmentationShortRangeResults localresults( | 
|---|
| 579 | shortrangedata, keysets, forcekeysets, edges_per_fragment, localValueMask); | 
|---|
| 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 | } | 
|---|
| 590 | printReceivedCycleResults(cycleresults, _prefix); | 
|---|
| 591 | } | 
|---|
| 592 |  | 
|---|
| 593 | static void SetForces( | 
|---|
| 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, | 
|---|
| 602 | "setForces() - obtained force vector has incorrect dimension."); | 
|---|
| 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) | 
|---|
| 611 | _atom->setAtomicForce(ForceVector); | 
|---|
| 612 | else | 
|---|
| 613 | ELOG(2, "Could not find atom to id " << index << "."); | 
|---|
| 614 | } | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performCall() { | 
|---|
| 618 | bool status=true; | 
|---|
| 619 |  | 
|---|
| 620 | /// get data and keysets from ResultsContainer | 
|---|
| 621 | FragmentationResultContainer& container = FragmentationResultContainer::getInstance(); | 
|---|
| 622 | const std::map<JobId_t, MPQCData> &shortrangedata = container.getShortRangeResults(); | 
|---|
| 623 | const KeySetsContainer &keysets = container.getKeySets(); | 
|---|
| 624 | const KeySetsContainer &forcekeysets = container.getForceKeySets(); | 
|---|
| 625 | const FragmentationResultContainer::edges_per_fragment_t edges_per_fragment = | 
|---|
| 626 | container.getEdgesPerFragment(); | 
|---|
| 627 | const bool DoLongrange = container.areFullRangeResultsPresent(); | 
|---|
| 628 | const bool IsAngstroem = true; | 
|---|
| 629 |  | 
|---|
| 630 | if (keysets.KeySets.empty()) { | 
|---|
| 631 | STATUS("There are no results in the container."); | 
|---|
| 632 | return Action::failure; | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | /// calculate normal contributions with (if present) cycles coming at their | 
|---|
| 636 | /// respective bond order. | 
|---|
| 637 | std::vector<bool> ValueMask(shortrangedata.size(), true); | 
|---|
| 638 | FragmentationShortRangeResults shortrangeresults( | 
|---|
| 639 | shortrangedata, keysets, forcekeysets, edges_per_fragment, ValueMask); | 
|---|
| 640 | shortrangeresults(shortrangedata); | 
|---|
| 641 | printReceivedShortResults(shortrangeresults, params.prefix.get()); | 
|---|
| 642 | printReceivedShortResultsPerIndex(shortrangeresults, params.prefix.get()); | 
|---|
| 643 | // add summed results to container | 
|---|
| 644 | container.addShortRangeSummedResults(shortrangeresults.getSummedShortRangeResults()); | 
|---|
| 645 |  | 
|---|
| 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()) { | 
|---|
| 680 | calculateCycleFullContribution( | 
|---|
| 681 | shortrangedata, | 
|---|
| 682 | keysets, | 
|---|
| 683 | forcekeysets, | 
|---|
| 684 | cycles, | 
|---|
| 685 | edges_per_fragment, | 
|---|
| 686 | shortrangeresults, | 
|---|
| 687 | params.prefix.get()); | 
|---|
| 688 | } | 
|---|
| 689 |  | 
|---|
| 690 | // adding obtained forces | 
|---|
| 691 | if ( const_cast<const World &>(World::getInstance()).getAllAtoms().size() != 0) { | 
|---|
| 692 | const IndexedVectors::indexedvectors_t shortrange_forces = | 
|---|
| 693 | boost::fusion::at_key<MPQCDataFused::forces>( | 
|---|
| 694 | shortrangeresults.Result_Force_fused.back() | 
|---|
| 695 | ).getVectors(); | 
|---|
| 696 | SetForces(shortrange_forces,IsAngstroem); | 
|---|
| 697 | } else { | 
|---|
| 698 | LOG(1, "INFO: Full molecule not loaded, hence will not add forces to atoms."); | 
|---|
| 699 | } | 
|---|
| 700 |  | 
|---|
| 701 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG) | 
|---|
| 702 | if (DoLongrange) { | 
|---|
| 703 | if ( const_cast<const World &>(World::getInstance()).getAllAtoms().size() == 0) { | 
|---|
| 704 | STATUS("Please load the full molecule into std::map<JobId_t, VMGData> longrangeData the world before starting this action."); | 
|---|
| 705 | return Action::failure; | 
|---|
| 706 | } | 
|---|
| 707 |  | 
|---|
| 708 | std::map<JobId_t, VMGData> longrangeData = container.getLongRangeResults(); | 
|---|
| 709 |  | 
|---|
| 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); | 
|---|
| 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(); | 
|---|
| 722 | std::advance(iter, -full_sample.size()); | 
|---|
| 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); | 
|---|
| 727 | if (longrangeData.size() > 1) // when there's just a single fragment, it corresponds to full solution | 
|---|
| 728 | longrangeData.erase(remove_iter, longrangeData.end()); | 
|---|
| 729 |  | 
|---|
| 730 | // Final phase: sum up and print result | 
|---|
| 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 |  | 
|---|
| 749 | FragmentationLongRangeResults longrangeresults( | 
|---|
| 750 | shortrangedata, longrangeData, keysets, forcekeysets); | 
|---|
| 751 | { | 
|---|
| 752 | SamplingGrid zero_globalgrid(domain); | 
|---|
| 753 | longrangeresults( | 
|---|
| 754 | shortrangedata, | 
|---|
| 755 | longrangeData, | 
|---|
| 756 | fullsolutionData, | 
|---|
| 757 | full_sample, | 
|---|
| 758 | zero_globalgrid, | 
|---|
| 759 | implicit_indices); | 
|---|
| 760 | printReceivedFullResults(longrangeresults, params.prefix.get()); | 
|---|
| 761 | } | 
|---|
| 762 |  | 
|---|
| 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(); | 
|---|
| 769 | SetForces(longrange_forces,IsAngstroem); | 
|---|
| 770 | } else { | 
|---|
| 771 | LOG(1, "INFO: Full molecule not loaded, hence will not add forces to atoms."); | 
|---|
| 772 | } | 
|---|
| 773 |  | 
|---|
| 774 | // append all keysets to homology file | 
|---|
| 775 | status = appendToHomologies(shortrangeresults, longrangeresults, params.DoStoreGrids.get()); | 
|---|
| 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( | 
|---|
| 780 | shortrangedata, longrangeData, keysets, forcekeysets); | 
|---|
| 781 | status = appendToHomologies(shortrangeresults, longrangeresults, false); | 
|---|
| 782 | } | 
|---|
| 783 | #else | 
|---|
| 784 | if (DoLongrange) { | 
|---|
| 785 | ELOG(2, "File contains long-range information but long-range analysis capability not compiled in."); | 
|---|
| 786 | } | 
|---|
| 787 |  | 
|---|
| 788 | // append all keysets to homology file with short-range info only (without grids) | 
|---|
| 789 | status = appendToHomologies(shortrangeresults, false); | 
|---|
| 790 | #endif | 
|---|
| 791 |  | 
|---|
| 792 | // we no longer clear the container | 
|---|
| 793 | //  container.clear(); | 
|---|
| 794 |  | 
|---|
| 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 | } | 
|---|
| 801 | } | 
|---|
| 802 |  | 
|---|
| 803 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performUndo(ActionState::ptr _state) { | 
|---|
| 804 | return Action::success; | 
|---|
| 805 | } | 
|---|
| 806 |  | 
|---|
| 807 | ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performRedo(ActionState::ptr _state){ | 
|---|
| 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 ====================== */ | 
|---|