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