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