[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>
|
---|
| 42 |
|
---|
[6ca578] | 43 | #include "CodePatterns/Assert.hpp"
|
---|
[edecba] | 44 | #include "CodePatterns/Info.hpp"
|
---|
| 45 | #include "CodePatterns/Log.hpp"
|
---|
| 46 | #include "JobMarket/Controller/FragmentController.hpp"
|
---|
| 47 | #include "JobMarket/Jobs/FragmentJob.hpp"
|
---|
| 48 |
|
---|
| 49 | #include "Atom/atom.hpp"
|
---|
[d12d621] | 50 | #include "Box.hpp"
|
---|
[06865e] | 51 | #include "Element/element.hpp"
|
---|
[edecba] | 52 | #include "Fragmentation/EnergyMatrix.hpp"
|
---|
| 53 | #include "Fragmentation/ForceMatrix.hpp"
|
---|
| 54 | #include "Fragmentation/Fragmentation.hpp"
|
---|
[184943] | 55 | #include "Fragmentation/SetValues/Fragment.hpp"
|
---|
[e06820] | 56 | #include "Fragmentation/SetValues/Histogram.hpp"
|
---|
[e13990b] | 57 | #include "Fragmentation/SetValues/IndexedVectors.hpp"
|
---|
[edecba] | 58 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
---|
[6ca578] | 59 | #include "Fragmentation/KeySet.hpp"
|
---|
[edecba] | 60 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
[0398bd] | 61 | #include "Fragmentation/Summation/OrthogonalSumUpPerLevel.hpp"
|
---|
| 62 | #include "Fragmentation/Summation/SumUpPerLevel.hpp"
|
---|
[358ddb] | 63 | #include "Fragmentation/Summation/OrthogonalFullSummator.hpp"
|
---|
| 64 | #include "Fragmentation/Summation/OrthogonalSummation.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"
|
---|
[849cd8] | 71 | #include "Jobs/Grid/SamplingGrid.hpp"
|
---|
[d12d621] | 72 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
[69c733] | 73 | #ifdef HAVE_VMG
|
---|
| 74 | #include "Jobs/VMGJob.hpp"
|
---|
[358ddb] | 75 | #include "Jobs/VMGData.hpp"
|
---|
| 76 | #include "Jobs/VMGDataFused.hpp"
|
---|
| 77 | #include "Jobs/VMGDataMap.hpp"
|
---|
| 78 | #include "Jobs/VMGData_printKeyNames.hpp"
|
---|
[69c733] | 79 | #endif
|
---|
[edecba] | 80 | #include "molecule.hpp"
|
---|
| 81 | #include "World.hpp"
|
---|
| 82 |
|
---|
| 83 | #include <iostream>
|
---|
| 84 | #include <string>
|
---|
| 85 | #include <vector>
|
---|
| 86 |
|
---|
[8cae4c] | 87 | #include <boost/mpl/for_each.hpp>
|
---|
| 88 |
|
---|
[edecba] | 89 | #include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
|
---|
| 90 |
|
---|
| 91 | using namespace MoleCuilder;
|
---|
| 92 |
|
---|
| 93 | // and construct the stuff
|
---|
| 94 | #include "FragmentationAutomationAction.def"
|
---|
| 95 | #include "Action_impl_pre.hpp"
|
---|
| 96 | /** =========== define the function ====================== */
|
---|
| 97 |
|
---|
| 98 | class controller_AddOn;
|
---|
| 99 |
|
---|
| 100 | // needs to be defined for using the FragmentController
|
---|
| 101 | controller_AddOn *getAddOn()
|
---|
| 102 | {
|
---|
| 103 | return NULL;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[d12d621] | 106 | const int LEVEL = 5;
|
---|
| 107 |
|
---|
[edecba] | 108 | /** Creates a MPQCCommandJob with argument \a filename.
|
---|
| 109 | *
|
---|
| 110 | * @param jobs created job is added to this vector
|
---|
| 111 | * @param command mpqc command to execute
|
---|
| 112 | * @param filename filename being argument to job
|
---|
| 113 | * @param nextid id for this job
|
---|
| 114 | */
|
---|
| 115 | void parsejob(
|
---|
| 116 | std::vector<FragmentJob::ptr> &jobs,
|
---|
| 117 | const std::string &command,
|
---|
| 118 | const std::string &filename,
|
---|
| 119 | const JobId_t nextid)
|
---|
| 120 | {
|
---|
| 121 | std::ifstream file;
|
---|
| 122 | file.open(filename.c_str());
|
---|
| 123 | ASSERT( file.good(), "parsejob() - file "+filename+" does not exist.");
|
---|
| 124 | std::string output((std::istreambuf_iterator<char>(file)),
|
---|
| 125 | std::istreambuf_iterator<char>());
|
---|
[d12d621] | 126 | double begin[NDIM] = { 0., 0., 0. };
|
---|
| 127 | const RealSpaceMatrix& M = World::getInstance().getDomain().getM();
|
---|
| 128 | const double size = M.at(0,0);
|
---|
| 129 | ASSERT( M.determinant() == size*size*size,
|
---|
| 130 | "parsejob() - current domain matrix "+toString(M)+" is not cubic.");
|
---|
| 131 | const int level = LEVEL;
|
---|
| 132 | FragmentJob::ptr testJob( new MPQCJob(nextid, output, begin, size, level) );
|
---|
[edecba] | 133 | jobs.push_back(testJob);
|
---|
| 134 | file.close();
|
---|
| 135 | LOG(1, "INFO: Added MPQCCommandJob from file "+filename+".");
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | /** Helper function to get number of atoms somehow.
|
---|
| 139 | *
|
---|
| 140 | * Here, we just parse the number of lines in the adjacency file as
|
---|
| 141 | * it should correspond to the number of atoms, except when some atoms
|
---|
| 142 | * are not bonded, but then fragmentation makes no sense.
|
---|
| 143 | *
|
---|
| 144 | * @param path path to the adjacency file
|
---|
| 145 | */
|
---|
| 146 | size_t getNoAtomsFromAdjacencyFile(const std::string &path)
|
---|
| 147 | {
|
---|
| 148 | size_t NoAtoms = 0;
|
---|
| 149 |
|
---|
| 150 | // parse in special file to get atom count (from line count)
|
---|
| 151 | std::string filename(path);
|
---|
| 152 | filename += FRAGMENTPREFIX;
|
---|
| 153 | filename += ADJACENCYFILE;
|
---|
| 154 | std::ifstream adjacency(filename.c_str());
|
---|
| 155 | if (adjacency.fail()) {
|
---|
| 156 | LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");
|
---|
| 157 | return false;
|
---|
| 158 | }
|
---|
| 159 | std::string buffer;
|
---|
| 160 | while (getline(adjacency, buffer))
|
---|
| 161 | NoAtoms++;
|
---|
| 162 | LOG(1, "INFO: There are " << NoAtoms << " atoms.");
|
---|
| 163 |
|
---|
| 164 | return NoAtoms;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[2764e0] | 167 | /** Extracts MPQCData from received vector of FragmentResults.
|
---|
| 168 | *
|
---|
| 169 | * @param results results to extract MPQCData from
|
---|
| 170 | * @param fragmentData on return array filled with extracted MPQCData
|
---|
| 171 | */
|
---|
[a0f8d3] | 172 | template <typename T>
|
---|
| 173 | void ConvertFragmentResultTo(
|
---|
[2764e0] | 174 | const std::vector<FragmentResult::ptr> &results,
|
---|
[a0f8d3] | 175 | std::vector<T> &fragmentData)
|
---|
[2764e0] | 176 | {
|
---|
| 177 | // extract results
|
---|
| 178 | fragmentData.clear();
|
---|
| 179 | fragmentData.reserve(results.size());
|
---|
| 180 |
|
---|
| 181 | LOG(2, "DEBUG: Parsing now through " << results.size() << " results.");
|
---|
| 182 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
---|
| 183 | iter != results.end(); ++iter) {
|
---|
| 184 | //LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
---|
[a0f8d3] | 185 | T extractedData;
|
---|
[2764e0] | 186 | std::stringstream inputstream((*iter)->result);
|
---|
| 187 | LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50));
|
---|
| 188 | boost::archive::text_iarchive ia(inputstream);
|
---|
| 189 | ia >> extractedData;
|
---|
| 190 | LOG(1, "INFO: extracted data is " << extractedData << ".");
|
---|
| 191 | fragmentData.push_back(extractedData);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | ASSERT( results.size() == fragmentData.size(),
|
---|
[a0f8d3] | 195 | "ConvertFragmentResultTo() - the number of extracted data differs from the number of results.");
|
---|
[2764e0] | 196 | }
|
---|
[edecba] | 197 |
|
---|
[c4ee08] | 198 | /** Creates a lookup from FragmentJob::id to the true fragment number.
|
---|
[edecba] | 199 | *
|
---|
[995e2f] | 200 | * @param jobids vector with job ids
|
---|
[c4ee08] | 201 | * @param MatrixNrLookup Lookup up-map, filled on return
|
---|
| 202 | * @param FragmentCounter total number of fragments on return
|
---|
[edecba] | 203 | */
|
---|
[c4ee08] | 204 | void createMatrixNrLookup(
|
---|
[995e2f] | 205 | const std::vector<JobId_t> &jobids,
|
---|
[c4ee08] | 206 | std::map< JobId_t, size_t > &MatrixNrLookup,
|
---|
| 207 | size_t &FragmentCounter)
|
---|
[edecba] | 208 | {
|
---|
| 209 | // align fragments
|
---|
[c4ee08] | 210 | MatrixNrLookup.clear();
|
---|
| 211 | FragmentCounter = 0;
|
---|
[995e2f] | 212 | for (std::vector<JobId_t>::const_iterator iter = jobids.begin();
|
---|
| 213 | iter != jobids.end(); ++iter) {
|
---|
| 214 | #ifndef NDEBUG
|
---|
| 215 | std::pair< std::map< JobId_t, size_t >::iterator, bool> inserter =
|
---|
| 216 | #endif
|
---|
| 217 | MatrixNrLookup.insert( std::make_pair(*iter, FragmentCounter++) );
|
---|
| 218 | ASSERT( inserter.second,
|
---|
| 219 | "createMatrixNrLookup() - two results have same id "
|
---|
| 220 | +toString(*iter)+".");
|
---|
[edecba] | 221 | }
|
---|
| 222 | LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
|
---|
[c4ee08] | 223 | }
|
---|
[edecba] | 224 |
|
---|
[c4ee08] | 225 | /** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
|
---|
| 226 | *
|
---|
[995e2f] | 227 | * @param jobids jobids with ids to associate with fragment number
|
---|
[c4ee08] | 228 | * @param fragmentData MPQCData resulting from the jobs
|
---|
| 229 | * @param MatrixNrLookup Lookup up-map from job id to fragment number
|
---|
| 230 | * @param FragmentCounter total number of fragments
|
---|
| 231 | * @param NoAtoms total number of atoms
|
---|
| 232 | * @param Energy energy matrix to be filled on return
|
---|
| 233 | * @param Force force matrix to be filled on return
|
---|
| 234 | * @return true - everything ok, false - else
|
---|
| 235 | */
|
---|
| 236 | bool putResultsintoMatrices(
|
---|
[995e2f] | 237 | const std::vector<JobId_t> &jobids,
|
---|
[c4ee08] | 238 | const std::vector<MPQCData> &fragmentData,
|
---|
| 239 | std::map< JobId_t, size_t > &MatrixNrLookup,
|
---|
| 240 | const size_t FragmentCounter,
|
---|
| 241 | const size_t NoAtoms,
|
---|
| 242 | EnergyMatrix &Energy,
|
---|
| 243 | ForceMatrix &Force)
|
---|
| 244 | {
|
---|
[995e2f] | 245 | ASSERT( jobids.size() == fragmentData.size(),
|
---|
| 246 | "putResultsintoMatrices() - jobids and fragmentData differ in size.");
|
---|
[2764e0] | 247 | std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
|
---|
[995e2f] | 248 | std::vector<JobId_t>::const_iterator iditer = jobids.begin();
|
---|
| 249 | for (; dataiter != fragmentData.end(); ++dataiter, ++iditer) {
|
---|
[2764e0] | 250 | const MPQCData &extractedData = *dataiter;
|
---|
[edecba] | 251 | // place results into EnergyMatrix ...
|
---|
| 252 | {
|
---|
| 253 | MatrixContainer::MatrixArray matrix;
|
---|
| 254 | matrix.resize(1);
|
---|
[a9558f] | 255 | matrix[0].resize(1, extractedData.energies.total);
|
---|
[edecba] | 256 | if (!Energy.AddMatrix(
|
---|
[995e2f] | 257 | std::string("MPQCJob ")+toString(*iditer),
|
---|
[edecba] | 258 | matrix,
|
---|
[995e2f] | 259 | MatrixNrLookup[*iditer])) {
|
---|
[edecba] | 260 | ELOG(1, "Adding energy matrix failed.");
|
---|
| 261 | return false;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | // ... and ForceMatrix (with two empty columns in front)
|
---|
| 265 | {
|
---|
| 266 | MatrixContainer::MatrixArray matrix;
|
---|
| 267 | const size_t rows = extractedData.forces.size();
|
---|
| 268 | matrix.resize(rows);
|
---|
| 269 | for (size_t i=0;i<rows;++i) {
|
---|
| 270 | const size_t columns = 2+extractedData.forces[i].size();
|
---|
| 271 | matrix[i].resize(columns, 0.);
|
---|
| 272 | // for (size_t j=0;j<2;++j)
|
---|
| 273 | // matrix[i][j] = 0.;
|
---|
| 274 | for (size_t j=2;j<columns;++j)
|
---|
| 275 | matrix[i][j] = extractedData.forces[i][j-2];
|
---|
| 276 | }
|
---|
| 277 | if (!Force.AddMatrix(
|
---|
[995e2f] | 278 | std::string("MPQCJob ")+toString(*iditer),
|
---|
[edecba] | 279 | matrix,
|
---|
[995e2f] | 280 | MatrixNrLookup[*iditer])) {
|
---|
[edecba] | 281 | ELOG(1, "Adding force matrix failed.");
|
---|
| 282 | return false;
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | // add one more matrix (not required for energy)
|
---|
| 287 | MatrixContainer::MatrixArray matrix;
|
---|
| 288 | matrix.resize(1);
|
---|
| 289 | matrix[0].resize(1, 0.);
|
---|
| 290 | if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
---|
| 291 | return false;
|
---|
| 292 | // but for energy because we need to know total number of atoms
|
---|
| 293 | matrix.resize(NoAtoms);
|
---|
| 294 | for (size_t i = 0; i< NoAtoms; ++i)
|
---|
| 295 | matrix[i].resize(2+NDIM, 0.);
|
---|
| 296 | if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
---|
| 297 | return false;
|
---|
| 298 |
|
---|
[c4ee08] | 299 | return true;
|
---|
| 300 | }
|
---|
| 301 | /** Print MPQCData from received results.
|
---|
| 302 | *
|
---|
[995e2f] | 303 | * @param jobids jobids with ids to associate with fragment number
|
---|
[c4ee08] | 304 | * @param fragmentData MPQCData resulting from the jobs
|
---|
| 305 | * @param KeySetFilename filename with keysets to associate forces correctly
|
---|
| 306 | * @param NoAtoms total number of atoms
|
---|
[184943] | 307 | * @param full_sample summed up charge density of electrons from fragments on return
|
---|
| 308 | * @param full_fragment summed up positions and charges of nuclei from fragments on return
|
---|
[849cd8] | 309 | */
|
---|
| 310 | bool sumUpChargeDensity(
|
---|
[995e2f] | 311 | const std::vector<JobId_t> &jobids,
|
---|
[849cd8] | 312 | const std::vector<MPQCData> &fragmentData,
|
---|
| 313 | const std::string &KeySetFilename,
|
---|
[184943] | 314 | SamplingGrid &full_sample,
|
---|
| 315 | Fragment &full_fragment)
|
---|
[849cd8] | 316 | {
|
---|
| 317 | // create lookup from job nr to fragment number
|
---|
| 318 | std::map< JobId_t, size_t > MatrixNrLookup;
|
---|
| 319 | size_t FragmentCounter = 0;
|
---|
[995e2f] | 320 | createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
|
---|
[849cd8] | 321 |
|
---|
| 322 | // initialise keysets
|
---|
| 323 | KeySetsContainer KeySet;
|
---|
| 324 | {
|
---|
| 325 | // else needs keysets without hydrogens
|
---|
| 326 | std::stringstream filename;
|
---|
| 327 | filename << FRAGMENTPREFIX << KEYSETFILE;
|
---|
| 328 | if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | /// prepare for OrthogonalSummation
|
---|
| 332 |
|
---|
| 333 | // convert KeySetContainer to IndexSetContainer
|
---|
| 334 | IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
|
---|
| 335 | // create the map of all keysets
|
---|
| 336 | SubsetMap::ptr subsetmap(new SubsetMap(*container));
|
---|
| 337 |
|
---|
| 338 | /// convert all MPQCData to MPQCDataMap_t
|
---|
| 339 | std::vector<MPQCDataGridMap_t> Result_Grid_fused(
|
---|
[358ddb] | 340 | OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
|
---|
[849cd8] | 341 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
[184943] | 342 | std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
|
---|
[358ddb] | 343 | OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
|
---|
[184943] | 344 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
[849cd8] | 345 | // obtain full grid
|
---|
| 346 | full_sample = boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused.back());
|
---|
[184943] | 347 | full_fragment = boost::fusion::at_key<MPQCDataFused::fragment>(Result_Fragment_fused.back());
|
---|
[849cd8] | 348 |
|
---|
| 349 | return true;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | /** Print MPQCData from received results.
|
---|
| 353 | *
|
---|
| 354 | * @param results results with ids to associate with fragment number
|
---|
| 355 | * @param fragmentData MPQCData resulting from the jobs
|
---|
| 356 | * @param KeySetFilename filename with keysets to associate forces correctly
|
---|
| 357 | * @param NoAtoms total number of atoms
|
---|
| 358 | * @param full_sample summed up charge from fragments on return
|
---|
[c4ee08] | 359 | */
|
---|
| 360 | bool printReceivedMPQCResults(
|
---|
[995e2f] | 361 | const std::vector<JobId_t> &jobids,
|
---|
[c4ee08] | 362 | const std::vector<MPQCData> &fragmentData,
|
---|
| 363 | const std::string &KeySetFilename,
|
---|
[849cd8] | 364 | size_t NoAtoms,
|
---|
| 365 | SamplingGrid &full_sample)
|
---|
[c4ee08] | 366 | {
|
---|
| 367 | // create lookup from job nr to fragment number
|
---|
| 368 | std::map< JobId_t, size_t > MatrixNrLookup;
|
---|
| 369 | size_t FragmentCounter = 0;
|
---|
[995e2f] | 370 | createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
|
---|
[c4ee08] | 371 |
|
---|
| 372 | // place results into maps
|
---|
| 373 | EnergyMatrix Energy;
|
---|
| 374 | ForceMatrix Force;
|
---|
[995e2f] | 375 | if (!putResultsintoMatrices(jobids, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
|
---|
[c4ee08] | 376 | return false;
|
---|
| 377 |
|
---|
| 378 | // initialise keysets
|
---|
[6ca578] | 379 | KeySetsContainer KeySet;
|
---|
[8b58ac] | 380 | KeySetsContainer ForceKeySet;
|
---|
[edecba] | 381 | if (!Energy.InitialiseIndices()) return false;
|
---|
| 382 |
|
---|
| 383 | if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
|
---|
| 384 |
|
---|
[8b58ac] | 385 | {
|
---|
[c4ee08] | 386 | // else needs keysets without hydrogens
|
---|
[8b58ac] | 387 | std::stringstream filename;
|
---|
| 388 | filename << FRAGMENTPREFIX << KEYSETFILE;
|
---|
| 389 | if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
---|
| 390 | }
|
---|
[edecba] | 391 |
|
---|
[8b58ac] | 392 | {
|
---|
[c4ee08] | 393 | // forces need keysets including hydrogens
|
---|
[8b58ac] | 394 | std::stringstream filename;
|
---|
| 395 | filename << FRAGMENTPREFIX << FORCESFILE;
|
---|
| 396 | if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
---|
| 397 | }
|
---|
[6ca578] | 398 |
|
---|
[a67a04] | 399 | /// prepare for OrthogonalSummation
|
---|
[fb69e9] | 400 |
|
---|
| 401 | // convert KeySetContainer to IndexSetContainer
|
---|
| 402 | IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
|
---|
[6ca578] | 403 | // create the map of all keysets
|
---|
| 404 | SubsetMap::ptr subsetmap(new SubsetMap(*container));
|
---|
| 405 |
|
---|
[e13990b] | 406 | /// convert all MPQCData to MPQCDataMap_t
|
---|
[8cae4c] | 407 | {
|
---|
[a67a04] | 408 | ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
|
---|
| 409 | "FragmentationAutomationAction::performCall() - ForceKeySet's KeySets and fragmentData differ in size.");
|
---|
[6ca578] | 410 |
|
---|
[358ddb] | 411 | typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type MPQCDataEnergyVector_noeigenvalues_t;
|
---|
[94d530f] | 412 | std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
|
---|
[358ddb] | 413 | OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
|
---|
[94d530f] | 414 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
| 415 | std::vector<MPQCDataGridMap_t> Result_Grid_fused(
|
---|
[358ddb] | 416 | OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
|
---|
[94d530f] | 417 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
| 418 | std::vector<MPQCDataTimeMap_t> Result_Time_fused(
|
---|
| 419 | SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
|
---|
| 420 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
| 421 |
|
---|
| 422 | // force has extra converter
|
---|
[c4ee08] | 423 | std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
|
---|
| 424 | convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
|
---|
[ff9963] | 425 | std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
|
---|
| 426 | AllLevelOrthogonalSummator<MPQCDataForceMap_t> forceSummer(
|
---|
[a3a382] | 427 | subsetmap,
|
---|
| 428 | MPQCData_Force_fused,
|
---|
| 429 | jobids,
|
---|
| 430 | container->getContainer(),
|
---|
[ff9963] | 431 | MatrixNrLookup,
|
---|
| 432 | Result_Force_fused);
|
---|
[a3a382] | 433 | boost::mpl::for_each<MPQCDataForceVector_t>(boost::ref(forceSummer));
|
---|
[20b3df] | 434 |
|
---|
[849cd8] | 435 | // obtain full grid
|
---|
| 436 | full_sample = boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused.back());
|
---|
| 437 |
|
---|
[fb881a] | 438 | // print tables (without eigenvalues, they go extra)
|
---|
[27afbf] | 439 | const size_t MaxLevel = subsetmap->getMaximumSubsetLevel();
|
---|
| 440 | const std::string energyresult =
|
---|
[fb881a] | 441 | writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
|
---|
[27afbf] | 442 | Result_Energy_fused, MaxLevel);
|
---|
| 443 | LOG(0, "Energy table is \n" << energyresult);
|
---|
[fb881a] | 444 | const std::string eigenvalueresult;
|
---|
| 445 |
|
---|
| 446 | LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
|
---|
[27afbf] | 447 | const std::string forceresult =
|
---|
| 448 | writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
|
---|
| 449 | Result_Force_fused, MaxLevel);
|
---|
| 450 | LOG(0, "Force table is \n" << forceresult);
|
---|
| 451 | // we don't want to print grid to a table
|
---|
[fb881a] | 452 | // print times (without flops for now)
|
---|
| 453 | typedef boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_flops>::type MPQCDataTimeVector_noflops_t;
|
---|
[27afbf] | 454 | const std::string timesresult =
|
---|
[fb881a] | 455 | writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
|
---|
[27afbf] | 456 | Result_Time_fused, MaxLevel);
|
---|
| 457 | LOG(0, "Times table is \n" << timesresult);
|
---|
[8cae4c] | 458 | }
|
---|
[56df37] | 459 |
|
---|
[6ca578] | 460 | // combine all found data
|
---|
[edecba] | 461 | if (!KeySet.ParseManyBodyTerms()) return false;
|
---|
| 462 |
|
---|
[c4ee08] | 463 | EnergyMatrix EnergyFragments;
|
---|
| 464 | ForceMatrix ForceFragments;
|
---|
[edecba] | 465 | if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
|
---|
| 466 | if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
|
---|
| 467 |
|
---|
| 468 | if(!Energy.SetLastMatrix(0., 0)) return false;
|
---|
| 469 | if(!Force.SetLastMatrix(0., 2)) return false;
|
---|
| 470 |
|
---|
| 471 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 472 | // --------- sum up energy --------------------
|
---|
| 473 | LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
|
---|
| 474 | if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
|
---|
| 475 | if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
|
---|
| 476 |
|
---|
| 477 | // --------- sum up Forces --------------------
|
---|
| 478 | LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
|
---|
| 479 | if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
|
---|
| 480 | if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | // for debugging print resulting energy and forces
|
---|
| 484 | LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
|
---|
| 485 | std::stringstream output;
|
---|
| 486 | for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
|
---|
| 487 | for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
|
---|
| 488 | output << Force.Matrix[ FragmentCounter ][i][j] << " ";
|
---|
| 489 | output << "\n";
|
---|
| 490 | }
|
---|
| 491 | LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
|
---|
| 492 |
|
---|
| 493 | return true;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
[358ddb] | 496 | /** Print MPQCData from received results.
|
---|
| 497 | *
|
---|
| 498 | * @param fragmentresults results with short-range job ids to associate with fragment number
|
---|
| 499 | * @param longrangeresults results with long-range job ids to associate with fragment number
|
---|
| 500 | * @param fragmentData MPQCData resulting from the jobs
|
---|
| 501 | * @param longrangeData VMGData resulting from long-range jobs
|
---|
[1f76f3] | 502 | * @param fullsolutionData VMGData resulting from long-range of full problem
|
---|
[358ddb] | 503 | * @param KeySetFilename filename with keysets to associate forces correctly
|
---|
| 504 | * @param NoAtoms total number of atoms
|
---|
| 505 | * @param full_sample summed up charge from fragments on return
|
---|
| 506 | */
|
---|
| 507 | bool printReceivedFullResults(
|
---|
| 508 | const std::vector<FragmentResult::ptr> &fragmentresults,
|
---|
| 509 | const std::vector<FragmentResult::ptr> &longrangeresults,
|
---|
| 510 | const std::vector<MPQCData> &fragmentData,
|
---|
| 511 | const std::vector<VMGData> &longrangeData,
|
---|
[1f76f3] | 512 | const VMGData &fullsolutionData,
|
---|
[358ddb] | 513 | const std::string &KeySetFilename,
|
---|
| 514 | size_t NoAtoms,
|
---|
| 515 | SamplingGrid &full_sample)
|
---|
| 516 | {
|
---|
[995e2f] | 517 | // create a vector of all job ids from short-range
|
---|
| 518 | std::vector<JobId_t> jobids(fragmentresults.size(), JobId::IllegalJob);
|
---|
| 519 | std::transform(fragmentresults.begin(), fragmentresults.end(), jobids.begin(),
|
---|
| 520 | boost::bind(&FragmentResult::getId,
|
---|
| 521 | boost::bind(&FragmentResult::ptr::operator->, _1)));
|
---|
| 522 |
|
---|
[358ddb] | 523 | // create lookup from job nr to fragment number
|
---|
| 524 | std::map< JobId_t, size_t > MatrixNrLookup;
|
---|
| 525 | size_t FragmentCounter = 0;
|
---|
[995e2f] | 526 | createMatrixNrLookup(jobids, MatrixNrLookup, FragmentCounter);
|
---|
[358ddb] | 527 |
|
---|
| 528 | // initialise keysets
|
---|
| 529 | KeySetsContainer KeySet;
|
---|
| 530 | KeySetsContainer ForceKeySet;
|
---|
| 531 | {
|
---|
| 532 | // else needs keysets without hydrogens
|
---|
| 533 | std::stringstream filename;
|
---|
| 534 | filename << FRAGMENTPREFIX << KEYSETFILE;
|
---|
| 535 | if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | {
|
---|
| 539 | // forces need keysets including hydrogens
|
---|
| 540 | std::stringstream filename;
|
---|
| 541 | filename << FRAGMENTPREFIX << FORCESFILE;
|
---|
| 542 | if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
|
---|
| 543 | }
|
---|
| 544 |
|
---|
| 545 | /// prepare for OrthogonalSummation
|
---|
| 546 |
|
---|
| 547 | // convert KeySetContainer to IndexSetContainer
|
---|
| 548 | IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
|
---|
| 549 | // create the map of all keysets
|
---|
| 550 | SubsetMap::ptr subsetmap(new SubsetMap(*container));
|
---|
| 551 |
|
---|
| 552 | /// convert all MPQCData to MPQCDataMap_t
|
---|
| 553 | {
|
---|
| 554 | typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type MPQCDataEnergyVector_noeigenvalues_t;
|
---|
| 555 | std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
|
---|
| 556 | OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
|
---|
| 557 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
| 558 | std::vector<MPQCDataGridMap_t> Result_Grid_fused(
|
---|
| 559 | OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
|
---|
| 560 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
| 561 | std::vector<MPQCDataTimeMap_t> Result_Time_fused(
|
---|
| 562 | SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
|
---|
| 563 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
[06865e] | 564 | std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
|
---|
| 565 | OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
|
---|
| 566 | fragmentData, jobids, MatrixNrLookup, container, subsetmap));
|
---|
[358ddb] | 567 |
|
---|
| 568 | // force has extra converter
|
---|
| 569 | std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
|
---|
| 570 | convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
|
---|
| 571 | std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
|
---|
| 572 | AllLevelOrthogonalSummator<MPQCDataForceMap_t> forceSummer(
|
---|
| 573 | subsetmap,
|
---|
| 574 | MPQCData_Force_fused,
|
---|
| 575 | jobids,
|
---|
| 576 | container->getContainer(),
|
---|
| 577 | MatrixNrLookup,
|
---|
| 578 | Result_Force_fused);
|
---|
| 579 | boost::mpl::for_each<MPQCDataForceVector_t>(boost::ref(forceSummer));
|
---|
| 580 |
|
---|
| 581 | // obtain full grid
|
---|
| 582 | std::vector<VMGDataMap_t> VMGData_Potential_fused;
|
---|
[1f76f3] | 583 | convertDataTo<VMGData, VMGDataMap_t>(longrangeData, VMGData_Potential_fused);
|
---|
[358ddb] | 584 | OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::sampled_potential> potentialSummer(
|
---|
| 585 | subsetmap,
|
---|
| 586 | VMGData_Potential_fused,
|
---|
[06865e] | 587 | jobids,
|
---|
[358ddb] | 588 | container->getContainer(),
|
---|
[06865e] | 589 | MatrixNrLookup);
|
---|
[358ddb] | 590 | potentialSummer(subsetmap->getMaximumSubsetLevel());
|
---|
[c5feef] | 591 | OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_potential> epotentialSummer(
|
---|
| 592 | subsetmap,
|
---|
| 593 | VMGData_Potential_fused,
|
---|
| 594 | jobids,
|
---|
| 595 | container->getContainer(),
|
---|
| 596 | MatrixNrLookup);
|
---|
| 597 | epotentialSummer(subsetmap->getMaximumSubsetLevel());
|
---|
[1f76f3] | 598 | SamplingGrid full_sample = fullsolutionData.sampled_potential;
|
---|
[c5feef] | 599 | LOG(0, "Remaining long-range energy from energy_potential is " << full_sample.integral()-epotentialSummer.getFullContribution() << ".");
|
---|
[06865e] | 600 | full_sample -= potentialSummer.getFullContribution();
|
---|
[358ddb] | 601 | LOG(0, "Remaining long-range energy from potential integral is " << full_sample.integral() << ".");
|
---|
| 602 |
|
---|
[c5feef] | 603 |
|
---|
[358ddb] | 604 | OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_long> elongSummer(
|
---|
| 605 | subsetmap,
|
---|
| 606 | VMGData_Potential_fused,
|
---|
[06865e] | 607 | jobids,
|
---|
[358ddb] | 608 | container->getContainer(),
|
---|
[06865e] | 609 | MatrixNrLookup);
|
---|
[358ddb] | 610 | elongSummer(subsetmap->getMaximumSubsetLevel());
|
---|
[1f76f3] | 611 | double e_long = fullsolutionData.e_long;
|
---|
[06865e] | 612 | e_long -= elongSummer.getFullContribution();
|
---|
[358ddb] | 613 | LOG(0, "Remaining long-range energy is " << e_long << ".");
|
---|
| 614 |
|
---|
| 615 | // print tables (without eigenvalues, they go extra)
|
---|
| 616 | const size_t MaxLevel = subsetmap->getMaximumSubsetLevel();
|
---|
| 617 | const std::string energyresult =
|
---|
| 618 | writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
|
---|
| 619 | Result_Energy_fused, MaxLevel);
|
---|
| 620 | LOG(0, "Energy table is \n" << energyresult);
|
---|
| 621 | const std::string eigenvalueresult;
|
---|
| 622 |
|
---|
| 623 | LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
|
---|
| 624 | const std::string forceresult =
|
---|
| 625 | writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
|
---|
| 626 | Result_Force_fused, MaxLevel);
|
---|
| 627 | LOG(0, "Force table is \n" << forceresult);
|
---|
| 628 | // we don't want to print grid to a table
|
---|
| 629 | // print times (without flops for now)
|
---|
| 630 | typedef boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_flops>::type MPQCDataTimeVector_noflops_t;
|
---|
| 631 | const std::string timesresult =
|
---|
| 632 | writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
|
---|
| 633 | Result_Time_fused, MaxLevel);
|
---|
| 634 | LOG(0, "Times table is \n" << timesresult);
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | return true;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
[edecba] | 640 |
|
---|
[c5324f] | 641 | void RunService(
|
---|
| 642 | boost::asio::io_service &io_service,
|
---|
| 643 | std::string message)
|
---|
| 644 | {
|
---|
| 645 | message = std::string("io_service: ") + message;
|
---|
| 646 | io_service.reset();
|
---|
| 647 | Info info(message.c_str());
|
---|
| 648 | io_service.run();
|
---|
| 649 | }
|
---|
[edecba] | 650 |
|
---|
[c5324f] | 651 | void requestIds(
|
---|
| 652 | FragmentController &controller,
|
---|
| 653 | const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters ¶ms,
|
---|
| 654 | const size_t numberjobs)
|
---|
| 655 | {
|
---|
| 656 | controller.requestIds(params.host.get(), params.port.get(), numberjobs);
|
---|
| 657 | }
|
---|
| 658 |
|
---|
| 659 | bool createJobsFromFiles(
|
---|
| 660 | FragmentController &controller,
|
---|
| 661 | const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters ¶ms,
|
---|
| 662 | const std::vector< boost::filesystem::path > &jobfiles)
|
---|
| 663 | {
|
---|
| 664 | std::vector<FragmentJob::ptr> jobs;
|
---|
| 665 | for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
|
---|
| 666 | iter != jobfiles .end(); ++iter) {
|
---|
| 667 | const std::string &filename = (*iter).string();
|
---|
| 668 | if (boost::filesystem::exists(filename)) {
|
---|
| 669 | const JobId_t next_id = controller.getAvailableId();
|
---|
| 670 | LOG(1, "INFO: Creating MPQCCommandJob with filename'"
|
---|
| 671 | +filename+"', and id "+toString(next_id)+".");
|
---|
| 672 | parsejob(jobs, params.executable.get().string(), filename, next_id);
|
---|
| 673 | } else {
|
---|
| 674 | ELOG(1, "Fragment job "+filename+" does not exist.");
|
---|
| 675 | return false;
|
---|
[edecba] | 676 | }
|
---|
| 677 | }
|
---|
[c5324f] | 678 | controller.addJobs(jobs);
|
---|
| 679 | controller.sendJobs(params.host.get(), params.port.get());
|
---|
| 680 | return true;
|
---|
| 681 | }
|
---|
| 682 |
|
---|
[69c733] | 683 | #ifdef HAVE_VMG
|
---|
| 684 | bool createLongRangeJobs(
|
---|
| 685 | FragmentController &controller,
|
---|
| 686 | const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters ¶ms,
|
---|
[849cd8] | 687 | const std::vector<MPQCData> &fragmentData,
|
---|
[184943] | 688 | const SamplingGrid &full_sampled_grid,
|
---|
| 689 | const Fragment &full_fragment)
|
---|
[69c733] | 690 | {
|
---|
| 691 | std::vector<FragmentJob::ptr> jobs;
|
---|
[d12d621] | 692 | // add one job for each fragment as the short-range correction which we need
|
---|
| 693 | // to subtract from the obtained full potential to get the long-range part only
|
---|
| 694 | for (std::vector<MPQCData>::const_iterator iter = fragmentData.begin();
|
---|
| 695 | iter != fragmentData.end(); ++iter) {
|
---|
[69c733] | 696 | const JobId_t next_id = controller.getAvailableId();
|
---|
[4adef7] | 697 | LOG(1, "INFO: Creating VMGJob with " << iter->sampled_grid.sampled_grid.size()
|
---|
| 698 | << " gridpoints and " << iter->charges.size() << " particle charges.");
|
---|
[d12d621] | 699 | FragmentJob::ptr testJob(
|
---|
[cd77fc] | 700 | new VMGJob(next_id, iter->sampled_grid, iter->positions, iter->charges) );
|
---|
[69c733] | 701 | jobs.push_back(testJob);
|
---|
| 702 | }
|
---|
[d12d621] | 703 |
|
---|
| 704 | {
|
---|
[06865e] | 705 | const World::AtomComposite &atoms = World::getInstance().getAllAtoms();
|
---|
| 706 | std::vector< std::vector<double> > positions;
|
---|
| 707 | positions.reserve(atoms.size());
|
---|
| 708 | std::vector<double> charges;
|
---|
| 709 | charges.reserve(atoms.size());
|
---|
| 710 | std::vector<double> position(3, 0.);
|
---|
| 711 | for (World::AtomComposite::const_iterator iter = atoms.begin();
|
---|
| 712 | iter != atoms.end(); ++iter) {
|
---|
| 713 | const Vector &pos = (*iter)->getPosition();
|
---|
| 714 | for (size_t i=0;i<3;++i) position[i] = pos[i];
|
---|
| 715 | positions.push_back(position);
|
---|
| 716 | charges.push_back((double)((*iter)->getElement().getAtomicNumber()));
|
---|
| 717 | }
|
---|
[d12d621] | 718 | const JobId_t next_id = controller.getAvailableId();
|
---|
[849cd8] | 719 | LOG(1, "INFO: Creating full VMGJob with " << full_sampled_grid.sampled_grid.size()
|
---|
[4adef7] | 720 | << " gridpoints and " << charges.size() << " particle charges.");
|
---|
[d12d621] | 721 | FragmentJob::ptr testJob(
|
---|
[cd77fc] | 722 | new VMGJob(next_id, full_sampled_grid, positions, charges) );
|
---|
[d12d621] | 723 | jobs.push_back(testJob);
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 | // then send jobs to controller
|
---|
[69c733] | 727 | controller.addJobs(jobs);
|
---|
| 728 | controller.sendJobs(params.host.get(), params.port.get());
|
---|
| 729 | return true;
|
---|
| 730 | }
|
---|
| 731 | #endif
|
---|
| 732 |
|
---|
[c5324f] | 733 | void WaitforResults(
|
---|
| 734 | boost::asio::io_service &io_service,
|
---|
| 735 | FragmentController &controller,
|
---|
| 736 | const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters ¶ms,
|
---|
| 737 | const size_t NoExpectedResults
|
---|
| 738 | )
|
---|
| 739 | {
|
---|
[edecba] | 740 | size_t NoCalculatedResults = 0;
|
---|
[c5324f] | 741 | while (NoCalculatedResults != NoExpectedResults) {
|
---|
[edecba] | 742 | // wait a bit
|
---|
| 743 | boost::asio::deadline_timer timer(io_service);
|
---|
| 744 | timer.expires_from_now(boost::posix_time::milliseconds(500));
|
---|
| 745 | timer.wait();
|
---|
| 746 | // then request status
|
---|
[bd81f9] | 747 | controller.checkResults(params.host.get(), params.port.get());
|
---|
[c5324f] | 748 | RunService(io_service, "Checking on results");
|
---|
| 749 |
|
---|
[edecba] | 750 | const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
|
---|
| 751 | LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
|
---|
| 752 | NoCalculatedResults = JobStatus.second;
|
---|
| 753 | }
|
---|
[c5324f] | 754 | }
|
---|
| 755 |
|
---|
| 756 |
|
---|
| 757 | Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
|
---|
| 758 | boost::asio::io_service io_service;
|
---|
| 759 | FragmentController controller(io_service);
|
---|
| 760 |
|
---|
| 761 | // TODO: Have io_service run in second thread and merge with current again eventually
|
---|
| 762 |
|
---|
| 763 | // Phase One: obtain ids
|
---|
| 764 | std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
|
---|
| 765 | requestIds(controller, params, jobfiles.size());
|
---|
| 766 | RunService(io_service, "Requesting ids");
|
---|
| 767 |
|
---|
[69c733] | 768 | // Phase Two: create and add MPQCJobs
|
---|
[c5324f] | 769 | if (!createJobsFromFiles(controller, params, jobfiles))
|
---|
| 770 | return Action::failure;
|
---|
[69c733] | 771 | RunService(io_service, "Adding MPQCJobs");
|
---|
[c5324f] | 772 |
|
---|
| 773 | // Phase Three: calculate result
|
---|
| 774 | WaitforResults(io_service, controller, params, jobfiles.size());
|
---|
[bd81f9] | 775 | controller.receiveResults(params.host.get(), params.port.get());
|
---|
[69c733] | 776 | RunService(io_service, "Requesting short-range results");
|
---|
[2764e0] | 777 | std::vector<FragmentResult::ptr> MPQCresults = controller.getReceivedResults();
|
---|
| 778 | std::vector<MPQCData> fragmentData;
|
---|
[a0f8d3] | 779 | ConvertFragmentResultTo<MPQCData>(MPQCresults, fragmentData);
|
---|
[c5324f] | 780 |
|
---|
[69c733] | 781 | #ifdef HAVE_VMG
|
---|
| 782 | if (params.DoLongrange.get()) {
|
---|
[06865e] | 783 | ASSERT( World::getInstance().getAllAtoms().size() != 0,
|
---|
| 784 | "FragmentationFragmentationAutomationAction::performCall() - please load the full molecule into the World before.");
|
---|
| 785 |
|
---|
[995e2f] | 786 | // create a vector of all job ids
|
---|
| 787 | std::vector<JobId_t> jobids(MPQCresults.size(), JobId::IllegalJob);
|
---|
| 788 | std::transform(MPQCresults.begin(), MPQCresults.end(), jobids.begin(),
|
---|
| 789 | boost::bind(&FragmentResult::getId,
|
---|
| 790 | boost::bind(&FragmentResult::ptr::operator->, _1)));
|
---|
| 791 |
|
---|
[849cd8] | 792 | // obtain combined charge density
|
---|
| 793 | LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
|
---|
| 794 | SamplingGrid full_sample;
|
---|
[184943] | 795 | Fragment full_fragment;
|
---|
[849cd8] | 796 | sumUpChargeDensity(
|
---|
[995e2f] | 797 | jobids,
|
---|
[849cd8] | 798 | fragmentData,
|
---|
| 799 | params.path.get(),
|
---|
[184943] | 800 | full_sample,
|
---|
| 801 | full_fragment);
|
---|
[849cd8] | 802 |
|
---|
[69c733] | 803 | // Phase Four: obtain more ids
|
---|
[2764e0] | 804 | requestIds(controller, params, fragmentData.size()+1);
|
---|
[69c733] | 805 | RunService(io_service, "Requesting ids");
|
---|
| 806 |
|
---|
| 807 | // Phase Five: create VMGJobs
|
---|
[184943] | 808 | if (!createLongRangeJobs(controller, params, fragmentData, full_sample, full_fragment))
|
---|
[69c733] | 809 | return Action::failure;
|
---|
| 810 | RunService(io_service, "Adding VMGJobs");
|
---|
| 811 |
|
---|
| 812 | // Phase Six: calculate result
|
---|
[2764e0] | 813 | WaitforResults(io_service, controller, params, fragmentData.size()+1);
|
---|
[69c733] | 814 | controller.receiveResults(params.host.get(), params.port.get());
|
---|
| 815 | RunService(io_service, "Requesting long-range results");
|
---|
| 816 | std::vector<FragmentResult::ptr> VMGresults = controller.getReceivedResults();
|
---|
[2764e0] | 817 | ASSERT( MPQCresults.size()+1 == VMGresults.size(),
|
---|
| 818 | "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresultd and VMGresults don't match.");
|
---|
| 819 |
|
---|
[358ddb] | 820 | std::vector<VMGData> longrangeData;
|
---|
| 821 | ConvertFragmentResultTo<VMGData>(VMGresults, longrangeData);
|
---|
[1f76f3] | 822 | // remove full solution from vector, has to be treated extra
|
---|
| 823 | VMGData fullsolutionData = longrangeData.back();
|
---|
| 824 | longrangeData.pop_back();
|
---|
[358ddb] | 825 |
|
---|
[2764e0] | 826 | // Final phase: print result
|
---|
| 827 | {
|
---|
| 828 | LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
|
---|
[358ddb] | 829 | printReceivedFullResults(
|
---|
[2764e0] | 830 | MPQCresults,
|
---|
[358ddb] | 831 | VMGresults,
|
---|
[2764e0] | 832 | fragmentData,
|
---|
[358ddb] | 833 | longrangeData,
|
---|
[1f76f3] | 834 | fullsolutionData,
|
---|
[2764e0] | 835 | params.path.get(),
|
---|
[849cd8] | 836 | getNoAtomsFromAdjacencyFile(params.path.get()),
|
---|
| 837 | full_sample);
|
---|
[2764e0] | 838 | }
|
---|
[69c733] | 839 | }
|
---|
[358ddb] | 840 | #else
|
---|
| 841 | // Final phase: print result
|
---|
| 842 | {
|
---|
| 843 | LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
|
---|
| 844 | printReceivedMPQCResults(
|
---|
[995e2f] | 845 | jobids,
|
---|
[358ddb] | 846 | fragmentData,
|
---|
| 847 | params.path.get(),
|
---|
| 848 | getNoAtomsFromAdjacencyFile(params.path.get()),
|
---|
| 849 | full_sample);
|
---|
| 850 | }
|
---|
[69c733] | 851 | #endif
|
---|
[edecba] | 852 | size_t Exitflag = controller.getExitflag();
|
---|
| 853 |
|
---|
| 854 | return (Exitflag == 0) ? Action::success : Action::failure;
|
---|
| 855 | }
|
---|
| 856 |
|
---|
| 857 | Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
|
---|
| 858 | return Action::success;
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
|
---|
| 862 | return Action::success;
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | bool FragmentationFragmentationAutomationAction::canUndo() {
|
---|
| 866 | return false;
|
---|
| 867 | }
|
---|
| 868 |
|
---|
| 869 | bool FragmentationFragmentationAutomationAction::shouldUndo() {
|
---|
| 870 | return false;
|
---|
| 871 | }
|
---|
| 872 | /** =========== end of function ====================== */
|
---|