| [edecba] | 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| [94d5ac6] | 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | * This file is part of MoleCuilder.
|
|---|
| 8 | *
|
|---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 10 | * it under the terms of the GNU General Public License as published by
|
|---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 12 | * (at your option) any later version.
|
|---|
| 13 | *
|
|---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | * GNU General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| [edecba] | 21 | */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | * FragmentationAutomationAction.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: May 18, 2012
|
|---|
| 27 | * Author: heber
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 36 | // boost asio needs specific operator new
|
|---|
| 37 | #include <boost/asio.hpp>
|
|---|
| 38 |
|
|---|
| 39 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 40 |
|
|---|
| [240c3e] | 41 | // include headers that implement a archive in simple text format
|
|---|
| 42 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| [fb881a] | 46 | #include <boost/mpl/remove.hpp>
|
|---|
| [c9f9bb] | 47 | #include <boost/lambda/lambda.hpp>
|
|---|
| [fb881a] | 48 |
|
|---|
| [240c3e] | 49 | #include <iostream>
|
|---|
| 50 |
|
|---|
| [6ca578] | 51 | #include "CodePatterns/Assert.hpp"
|
|---|
| [edecba] | 52 | #include "CodePatterns/Info.hpp"
|
|---|
| 53 | #include "CodePatterns/Log.hpp"
|
|---|
| 54 | #include "JobMarket/Jobs/FragmentJob.hpp"
|
|---|
| 55 |
|
|---|
| [184615] | 56 | #include "Fragmentation/Automation/createMatrixNrLookup.hpp"
|
|---|
| [447481] | 57 | #include "Fragmentation/Automation/extractJobIds.hpp"
|
|---|
| [27594e] | 58 | #include "Fragmentation/Automation/FragmentationChargeDensity.hpp"
|
|---|
| [376a3b] | 59 | #include "Fragmentation/Automation/FragmentationResults.hpp"
|
|---|
| [ffe057] | 60 | #include "Fragmentation/Automation/MPQCFragmentController.hpp"
|
|---|
| [238868] | 61 | #include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp"
|
|---|
| [ffe057] | 62 | #include "Fragmentation/Automation/VMGFragmentController.hpp"
|
|---|
| [edecba] | 63 | #include "Fragmentation/EnergyMatrix.hpp"
|
|---|
| 64 | #include "Fragmentation/ForceMatrix.hpp"
|
|---|
| 65 | #include "Fragmentation/Fragmentation.hpp"
|
|---|
| [766767] | 66 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
|---|
| [240c3e] | 67 | #include "Fragmentation/Homology/HomologyContainer.hpp"
|
|---|
| 68 | #include "Fragmentation/Homology/HomologyGraph.hpp"
|
|---|
| [766767] | 69 | #include "Fragmentation/KeySet.hpp"
|
|---|
| 70 | #include "Fragmentation/KeySetsContainer.hpp"
|
|---|
| [184943] | 71 | #include "Fragmentation/SetValues/Fragment.hpp"
|
|---|
| [e06820] | 72 | #include "Fragmentation/SetValues/Histogram.hpp"
|
|---|
| [e13990b] | 73 | #include "Fragmentation/SetValues/IndexedVectors.hpp"
|
|---|
| [766767] | 74 | #include "Fragmentation/Summation/IndexSetContainer.hpp"
|
|---|
| [27afbf] | 75 | #include "Fragmentation/Summation/writeTable.hpp"
|
|---|
| [edecba] | 76 | #include "Graph/DepthFirstSearchAnalysis.hpp"
|
|---|
| [8b58ac] | 77 | #include "Helpers/defs.hpp"
|
|---|
| [28e894] | 78 | #include "Jobs/MPQCJob.hpp"
|
|---|
| [4bc75d] | 79 | #include "Jobs/MPQCData.hpp"
|
|---|
| [1f66c7] | 80 | #include "Jobs/MPQCData_printKeyNames.hpp"
|
|---|
| [69c733] | 81 | #ifdef HAVE_VMG
|
|---|
| [238868] | 82 | #include "Jobs/VMGDebugGridJob.hpp"
|
|---|
| [69c733] | 83 | #include "Jobs/VMGJob.hpp"
|
|---|
| [358ddb] | 84 | #include "Jobs/VMGData.hpp"
|
|---|
| 85 | #include "Jobs/VMGDataFused.hpp"
|
|---|
| 86 | #include "Jobs/VMGDataMap.hpp"
|
|---|
| 87 | #include "Jobs/VMGData_printKeyNames.hpp"
|
|---|
| [69c733] | 88 | #endif
|
|---|
| [edecba] | 89 | #include "World.hpp"
|
|---|
| 90 |
|
|---|
| [86cfac5] | 91 | #include <fstream>
|
|---|
| [edecba] | 92 | #include <iostream>
|
|---|
| 93 | #include <string>
|
|---|
| 94 | #include <vector>
|
|---|
| 95 |
|
|---|
| [8cae4c] | 96 | #include <boost/mpl/for_each.hpp>
|
|---|
| 97 |
|
|---|
| [edecba] | 98 | #include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
|
|---|
| 99 |
|
|---|
| 100 | using namespace MoleCuilder;
|
|---|
| 101 |
|
|---|
| 102 | // and construct the stuff
|
|---|
| 103 | #include "FragmentationAutomationAction.def"
|
|---|
| 104 | #include "Action_impl_pre.hpp"
|
|---|
| 105 | /** =========== define the function ====================== */
|
|---|
| 106 |
|
|---|
| 107 | class controller_AddOn;
|
|---|
| 108 |
|
|---|
| 109 | // needs to be defined for using the FragmentController
|
|---|
| 110 | controller_AddOn *getAddOn()
|
|---|
| 111 | {
|
|---|
| 112 | return NULL;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /** Helper function to get number of atoms somehow.
|
|---|
| 116 | *
|
|---|
| 117 | * Here, we just parse the number of lines in the adjacency file as
|
|---|
| 118 | * it should correspond to the number of atoms, except when some atoms
|
|---|
| 119 | * are not bonded, but then fragmentation makes no sense.
|
|---|
| 120 | *
|
|---|
| 121 | * @param path path to the adjacency file
|
|---|
| 122 | */
|
|---|
| 123 | size_t getNoAtomsFromAdjacencyFile(const std::string &path)
|
|---|
| 124 | {
|
|---|
| 125 | size_t NoAtoms = 0;
|
|---|
| 126 |
|
|---|
| 127 | // parse in special file to get atom count (from line count)
|
|---|
| 128 | std::string filename(path);
|
|---|
| 129 | filename += FRAGMENTPREFIX;
|
|---|
| 130 | filename += ADJACENCYFILE;
|
|---|
| 131 | std::ifstream adjacency(filename.c_str());
|
|---|
| 132 | if (adjacency.fail()) {
|
|---|
| 133 | LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");
|
|---|
| 134 | return false;
|
|---|
| 135 | }
|
|---|
| 136 | std::string buffer;
|
|---|
| 137 | while (getline(adjacency, buffer))
|
|---|
| 138 | NoAtoms++;
|
|---|
| 139 | LOG(1, "INFO: There are " << NoAtoms << " atoms.");
|
|---|
| 140 |
|
|---|
| 141 | return NoAtoms;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| [c4ee08] | 146 | /** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
|
|---|
| 147 | *
|
|---|
| 148 | * @param fragmentData MPQCData resulting from the jobs
|
|---|
| 149 | * @param MatrixNrLookup Lookup up-map from job id to fragment number
|
|---|
| 150 | * @param FragmentCounter total number of fragments
|
|---|
| 151 | * @param NoAtoms total number of atoms
|
|---|
| 152 | * @param Energy energy matrix to be filled on return
|
|---|
| 153 | * @param Force force matrix to be filled on return
|
|---|
| 154 | * @return true - everything ok, false - else
|
|---|
| 155 | */
|
|---|
| 156 | bool putResultsintoMatrices(
|
|---|
| [c9f9bb] | 157 | const std::map<JobId_t, MPQCData> &fragmentData,
|
|---|
| [3dd32f] | 158 | const std::map< JobId_t, size_t > &MatrixNrLookup,
|
|---|
| [c4ee08] | 159 | const size_t FragmentCounter,
|
|---|
| 160 | const size_t NoAtoms,
|
|---|
| 161 | EnergyMatrix &Energy,
|
|---|
| 162 | ForceMatrix &Force)
|
|---|
| 163 | {
|
|---|
| [c9f9bb] | 164 | for (std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
|
|---|
| 165 | dataiter != fragmentData.end(); ++dataiter) {
|
|---|
| 166 | const MPQCData &extractedData = dataiter->second;
|
|---|
| 167 | const JobId_t &jobid = dataiter->first;
|
|---|
| [3dd32f] | 168 | std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);
|
|---|
| 169 | ASSERT( nriter != MatrixNrLookup.end(),
|
|---|
| 170 | "putResultsintoMatrices() - MatrixNrLookup does not contain id "
|
|---|
| 171 | +toString(jobid)+".");
|
|---|
| [edecba] | 172 | // place results into EnergyMatrix ...
|
|---|
| 173 | {
|
|---|
| 174 | MatrixContainer::MatrixArray matrix;
|
|---|
| 175 | matrix.resize(1);
|
|---|
| [a9558f] | 176 | matrix[0].resize(1, extractedData.energies.total);
|
|---|
| [edecba] | 177 | if (!Energy.AddMatrix(
|
|---|
| [c9f9bb] | 178 | std::string("MPQCJob ")+toString(jobid),
|
|---|
| [edecba] | 179 | matrix,
|
|---|
| [3dd32f] | 180 | nriter->second)) {
|
|---|
| [edecba] | 181 | ELOG(1, "Adding energy matrix failed.");
|
|---|
| 182 | return false;
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 | // ... and ForceMatrix (with two empty columns in front)
|
|---|
| 186 | {
|
|---|
| 187 | MatrixContainer::MatrixArray matrix;
|
|---|
| 188 | const size_t rows = extractedData.forces.size();
|
|---|
| 189 | matrix.resize(rows);
|
|---|
| 190 | for (size_t i=0;i<rows;++i) {
|
|---|
| 191 | const size_t columns = 2+extractedData.forces[i].size();
|
|---|
| 192 | matrix[i].resize(columns, 0.);
|
|---|
| 193 | // for (size_t j=0;j<2;++j)
|
|---|
| 194 | // matrix[i][j] = 0.;
|
|---|
| 195 | for (size_t j=2;j<columns;++j)
|
|---|
| 196 | matrix[i][j] = extractedData.forces[i][j-2];
|
|---|
| 197 | }
|
|---|
| 198 | if (!Force.AddMatrix(
|
|---|
| [c9f9bb] | 199 | std::string("MPQCJob ")+toString(jobid),
|
|---|
| [edecba] | 200 | matrix,
|
|---|
| [3dd32f] | 201 | nriter->second)) {
|
|---|
| [edecba] | 202 | ELOG(1, "Adding force matrix failed.");
|
|---|
| 203 | return false;
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | // add one more matrix (not required for energy)
|
|---|
| 208 | MatrixContainer::MatrixArray matrix;
|
|---|
| 209 | matrix.resize(1);
|
|---|
| 210 | matrix[0].resize(1, 0.);
|
|---|
| 211 | if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
|---|
| 212 | return false;
|
|---|
| 213 | // but for energy because we need to know total number of atoms
|
|---|
| 214 | matrix.resize(NoAtoms);
|
|---|
| 215 | for (size_t i = 0; i< NoAtoms; ++i)
|
|---|
| 216 | matrix[i].resize(2+NDIM, 0.);
|
|---|
| 217 | if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
|---|
| 218 | return false;
|
|---|
| 219 |
|
|---|
| [c4ee08] | 220 | return true;
|
|---|
| 221 | }
|
|---|
| [849cd8] | 222 |
|
|---|
| 223 | /** Print MPQCData from received results.
|
|---|
| 224 | *
|
|---|
| [c9f9bb] | 225 | * @param fragmentData MPQCData resulting from the jobs, associated to job id
|
|---|
| [849cd8] | 226 | * @param KeySetFilename filename with keysets to associate forces correctly
|
|---|
| 227 | * @param NoAtoms total number of atoms
|
|---|
| 228 | * @param full_sample summed up charge from fragments on return
|
|---|
| [c4ee08] | 229 | */
|
|---|
| 230 | bool printReceivedMPQCResults(
|
|---|
| [c9f9bb] | 231 | const std::map<JobId_t, MPQCData> &fragmentData,
|
|---|
| [c4ee08] | 232 | const std::string &KeySetFilename,
|
|---|
| [c699f4] | 233 | size_t NoAtoms)
|
|---|
| [c4ee08] | 234 | {
|
|---|
| [c9f9bb] | 235 | // create a vector of all job ids
|
|---|
| 236 | std::vector<JobId_t> jobids;
|
|---|
| 237 | std::transform(fragmentData.begin(),fragmentData.end(),
|
|---|
| 238 | std::back_inserter(jobids),
|
|---|
| 239 | boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )
|
|---|
| 240 | );
|
|---|
| 241 |
|
|---|
| [c4ee08] | 242 | // create lookup from job nr to fragment number
|
|---|
| 243 | size_t FragmentCounter = 0;
|
|---|
| [3dd32f] | 244 | const std::map< JobId_t, size_t > MatrixNrLookup=
|
|---|
| 245 | createMatrixNrLookup(jobids, FragmentCounter);
|
|---|
| [c4ee08] | 246 |
|
|---|
| 247 | // place results into maps
|
|---|
| 248 | EnergyMatrix Energy;
|
|---|
| 249 | ForceMatrix Force;
|
|---|
| [c9f9bb] | 250 | if (!putResultsintoMatrices(fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
|
|---|
| [c4ee08] | 251 | return false;
|
|---|
| 252 |
|
|---|
| 253 | // initialise keysets
|
|---|
| [6ca578] | 254 | KeySetsContainer KeySet;
|
|---|
| [8b58ac] | 255 | KeySetsContainer ForceKeySet;
|
|---|
| [edecba] | 256 | if (!Energy.InitialiseIndices()) return false;
|
|---|
| 257 |
|
|---|
| 258 | if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
|
|---|
| 259 |
|
|---|
| [8b58ac] | 260 | {
|
|---|
| [c4ee08] | 261 | // else needs keysets without hydrogens
|
|---|
| [8b58ac] | 262 | std::stringstream filename;
|
|---|
| 263 | filename << FRAGMENTPREFIX << KEYSETFILE;
|
|---|
| 264 | if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
|---|
| 265 | }
|
|---|
| [edecba] | 266 |
|
|---|
| [8b58ac] | 267 | {
|
|---|
| [c4ee08] | 268 | // forces need keysets including hydrogens
|
|---|
| [8b58ac] | 269 | std::stringstream filename;
|
|---|
| 270 | filename << FRAGMENTPREFIX << FORCESFILE;
|
|---|
| 271 | if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
|---|
| 272 | }
|
|---|
| [6ca578] | 273 |
|
|---|
| 274 | // combine all found data
|
|---|
| [edecba] | 275 | if (!KeySet.ParseManyBodyTerms()) return false;
|
|---|
| 276 |
|
|---|
| [c4ee08] | 277 | EnergyMatrix EnergyFragments;
|
|---|
| 278 | ForceMatrix ForceFragments;
|
|---|
| [edecba] | 279 | if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
|
|---|
| 280 | if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
|
|---|
| 281 |
|
|---|
| 282 | if(!Energy.SetLastMatrix(0., 0)) return false;
|
|---|
| 283 | if(!Force.SetLastMatrix(0., 2)) return false;
|
|---|
| 284 |
|
|---|
| 285 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
|---|
| 286 | // --------- sum up energy --------------------
|
|---|
| 287 | LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
|
|---|
| 288 | if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
|
|---|
| 289 | if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
|
|---|
| 290 |
|
|---|
| 291 | // --------- sum up Forces --------------------
|
|---|
| 292 | LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
|
|---|
| 293 | if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
|
|---|
| 294 | if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | // for debugging print resulting energy and forces
|
|---|
| 298 | LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
|
|---|
| 299 | std::stringstream output;
|
|---|
| 300 | for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
|
|---|
| 301 | for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
|
|---|
| 302 | output << Force.Matrix[ FragmentCounter ][i][j] << " ";
|
|---|
| 303 | output << "\n";
|
|---|
| 304 | }
|
|---|
| 305 | LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
|
|---|
| 306 |
|
|---|
| 307 | return true;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| [86cfac5] | 310 | void writeToFile(const std::string &filename, const std::string contents)
|
|---|
| 311 | {
|
|---|
| 312 | std::ofstream tablefile(filename.c_str());
|
|---|
| 313 | tablefile << contents;
|
|---|
| 314 | tablefile.close();
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| [358ddb] | 317 | /** Print MPQCData from received results.
|
|---|
| 318 | *
|
|---|
| [376a3b] | 319 | * @param results summed up results container
|
|---|
| [358ddb] | 320 | */
|
|---|
| [376a3b] | 321 | void printReceivedFullResults(
|
|---|
| 322 | const FragmentationResults &results)
|
|---|
| [358ddb] | 323 | {
|
|---|
| [376a3b] | 324 | // print tables (without eigenvalues, they go extra)
|
|---|
| [86cfac5] | 325 | {
|
|---|
| 326 | typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type
|
|---|
| 327 | MPQCDataEnergyVector_noeigenvalues_t;
|
|---|
| 328 | const std::string energyresult =
|
|---|
| 329 | writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
|
|---|
| 330 | results.Result_Energy_fused, results.getMaxLevel());
|
|---|
| 331 | LOG(0, "Energy table is \n" << energyresult);
|
|---|
| 332 | std::string filename;
|
|---|
| 333 | filename += FRAGMENTPREFIX + std::string("_Energy.dat");
|
|---|
| 334 | writeToFile(filename, energyresult);
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| [82cbe4] | 337 | {
|
|---|
| 338 | const std::string gridresult =
|
|---|
| 339 | writeTable<VMGDataMap_t, VMGDataVector_t >()(
|
|---|
| 340 | results.Result_LongRange_fused, results.getMaxLevel(), 2);
|
|---|
| 341 | LOG(0, "VMG table is \n" << gridresult);
|
|---|
| 342 | std::string filename;
|
|---|
| 343 | filename += FRAGMENTPREFIX + std::string("_VMGEnergy.dat");
|
|---|
| 344 | writeToFile(filename, gridresult);
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| [86cfac5] | 347 | {
|
|---|
| 348 | const std::string gridresult =
|
|---|
| 349 | writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()(
|
|---|
| [d4f31f] | 350 | results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 2);
|
|---|
| [86cfac5] | 351 | LOG(0, "LongRange table is \n" << gridresult);
|
|---|
| 352 | std::string filename;
|
|---|
| 353 | filename += FRAGMENTPREFIX + std::string("_LongRangeEnergy.dat");
|
|---|
| 354 | writeToFile(filename, gridresult);
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | {
|
|---|
| 358 | const std::string eigenvalueresult;
|
|---|
| 359 | LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
|
|---|
| 360 | std::string filename;
|
|---|
| 361 | filename += FRAGMENTPREFIX + std::string("_Eigenvalues.dat");
|
|---|
| 362 | writeToFile(filename, eigenvalueresult);
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | {
|
|---|
| 366 | const std::string forceresult =
|
|---|
| 367 | writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
|
|---|
| 368 | results.Result_Force_fused, results.getMaxLevel());
|
|---|
| 369 | LOG(0, "Force table is \n" << forceresult);
|
|---|
| 370 | std::string filename;
|
|---|
| 371 | filename += FRAGMENTPREFIX + std::string("_Forces.dat");
|
|---|
| 372 | writeToFile(filename, forceresult);
|
|---|
| 373 | }
|
|---|
| [376a3b] | 374 | // we don't want to print grid to a table
|
|---|
| [86cfac5] | 375 | {
|
|---|
| 376 | // print times (without flops for now)
|
|---|
| 377 | typedef boost::mpl::remove<
|
|---|
| 378 | boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_total_flops>::type,
|
|---|
| 379 | MPQCDataFused::times_gather_flops>::type
|
|---|
| 380 | MPQCDataTimeVector_noflops_t;
|
|---|
| 381 | const std::string timesresult =
|
|---|
| 382 | writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
|
|---|
| 383 | results.Result_Time_fused, results.getMaxLevel());
|
|---|
| 384 | LOG(0, "Times table is \n" << timesresult);
|
|---|
| 385 | std::string filename;
|
|---|
| 386 | filename += FRAGMENTPREFIX + std::string("_Times.dat");
|
|---|
| 387 | writeToFile(filename, timesresult);
|
|---|
| 388 | }
|
|---|
| [358ddb] | 389 | }
|
|---|
| 390 |
|
|---|
| [766767] | 391 | bool appendToHomologyFile(
|
|---|
| 392 | const boost::filesystem::path &homology_file,
|
|---|
| 393 | const FragmentationResults &results,
|
|---|
| 394 | const std::string &KeySetFilename)
|
|---|
| [240c3e] | 395 | {
|
|---|
| 396 | // read homology container (if present)
|
|---|
| 397 | HomologyContainer homology_container;
|
|---|
| 398 | if (boost::filesystem::exists(homology_file)) {
|
|---|
| 399 | std::ifstream returnstream(homology_file.string().c_str());
|
|---|
| 400 | if (returnstream.good()) {
|
|---|
| 401 | boost::archive::text_iarchive ia(returnstream);
|
|---|
| 402 | ia >> homology_container;
|
|---|
| 403 | } else {
|
|---|
| 404 | ELOG(2, "Failed to parse from " << homology_file.string() << ".");
|
|---|
| 405 | }
|
|---|
| 406 | returnstream.close();
|
|---|
| 407 | } else {
|
|---|
| 408 | LOG(2, "Could not open " << homology_file.string()
|
|---|
| 409 | << ", creating empty container.");
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | // append all fragments to a HomologyContainer
|
|---|
| 413 | HomologyContainer::container_t values;
|
|---|
| [766767] | 414 | KeySetsContainer ForceKeySet;
|
|---|
| 415 | {
|
|---|
| 416 | // forces need keysets including hydrogens
|
|---|
| 417 | std::stringstream filename;
|
|---|
| 418 | filename << FRAGMENTPREFIX << FORCESFILE;
|
|---|
| 419 | #ifndef NDEBUG
|
|---|
| 420 | bool status =
|
|---|
| 421 | #endif
|
|---|
| 422 | ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), results.Result_perIndexSet_Energy.size());
|
|---|
| 423 | ASSERT( status,
|
|---|
| 424 | "FragmentationResults::FragmentationResults() - ParseKeySets() of "
|
|---|
| 425 | +toString(FORCESFILE)+" failed.");
|
|---|
| 426 | }
|
|---|
| 427 | // convert KeySetContainer to IndexSetContainer
|
|---|
| 428 | IndexSetContainer::ptr container(new IndexSetContainer(ForceKeySet));
|
|---|
| 429 | for (IndexSetContainer::Container_t::const_iterator iter = container->getContainer().begin();
|
|---|
| 430 | iter != container->getContainer().end(); ++iter) // go through each IndexSet
|
|---|
| 431 | {
|
|---|
| 432 | const IndexSet::ptr &index = *iter;
|
|---|
| 433 | HomologyGraph graph(*index);
|
|---|
| 434 | HomologyContainer::value_t value;
|
|---|
| 435 | std::map<IndexSet::ptr, MPQCDataFragmentMap_t>::const_iterator fragmentiter
|
|---|
| 436 | = results.Result_perIndexSet_Fragment.find(index);
|
|---|
| 437 | ASSERT( fragmentiter != results.Result_perIndexSet_Fragment.end(),
|
|---|
| 438 | "appendToHomologyFile() - cannot find index "+toString(*index)
|
|---|
| 439 | +" in FragmentResults.");
|
|---|
| 440 | value.first = boost::fusion::at_key<MPQCDataFused::fragment>(fragmentiter->second);
|
|---|
| 441 | std::map<IndexSet::ptr, MPQCDataEnergyMap_t>::const_iterator energyiter
|
|---|
| 442 | = results.Result_perIndexSet_Energy.find(index);
|
|---|
| 443 | ASSERT( energyiter != results.Result_perIndexSet_Energy.end(),
|
|---|
| 444 | "appendToHomologyFile() - cannot find index "+toString(*index)
|
|---|
| 445 | +" in FragmentResults.");
|
|---|
| 446 | value.second = boost::fusion::at_key<MPQCDataFused::energy_total>(energyiter->second);
|
|---|
| 447 | values.insert( std::make_pair( graph, value) );
|
|---|
| 448 | }
|
|---|
| [240c3e] | 449 | homology_container.insert(values);
|
|---|
| 450 |
|
|---|
| 451 | // store homology container again
|
|---|
| 452 | std::ofstream outputstream(homology_file.string().c_str());
|
|---|
| [b8f0b25] | 453 | if (outputstream.good()) { // check if opened
|
|---|
| [240c3e] | 454 | boost::archive::text_oarchive oa(outputstream);
|
|---|
| 455 | oa << homology_container;
|
|---|
| 456 | if (outputstream.fail()) { // check if correctly written
|
|---|
| 457 | LOG(1, "Failed to write to file " << homology_file.string() << ".");
|
|---|
| 458 | return false;
|
|---|
| 459 | } else
|
|---|
| 460 | outputstream.close();
|
|---|
| 461 | } else {
|
|---|
| 462 | LOG(1, "Failed to open file " << homology_file.string()
|
|---|
| 463 | << " for writing.");
|
|---|
| 464 | return false;
|
|---|
| 465 | }
|
|---|
| 466 | return true;
|
|---|
| 467 | }
|
|---|
| [edecba] | 468 |
|
|---|
| [c5324f] | 469 | Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
|
|---|
| 470 | boost::asio::io_service io_service;
|
|---|
| 471 |
|
|---|
| 472 | // TODO: Have io_service run in second thread and merge with current again eventually
|
|---|
| 473 |
|
|---|
| [4f056e] | 474 | size_t Exitflag = 0;
|
|---|
| [c9f9bb] | 475 | std::map<JobId_t, MPQCData> fragmentData;
|
|---|
| [4f056e] | 476 | {
|
|---|
| 477 | MPQCFragmentController mpqccontroller(io_service);
|
|---|
| 478 | mpqccontroller.setHost(params.host.get());
|
|---|
| 479 | mpqccontroller.setPort(params.port.get());
|
|---|
| 480 | mpqccontroller.setLevel(params.level.get());
|
|---|
| 481 | // Phase One: obtain ids
|
|---|
| 482 | std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
|
|---|
| 483 | mpqccontroller.requestIds(jobfiles.size());
|
|---|
| 484 |
|
|---|
| 485 | // Phase Two: create and add MPQCJobs
|
|---|
| 486 | if (!mpqccontroller.addJobsFromFiles(params.executable.get().string(), jobfiles))
|
|---|
| 487 | return Action::failure;
|
|---|
| 488 |
|
|---|
| 489 | // Phase Three: calculate result
|
|---|
| 490 | mpqccontroller.waitforResults(jobfiles.size());
|
|---|
| 491 | mpqccontroller.getResults(fragmentData);
|
|---|
| 492 |
|
|---|
| 493 | Exitflag += mpqccontroller.getExitflag();
|
|---|
| 494 | }
|
|---|
| [c5324f] | 495 |
|
|---|
| [69c733] | 496 | #ifdef HAVE_VMG
|
|---|
| 497 | if (params.DoLongrange.get()) {
|
|---|
| [db6f7d] | 498 | if ( World::getInstance().getAllAtoms().size() == 0) {
|
|---|
| 499 | ELOG(1, "Please load the full molecule into the world before starting this action.");
|
|---|
| 500 | return Action::failure;
|
|---|
| 501 | }
|
|---|
| [06865e] | 502 |
|
|---|
| [849cd8] | 503 | // obtain combined charge density
|
|---|
| [27594e] | 504 | FragmentationChargeDensity summedChargeDensity(
|
|---|
| [849cd8] | 505 | fragmentData,
|
|---|
| [27594e] | 506 | params.path.get());
|
|---|
| 507 | const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
|
|---|
| [849cd8] | 508 |
|
|---|
| [4f056e] | 509 | LOG(1, "INFO: There are " << fragmentData.size() << " short-range and "
|
|---|
| 510 | << full_sample.size() << " level-wise long-range jobs.");
|
|---|
| [69c733] | 511 |
|
|---|
| [4f056e] | 512 | // Phase Four: obtain more ids
|
|---|
| [c9f9bb] | 513 | std::map<JobId_t, VMGData> longrangeData;
|
|---|
| [4f056e] | 514 | {
|
|---|
| 515 | VMGFragmentController vmgcontroller(io_service);
|
|---|
| 516 | vmgcontroller.setHost(params.host.get());
|
|---|
| 517 | vmgcontroller.setPort(params.port.get());
|
|---|
| 518 | const size_t NoJobs = fragmentData.size()+full_sample.size();
|
|---|
| 519 | vmgcontroller.requestIds(NoJobs);
|
|---|
| 520 |
|
|---|
| 521 | // Phase Five: create VMGJobs
|
|---|
| 522 | const size_t near_field_cells = params.near_field_cells.get();
|
|---|
| [cd2591] | 523 | const size_t interpolation_degree = params.interpolation_degree.get();
|
|---|
| [4f056e] | 524 | if (!vmgcontroller.createLongRangeJobs(
|
|---|
| 525 | fragmentData,
|
|---|
| 526 | full_sample,
|
|---|
| [cd2591] | 527 | summedChargeDensity.getFragment(),
|
|---|
| 528 | near_field_cells,
|
|---|
| 529 | interpolation_degree))
|
|---|
| [4f056e] | 530 | return Action::failure;
|
|---|
| 531 |
|
|---|
| 532 | // Phase Six: calculate result
|
|---|
| 533 | vmgcontroller.waitforResults(NoJobs);
|
|---|
| 534 | vmgcontroller.getResults(longrangeData);
|
|---|
| 535 | ASSERT( NoJobs == longrangeData.size(),
|
|---|
| 536 | "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
|
|---|
| 537 | +toString(full_sample.size())+"="+toString(NoJobs)
|
|---|
| 538 | +" and VMGresults "+toString(longrangeData.size())+" don't match.");
|
|---|
| 539 | Exitflag += vmgcontroller.getExitflag();
|
|---|
| 540 | }
|
|---|
| [a2295a] | 541 |
|
|---|
| 542 | // remove full solution corresponding to full_sample from map (must be highest ids), has to be treated extra
|
|---|
| 543 | std::map<JobId_t, VMGData>::iterator iter = longrangeData.end();
|
|---|
| 544 | for (size_t i=0;i<full_sample.size();++i)
|
|---|
| 545 | --iter;
|
|---|
| 546 | std::map<JobId_t, VMGData>::iterator remove_iter = iter;
|
|---|
| 547 | std::vector<VMGData> fullsolutionData;
|
|---|
| 548 | for (; iter != longrangeData.end(); ++iter)
|
|---|
| 549 | fullsolutionData.push_back(iter->second);
|
|---|
| 550 | longrangeData.erase(remove_iter, longrangeData.end());
|
|---|
| [358ddb] | 551 |
|
|---|
| [376a3b] | 552 | // Final phase: sum up and print result
|
|---|
| [b8f0b25] | 553 | FragmentationResults results(
|
|---|
| 554 | fragmentData,
|
|---|
| 555 | longrangeData,
|
|---|
| 556 | fullsolutionData,
|
|---|
| 557 | params.path.get(),
|
|---|
| 558 | getNoAtomsFromAdjacencyFile(params.path.get()),
|
|---|
| 559 | full_sample);
|
|---|
| [238868] | 560 |
|
|---|
| [b8f0b25] | 561 | {
|
|---|
| [376a3b] | 562 | LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
|
|---|
| 563 | printReceivedFullResults(results);
|
|---|
| [4f056e] | 564 | }
|
|---|
| [376a3b] | 565 |
|
|---|
| [240c3e] | 566 | // append all keysets to homology file
|
|---|
| [b8f0b25] | 567 | if (Exitflag == 0) {
|
|---|
| [240c3e] | 568 | const boost::filesystem::path &homology_file = params.homology_file.get();
|
|---|
| [b8f0b25] | 569 | if (homology_file.string() != "") {
|
|---|
| 570 | LOG(1, "INFO: Appending HomologyGraphs to file " << homology_file.string() << ".");
|
|---|
| [766767] | 571 | if (!appendToHomologyFile(homology_file, results, params.path.get()))
|
|---|
| [b8f0b25] | 572 | Exitflag = 1;
|
|---|
| 573 | }
|
|---|
| [240c3e] | 574 | }
|
|---|
| 575 |
|
|---|
| [4f056e] | 576 | std::map<JobId_t, std::string> debugData;
|
|---|
| 577 | {
|
|---|
| [a2295a] | 578 | if (!full_sample.empty()) {
|
|---|
| [376a3b] | 579 | // create debug jobs for each level to print the summed-up potential to vtk files
|
|---|
| [4f056e] | 580 | VMGDebugGridFragmentController debugcontroller(io_service);
|
|---|
| 581 | debugcontroller.setHost(params.host.get());
|
|---|
| 582 | debugcontroller.setPort(params.port.get());
|
|---|
| [a2295a] | 583 | debugcontroller.requestIds(full_sample.size());
|
|---|
| 584 | if (!debugcontroller.createDebugJobs(full_sample))
|
|---|
| 585 | return Action::failure;
|
|---|
| 586 | debugcontroller.waitforResults(full_sample.size());
|
|---|
| 587 | debugcontroller.getResults(debugData);
|
|---|
| [4f056e] | 588 | Exitflag += debugcontroller.getExitflag();
|
|---|
| [a2295a] | 589 | }
|
|---|
| [2764e0] | 590 | }
|
|---|
| [69c733] | 591 | }
|
|---|
| [358ddb] | 592 | #else
|
|---|
| 593 | // Final phase: print result
|
|---|
| 594 | {
|
|---|
| 595 | LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
|
|---|
| 596 | printReceivedMPQCResults(
|
|---|
| 597 | fragmentData,
|
|---|
| 598 | params.path.get(),
|
|---|
| [c699f4] | 599 | getNoAtomsFromAdjacencyFile(params.path.get()));
|
|---|
| [358ddb] | 600 | }
|
|---|
| [69c733] | 601 | #endif
|
|---|
| [edecba] | 602 |
|
|---|
| 603 | return (Exitflag == 0) ? Action::success : Action::failure;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
|
|---|
| 607 | return Action::success;
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 | Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
|
|---|
| 611 | return Action::success;
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | bool FragmentationFragmentationAutomationAction::canUndo() {
|
|---|
| 615 | return false;
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | bool FragmentationFragmentationAutomationAction::shouldUndo() {
|
|---|
| 619 | return false;
|
|---|
| 620 | }
|
|---|
| 621 | /** =========== end of function ====================== */
|
|---|