source: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp@ 1f76f3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 1f76f3 was 1f76f3, checked in by Frederik Heber <heber@…>, 12 years ago

Fullsolution in printReceivedFullResults() has to be given extra.

  • Property mode set to 100644
File size: 41.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
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/>.
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
41#include <boost/mpl/remove.hpp>
42
43#include "CodePatterns/Assert.hpp"
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"
50#include "Box.hpp"
51#include "Element/element.hpp"
52#include "Fragmentation/EnergyMatrix.hpp"
53#include "Fragmentation/ForceMatrix.hpp"
54#include "Fragmentation/Fragmentation.hpp"
55#include "Fragmentation/SetValues/Fragment.hpp"
56#include "Fragmentation/SetValues/Histogram.hpp"
57#include "Fragmentation/SetValues/IndexedVectors.hpp"
58#include "Fragmentation/HydrogenSaturation_enum.hpp"
59#include "Fragmentation/KeySet.hpp"
60#include "Fragmentation/KeySetsContainer.hpp"
61#include "Fragmentation/Summation/AllLevelOrthogonalSummator.hpp"
62#include "Fragmentation/Summation/AllLevelSummator.hpp"
63#include "Fragmentation/Summation/OrthogonalFullSummator.hpp"
64#include "Fragmentation/Summation/OrthogonalSummation.hpp"
65#include "Fragmentation/Summation/writeTable.hpp"
66#include "Graph/DepthFirstSearchAnalysis.hpp"
67#include "Helpers/defs.hpp"
68#include "Jobs/MPQCJob.hpp"
69#include "Jobs/MPQCData.hpp"
70#include "Jobs/MPQCData_printKeyNames.hpp"
71#include "Jobs/Grid/SamplingGrid.hpp"
72#include "LinearAlgebra/RealSpaceMatrix.hpp"
73#ifdef HAVE_VMG
74#include "Jobs/VMGJob.hpp"
75#include "Jobs/VMGData.hpp"
76#include "Jobs/VMGDataFused.hpp"
77#include "Jobs/VMGDataMap.hpp"
78#include "Jobs/VMGData_printKeyNames.hpp"
79#endif
80#include "molecule.hpp"
81#include "World.hpp"
82
83#include <iostream>
84#include <string>
85#include <vector>
86
87#include <boost/mpl/for_each.hpp>
88
89#include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
90
91using namespace MoleCuilder;
92
93// and construct the stuff
94#include "FragmentationAutomationAction.def"
95#include "Action_impl_pre.hpp"
96/** =========== define the function ====================== */
97
98class controller_AddOn;
99
100// needs to be defined for using the FragmentController
101controller_AddOn *getAddOn()
102{
103 return NULL;
104}
105
106const int LEVEL = 5;
107
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 */
115void 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>());
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) );
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 */
146size_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
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 */
172template <typename T>
173void ConvertFragmentResultTo(
174 const std::vector<FragmentResult::ptr> &results,
175 std::vector<T> &fragmentData)
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));
185 T extractedData;
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(),
195 "ConvertFragmentResultTo() - the number of extracted data differs from the number of results.");
196}
197
198/** Creates a lookup from FragmentJob::id to the true fragment number.
199 *
200 * @param results result with job ids
201 * @param MatrixNrLookup Lookup up-map, filled on return
202 * @param FragmentCounter total number of fragments on return
203 */
204void createMatrixNrLookup(
205 const std::vector<FragmentResult::ptr> &results,
206 std::map< JobId_t, size_t > &MatrixNrLookup,
207 size_t &FragmentCounter)
208{
209 // align fragments
210 MatrixNrLookup.clear();
211 FragmentCounter = 0;
212 {
213 // bring ids in order ...
214 typedef std::map< JobId_t, FragmentResult::ptr> IdResultMap_t;
215 IdResultMap_t IdResultMap;
216 for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
217 iter != results.end(); ++iter) {
218 #ifndef NDEBUG
219 std::pair< IdResultMap_t::iterator, bool> inserter =
220 #endif
221 IdResultMap.insert( make_pair((*iter)->getId(), *iter) );
222 ASSERT( inserter.second,
223 "ExtractMPQCDataFromResults() - two results have same id "
224 +toString((*iter)->getId())+".");
225 }
226 // ... and fill lookup
227 for(IdResultMap_t::const_iterator iter = IdResultMap.begin();
228 iter != IdResultMap.end(); ++iter)
229 MatrixNrLookup.insert( make_pair(iter->first, FragmentCounter++) );
230 }
231 LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
232}
233
234/** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
235 *
236 * @param results results with ids to associate with fragment number
237 * @param fragmentData MPQCData resulting from the jobs
238 * @param MatrixNrLookup Lookup up-map from job id to fragment number
239 * @param FragmentCounter total number of fragments
240 * @param NoAtoms total number of atoms
241 * @param Energy energy matrix to be filled on return
242 * @param Force force matrix to be filled on return
243 * @return true - everything ok, false - else
244 */
245bool putResultsintoMatrices(
246 const std::vector<FragmentResult::ptr> &results,
247 const std::vector<MPQCData> &fragmentData,
248 std::map< JobId_t, size_t > &MatrixNrLookup,
249 const size_t FragmentCounter,
250 const size_t NoAtoms,
251 EnergyMatrix &Energy,
252 ForceMatrix &Force)
253{
254 ASSERT( results.size() == fragmentData.size(),
255 "printReceivedMPQCResults() - results and fragmentData differ in size.");
256 std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
257 std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
258 for (; dataiter != fragmentData.end(); ++dataiter, ++resultiter) {
259 const MPQCData &extractedData = *dataiter;
260 // place results into EnergyMatrix ...
261 {
262 MatrixContainer::MatrixArray matrix;
263 matrix.resize(1);
264 matrix[0].resize(1, extractedData.energies.total);
265 if (!Energy.AddMatrix(
266 std::string("MPQCJob ")+toString((*resultiter)->getId()),
267 matrix,
268 MatrixNrLookup[(*resultiter)->getId()])) {
269 ELOG(1, "Adding energy matrix failed.");
270 return false;
271 }
272 }
273 // ... and ForceMatrix (with two empty columns in front)
274 {
275 MatrixContainer::MatrixArray matrix;
276 const size_t rows = extractedData.forces.size();
277 matrix.resize(rows);
278 for (size_t i=0;i<rows;++i) {
279 const size_t columns = 2+extractedData.forces[i].size();
280 matrix[i].resize(columns, 0.);
281 // for (size_t j=0;j<2;++j)
282 // matrix[i][j] = 0.;
283 for (size_t j=2;j<columns;++j)
284 matrix[i][j] = extractedData.forces[i][j-2];
285 }
286 if (!Force.AddMatrix(
287 std::string("MPQCJob ")+toString((*resultiter)->getId()),
288 matrix,
289 MatrixNrLookup[(*resultiter)->getId()])) {
290 ELOG(1, "Adding force matrix failed.");
291 return false;
292 }
293 }
294 }
295 // add one more matrix (not required for energy)
296 MatrixContainer::MatrixArray matrix;
297 matrix.resize(1);
298 matrix[0].resize(1, 0.);
299 if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
300 return false;
301 // but for energy because we need to know total number of atoms
302 matrix.resize(NoAtoms);
303 for (size_t i = 0; i< NoAtoms; ++i)
304 matrix[i].resize(2+NDIM, 0.);
305 if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
306 return false;
307
308 return true;
309}
310
311template <typename source, typename dest>
312void convertDataTo(
313 const std::vector<source> &fragmentData,
314 std::vector<dest> &MPQCData_fused)
315{
316 MPQCData_fused.clear();
317}
318
319template <>
320void convertDataTo<MPQCData, MPQCDataEnergyMap_t>(
321 const std::vector<MPQCData> &fragmentData,
322 std::vector<MPQCDataEnergyMap_t> &MPQCData_Energy_fused)
323{
324 // energy_t
325 MPQCData_Energy_fused.clear();
326 MPQCData_Energy_fused.reserve(fragmentData.size());
327 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
328 dataiter != fragmentData.end(); ++dataiter) {
329 const MPQCData &extractedData = *dataiter;
330 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
331 MPQCDataEnergyMap_t instance;
332 boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
333 boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
334 boost::fusion::at_key<MPQCDataFused::energy_electron_coulomb>(instance) = extractedData.energies.electron_coulomb;
335 boost::fusion::at_key<MPQCDataFused::energy_electron_exchange>(instance) = extractedData.energies.electron_exchange;
336 boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
337 boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
338 boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
339 boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
340 boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
341 MPQCData_Energy_fused.push_back(instance);
342 }
343}
344
345template <>
346void convertDataTo<VMGData, VMGDataMap_t>(
347 const std::vector<VMGData> &longrangeData,
348 std::vector<VMGDataMap_t> &VMGData_fused)
349{
350 // energy_t
351 VMGData_fused.clear();
352 VMGData_fused.reserve(longrangeData.size());
353 for(std::vector<VMGData>::const_iterator dataiter = longrangeData.begin();
354 dataiter != longrangeData.end(); ++dataiter) {
355 const VMGData &extractedData = *dataiter;
356 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
357 VMGDataMap_t instance;
358 boost::fusion::at_key<VMGDataFused::sampled_potential>(instance) = extractedData.sampled_potential;
359 boost::fusion::at_key<VMGDataFused::energy_potential>(instance) = extractedData.sampled_potential.integral();
360 boost::fusion::at_key<VMGDataFused::energy_long>(instance) = extractedData.e_long;
361 VMGData_fused.push_back(instance);
362 }
363}
364
365void convertMPQCDatatoForceMap(
366 const std::vector<MPQCData> &fragmentData,
367 const KeySetsContainer &ForceKeySet,
368 std::vector<MPQCDataForceMap_t> &MPQCData_Force_fused)
369{
370 // forces
371 ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
372 "FragmentationAutomationAction::performCall() - indices and fragmentData differ in size.");
373 MPQCData_Force_fused.clear();
374 MPQCData_Force_fused.reserve(fragmentData.size());
375 std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
376 KeySetsContainer::ArrayOfIntVectors::const_iterator arrayiter = ForceKeySet.KeySets.begin();
377 for(;dataiter != fragmentData.end(); ++dataiter, ++arrayiter) {
378 const MPQCData &extractedData = *dataiter;
379 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
380 MPQCDataForceMap_t instance;
381 // must convert int to index_t
382 IndexedVectors::indices_t indices(arrayiter->begin(), arrayiter->end());
383 boost::fusion::at_key<MPQCDataFused::forces>(instance) =
384 IndexedVectors(indices, extractedData.forces);
385 MPQCData_Force_fused.push_back(instance);
386 }
387}
388
389template <>
390void convertDataTo<MPQCData, MPQCDataGridMap_t>(
391 const std::vector<MPQCData> &fragmentData,
392 std::vector<MPQCDataGridMap_t> &MPQCData_Grid_fused)
393{
394 // sampled_grid
395 MPQCData_Grid_fused.clear();
396 MPQCData_Grid_fused.reserve(fragmentData.size());
397 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
398 dataiter != fragmentData.end(); ++dataiter) {
399 const MPQCData &extractedData = *dataiter;
400 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
401 MPQCDataGridMap_t instance;
402 boost::fusion::at_key<MPQCDataFused::sampled_grid>(instance) = extractedData.sampled_grid;
403 MPQCData_Grid_fused.push_back(instance);
404 }
405}
406
407template <>
408void convertDataTo<MPQCData, MPQCDataFragmentMap_t>(
409 const std::vector<MPQCData> &fragmentData,
410 std::vector<MPQCDataFragmentMap_t> &MPQCData_Fragment_fused)
411{
412 // fragment
413 MPQCData_Fragment_fused.clear();
414 MPQCData_Fragment_fused.reserve(fragmentData.size());
415 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
416 dataiter != fragmentData.end(); ++dataiter) {
417 const MPQCData &extractedData = *dataiter;
418 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
419 MPQCDataFragmentMap_t instance;
420 boost::fusion::at_key<MPQCDataFused::fragment>(instance) =
421 Fragment(extractedData.positions, extractedData.charges);
422 MPQCData_Fragment_fused.push_back(instance);
423 }
424}
425
426template <>
427void convertDataTo<MPQCData, MPQCDataTimeMap_t>(
428 const std::vector<MPQCData> &fragmentData,
429 std::vector<MPQCDataTimeMap_t> &MPQCData_Time_fused)
430{
431 // times
432 MPQCData_Time_fused.clear();
433 MPQCData_Time_fused.reserve(fragmentData.size());
434 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
435 dataiter != fragmentData.end(); ++dataiter) {
436 const MPQCData &extractedData = *dataiter;
437 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
438 MPQCDataTimeMap_t instance;
439 boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = extractedData.times.walltime;
440 boost::fusion::at_key<MPQCDataFused::times_cputime>(instance) = extractedData.times.cputime;
441 boost::fusion::at_key<MPQCDataFused::times_flops>(instance) = extractedData.times.flops;
442 MPQCData_Time_fused.push_back(instance);
443 }
444}
445
446template <typename TypeMap, typename TypeVector>
447std::vector<TypeMap> SumUpPerLevel(
448 const std::vector<MPQCData> &fragmentData,
449 const std::vector<JobId_t> &jobids,
450 std::map< JobId_t, size_t > &MatrixNrLookup,
451 const IndexSetContainer::ptr &container,
452 SubsetMap::ptr &subsetmap
453 )
454{
455 // place data into boost::fusion::map instance
456 std::vector<TypeMap> MPQCData_fused;
457 convertDataTo<MPQCData, TypeMap>(fragmentData, MPQCData_fused);
458 // instantiate summator
459 std::vector<TypeMap> Result_fused(subsetmap->getMaximumSubsetLevel());
460 AllLevelSummator<TypeMap> Summer(
461 subsetmap,
462 MPQCData_fused,
463 jobids,
464 container->getContainer(),
465 MatrixNrLookup,
466 Result_fused);
467 // sum up for each type key in TypeVector
468 boost::mpl::for_each<TypeVector>(boost::ref(Summer));
469 return Result_fused;
470}
471
472template <typename TypeMap, typename TypeVector>
473std::vector<TypeMap> OrthogonalSumUpPerLevel(
474 const std::vector<MPQCData> &fragmentData,
475 const std::vector<JobId_t> &jobids,
476 std::map< JobId_t, size_t > &MatrixNrLookup,
477 const IndexSetContainer::ptr &container,
478 SubsetMap::ptr &subsetmap
479 )
480{
481 // place data into boost::fusion::map instance
482 std::vector<TypeMap> MPQCData_fused;
483 convertDataTo<MPQCData, TypeMap>(fragmentData, MPQCData_fused);
484 // instantiate summator
485 std::vector<TypeMap> Result_fused(subsetmap->getMaximumSubsetLevel());
486 AllLevelOrthogonalSummator<TypeMap> Summer(
487 subsetmap,
488 MPQCData_fused,
489 jobids,
490 container->getContainer(),
491 MatrixNrLookup,
492 Result_fused);
493 // sum up for each type key in TypeVector
494 boost::mpl::for_each<TypeVector>(boost::ref(Summer));
495 return Result_fused;
496}
497
498/** Print MPQCData from received results.
499 *
500 * @param results results with ids to associate with fragment number
501 * @param fragmentData MPQCData resulting from the jobs
502 * @param KeySetFilename filename with keysets to associate forces correctly
503 * @param NoAtoms total number of atoms
504 * @param full_sample summed up charge density of electrons from fragments on return
505 * @param full_fragment summed up positions and charges of nuclei from fragments on return
506 */
507bool sumUpChargeDensity(
508 const std::vector<FragmentResult::ptr> &results,
509 const std::vector<MPQCData> &fragmentData,
510 const std::string &KeySetFilename,
511 SamplingGrid &full_sample,
512 Fragment &full_fragment)
513{
514 // create lookup from job nr to fragment number
515 std::map< JobId_t, size_t > MatrixNrLookup;
516 size_t FragmentCounter = 0;
517 createMatrixNrLookup(results, MatrixNrLookup, FragmentCounter);
518
519 // initialise keysets
520 KeySetsContainer KeySet;
521 {
522 // else needs keysets without hydrogens
523 std::stringstream filename;
524 filename << FRAGMENTPREFIX << KEYSETFILE;
525 if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
526 }
527
528 /// prepare for OrthogonalSummation
529
530 // convert KeySetContainer to IndexSetContainer
531 IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
532 // create the map of all keysets
533 SubsetMap::ptr subsetmap(new SubsetMap(*container));
534
535 // create a vector of all job ids
536 std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
537 std::transform(results.begin(), results.end(), jobids.begin(),
538 boost::bind(&FragmentResult::getId,
539 boost::bind(&FragmentResult::ptr::operator->, _1)));
540
541 /// convert all MPQCData to MPQCDataMap_t
542 std::vector<MPQCDataGridMap_t> Result_Grid_fused(
543 OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
544 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
545 std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
546 OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
547 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
548 // obtain full grid
549 full_sample = boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused.back());
550 full_fragment = boost::fusion::at_key<MPQCDataFused::fragment>(Result_Fragment_fused.back());
551
552 return true;
553}
554
555
556/** Print MPQCData from received results.
557 *
558 * @param results results with ids to associate with fragment number
559 * @param fragmentData MPQCData resulting from the jobs
560 * @param KeySetFilename filename with keysets to associate forces correctly
561 * @param NoAtoms total number of atoms
562 * @param full_sample summed up charge from fragments on return
563 */
564bool printReceivedMPQCResults(
565 const std::vector<FragmentResult::ptr> &results,
566 const std::vector<MPQCData> &fragmentData,
567 const std::string &KeySetFilename,
568 size_t NoAtoms,
569 SamplingGrid &full_sample)
570{
571 // create lookup from job nr to fragment number
572 std::map< JobId_t, size_t > MatrixNrLookup;
573 size_t FragmentCounter = 0;
574 createMatrixNrLookup(results, MatrixNrLookup, FragmentCounter);
575
576 // place results into maps
577 EnergyMatrix Energy;
578 ForceMatrix Force;
579 if (!putResultsintoMatrices(results, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
580 return false;
581
582 // initialise keysets
583 KeySetsContainer KeySet;
584 KeySetsContainer ForceKeySet;
585 if (!Energy.InitialiseIndices()) return false;
586
587 if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
588
589 {
590 // else needs keysets without hydrogens
591 std::stringstream filename;
592 filename << FRAGMENTPREFIX << KEYSETFILE;
593 if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
594 }
595
596 {
597 // forces need keysets including hydrogens
598 std::stringstream filename;
599 filename << FRAGMENTPREFIX << FORCESFILE;
600 if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
601 }
602
603 /// prepare for OrthogonalSummation
604
605 // convert KeySetContainer to IndexSetContainer
606 IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
607 // create the map of all keysets
608 SubsetMap::ptr subsetmap(new SubsetMap(*container));
609
610 // create a vector of all job ids
611 std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
612 std::transform(results.begin(), results.end(), jobids.begin(),
613 boost::bind(&FragmentResult::getId,
614 boost::bind(&FragmentResult::ptr::operator->, _1)));
615
616 /// convert all MPQCData to MPQCDataMap_t
617 {
618 ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
619 "FragmentationAutomationAction::performCall() - ForceKeySet's KeySets and fragmentData differ in size.");
620
621 typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type MPQCDataEnergyVector_noeigenvalues_t;
622 std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
623 OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
624 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
625 std::vector<MPQCDataGridMap_t> Result_Grid_fused(
626 OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
627 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
628 std::vector<MPQCDataTimeMap_t> Result_Time_fused(
629 SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
630 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
631
632 // force has extra converter
633 std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
634 convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
635 std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
636 AllLevelOrthogonalSummator<MPQCDataForceMap_t> forceSummer(
637 subsetmap,
638 MPQCData_Force_fused,
639 jobids,
640 container->getContainer(),
641 MatrixNrLookup,
642 Result_Force_fused);
643 boost::mpl::for_each<MPQCDataForceVector_t>(boost::ref(forceSummer));
644
645 // obtain full grid
646 full_sample = boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused.back());
647
648 // print tables (without eigenvalues, they go extra)
649 const size_t MaxLevel = subsetmap->getMaximumSubsetLevel();
650 const std::string energyresult =
651 writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
652 Result_Energy_fused, MaxLevel);
653 LOG(0, "Energy table is \n" << energyresult);
654 const std::string eigenvalueresult;
655
656 LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
657 const std::string forceresult =
658 writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
659 Result_Force_fused, MaxLevel);
660 LOG(0, "Force table is \n" << forceresult);
661 // we don't want to print grid to a table
662 // print times (without flops for now)
663 typedef boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_flops>::type MPQCDataTimeVector_noflops_t;
664 const std::string timesresult =
665 writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
666 Result_Time_fused, MaxLevel);
667 LOG(0, "Times table is \n" << timesresult);
668 }
669
670 // combine all found data
671 if (!KeySet.ParseManyBodyTerms()) return false;
672
673 EnergyMatrix EnergyFragments;
674 ForceMatrix ForceFragments;
675 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
676 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
677
678 if(!Energy.SetLastMatrix(0., 0)) return false;
679 if(!Force.SetLastMatrix(0., 2)) return false;
680
681 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
682 // --------- sum up energy --------------------
683 LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
684 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
685 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
686
687 // --------- sum up Forces --------------------
688 LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
689 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
690 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
691 }
692
693 // for debugging print resulting energy and forces
694 LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
695 std::stringstream output;
696 for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
697 for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
698 output << Force.Matrix[ FragmentCounter ][i][j] << " ";
699 output << "\n";
700 }
701 LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
702
703 return true;
704}
705
706/** Print MPQCData from received results.
707 *
708 * @param fragmentresults results with short-range job ids to associate with fragment number
709 * @param longrangeresults results with long-range job ids to associate with fragment number
710 * @param fragmentData MPQCData resulting from the jobs
711 * @param longrangeData VMGData resulting from long-range jobs
712 * @param fullsolutionData VMGData resulting from long-range of full problem
713 * @param KeySetFilename filename with keysets to associate forces correctly
714 * @param NoAtoms total number of atoms
715 * @param full_sample summed up charge from fragments on return
716 */
717bool printReceivedFullResults(
718 const std::vector<FragmentResult::ptr> &fragmentresults,
719 const std::vector<FragmentResult::ptr> &longrangeresults,
720 const std::vector<MPQCData> &fragmentData,
721 const std::vector<VMGData> &longrangeData,
722 const VMGData &fullsolutionData,
723 const std::string &KeySetFilename,
724 size_t NoAtoms,
725 SamplingGrid &full_sample)
726{
727 // create lookup from job nr to fragment number
728 std::map< JobId_t, size_t > MatrixNrLookup;
729 size_t FragmentCounter = 0;
730 createMatrixNrLookup(fragmentresults, MatrixNrLookup, FragmentCounter);
731
732 // initialise keysets
733 KeySetsContainer KeySet;
734 KeySetsContainer ForceKeySet;
735 {
736 // else needs keysets without hydrogens
737 std::stringstream filename;
738 filename << FRAGMENTPREFIX << KEYSETFILE;
739 if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
740 }
741
742 {
743 // forces need keysets including hydrogens
744 std::stringstream filename;
745 filename << FRAGMENTPREFIX << FORCESFILE;
746 if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
747 }
748
749 /// prepare for OrthogonalSummation
750
751 // convert KeySetContainer to IndexSetContainer
752 IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
753 // create the map of all keysets
754 SubsetMap::ptr subsetmap(new SubsetMap(*container));
755
756 // create a vector of all job ids from short-range
757 std::vector<JobId_t> jobids(fragmentresults.size(), JobId::IllegalJob);
758 std::transform(fragmentresults.begin(), fragmentresults.end(), jobids.begin(),
759 boost::bind(&FragmentResult::getId,
760 boost::bind(&FragmentResult::ptr::operator->, _1)));
761
762 /// convert all MPQCData to MPQCDataMap_t
763 {
764 typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type MPQCDataEnergyVector_noeigenvalues_t;
765 std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
766 OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
767 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
768 std::vector<MPQCDataGridMap_t> Result_Grid_fused(
769 OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
770 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
771 std::vector<MPQCDataTimeMap_t> Result_Time_fused(
772 SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
773 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
774 std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
775 OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
776 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
777
778 // force has extra converter
779 std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
780 convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
781 std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
782 AllLevelOrthogonalSummator<MPQCDataForceMap_t> forceSummer(
783 subsetmap,
784 MPQCData_Force_fused,
785 jobids,
786 container->getContainer(),
787 MatrixNrLookup,
788 Result_Force_fused);
789 boost::mpl::for_each<MPQCDataForceVector_t>(boost::ref(forceSummer));
790
791 // obtain full grid
792 std::vector<VMGDataMap_t> VMGData_Potential_fused;
793 convertDataTo<VMGData, VMGDataMap_t>(longrangeData, VMGData_Potential_fused);
794 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::sampled_potential> potentialSummer(
795 subsetmap,
796 VMGData_Potential_fused,
797 jobids,
798 container->getContainer(),
799 MatrixNrLookup);
800 potentialSummer(subsetmap->getMaximumSubsetLevel());
801 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_potential> epotentialSummer(
802 subsetmap,
803 VMGData_Potential_fused,
804 jobids,
805 container->getContainer(),
806 MatrixNrLookup);
807 epotentialSummer(subsetmap->getMaximumSubsetLevel());
808 SamplingGrid full_sample = fullsolutionData.sampled_potential;
809 LOG(0, "Remaining long-range energy from energy_potential is " << full_sample.integral()-epotentialSummer.getFullContribution() << ".");
810 full_sample -= potentialSummer.getFullContribution();
811 LOG(0, "Remaining long-range energy from potential integral is " << full_sample.integral() << ".");
812
813
814 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_long> elongSummer(
815 subsetmap,
816 VMGData_Potential_fused,
817 jobids,
818 container->getContainer(),
819 MatrixNrLookup);
820 elongSummer(subsetmap->getMaximumSubsetLevel());
821 double e_long = fullsolutionData.e_long;
822 e_long -= elongSummer.getFullContribution();
823 LOG(0, "Remaining long-range energy is " << e_long << ".");
824
825 // print tables (without eigenvalues, they go extra)
826 const size_t MaxLevel = subsetmap->getMaximumSubsetLevel();
827 const std::string energyresult =
828 writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
829 Result_Energy_fused, MaxLevel);
830 LOG(0, "Energy table is \n" << energyresult);
831 const std::string eigenvalueresult;
832
833 LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
834 const std::string forceresult =
835 writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
836 Result_Force_fused, MaxLevel);
837 LOG(0, "Force table is \n" << forceresult);
838 // we don't want to print grid to a table
839 // print times (without flops for now)
840 typedef boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_flops>::type MPQCDataTimeVector_noflops_t;
841 const std::string timesresult =
842 writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
843 Result_Time_fused, MaxLevel);
844 LOG(0, "Times table is \n" << timesresult);
845 }
846
847 return true;
848}
849
850
851void RunService(
852 boost::asio::io_service &io_service,
853 std::string message)
854{
855 message = std::string("io_service: ") + message;
856 io_service.reset();
857 Info info(message.c_str());
858 io_service.run();
859}
860
861void requestIds(
862 FragmentController &controller,
863 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
864 const size_t numberjobs)
865{
866 controller.requestIds(params.host.get(), params.port.get(), numberjobs);
867}
868
869bool createJobsFromFiles(
870 FragmentController &controller,
871 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
872 const std::vector< boost::filesystem::path > &jobfiles)
873{
874 std::vector<FragmentJob::ptr> jobs;
875 for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
876 iter != jobfiles .end(); ++iter) {
877 const std::string &filename = (*iter).string();
878 if (boost::filesystem::exists(filename)) {
879 const JobId_t next_id = controller.getAvailableId();
880 LOG(1, "INFO: Creating MPQCCommandJob with filename'"
881 +filename+"', and id "+toString(next_id)+".");
882 parsejob(jobs, params.executable.get().string(), filename, next_id);
883 } else {
884 ELOG(1, "Fragment job "+filename+" does not exist.");
885 return false;
886 }
887 }
888 controller.addJobs(jobs);
889 controller.sendJobs(params.host.get(), params.port.get());
890 return true;
891}
892
893#ifdef HAVE_VMG
894bool createLongRangeJobs(
895 FragmentController &controller,
896 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
897 const std::vector<MPQCData> &fragmentData,
898 const SamplingGrid &full_sampled_grid,
899 const Fragment &full_fragment)
900{
901 std::vector<FragmentJob::ptr> jobs;
902 // add one job for each fragment as the short-range correction which we need
903 // to subtract from the obtained full potential to get the long-range part only
904 for (std::vector<MPQCData>::const_iterator iter = fragmentData.begin();
905 iter != fragmentData.end(); ++iter) {
906 const JobId_t next_id = controller.getAvailableId();
907 LOG(1, "INFO: Creating VMGJob with " << iter->sampled_grid.sampled_grid.size()
908 << " gridpoints and " << iter->charges.size() << " particle charges.");
909 FragmentJob::ptr testJob(
910 new VMGJob(next_id, iter->sampled_grid, iter->positions, iter->charges) );
911 jobs.push_back(testJob);
912 }
913
914 {
915 const World::AtomComposite &atoms = World::getInstance().getAllAtoms();
916 std::vector< std::vector<double> > positions;
917 positions.reserve(atoms.size());
918 std::vector<double> charges;
919 charges.reserve(atoms.size());
920 std::vector<double> position(3, 0.);
921 for (World::AtomComposite::const_iterator iter = atoms.begin();
922 iter != atoms.end(); ++iter) {
923 const Vector &pos = (*iter)->getPosition();
924 for (size_t i=0;i<3;++i) position[i] = pos[i];
925 positions.push_back(position);
926 charges.push_back((double)((*iter)->getElement().getAtomicNumber()));
927 }
928 const JobId_t next_id = controller.getAvailableId();
929 LOG(1, "INFO: Creating full VMGJob with " << full_sampled_grid.sampled_grid.size()
930 << " gridpoints and " << charges.size() << " particle charges.");
931 FragmentJob::ptr testJob(
932 new VMGJob(next_id, full_sampled_grid, positions, charges) );
933 jobs.push_back(testJob);
934 }
935
936 // then send jobs to controller
937 controller.addJobs(jobs);
938 controller.sendJobs(params.host.get(), params.port.get());
939 return true;
940}
941#endif
942
943void WaitforResults(
944 boost::asio::io_service &io_service,
945 FragmentController &controller,
946 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
947 const size_t NoExpectedResults
948 )
949{
950 size_t NoCalculatedResults = 0;
951 while (NoCalculatedResults != NoExpectedResults) {
952 // wait a bit
953 boost::asio::deadline_timer timer(io_service);
954 timer.expires_from_now(boost::posix_time::milliseconds(500));
955 timer.wait();
956 // then request status
957 controller.checkResults(params.host.get(), params.port.get());
958 RunService(io_service, "Checking on results");
959
960 const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
961 LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
962 NoCalculatedResults = JobStatus.second;
963 }
964}
965
966
967Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
968 boost::asio::io_service io_service;
969 FragmentController controller(io_service);
970
971 // TODO: Have io_service run in second thread and merge with current again eventually
972
973 // Phase One: obtain ids
974 std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
975 requestIds(controller, params, jobfiles.size());
976 RunService(io_service, "Requesting ids");
977
978 // Phase Two: create and add MPQCJobs
979 if (!createJobsFromFiles(controller, params, jobfiles))
980 return Action::failure;
981 RunService(io_service, "Adding MPQCJobs");
982
983 // Phase Three: calculate result
984 WaitforResults(io_service, controller, params, jobfiles.size());
985 controller.receiveResults(params.host.get(), params.port.get());
986 RunService(io_service, "Requesting short-range results");
987 std::vector<FragmentResult::ptr> MPQCresults = controller.getReceivedResults();
988 std::vector<MPQCData> fragmentData;
989 ConvertFragmentResultTo<MPQCData>(MPQCresults, fragmentData);
990
991#ifdef HAVE_VMG
992 if (params.DoLongrange.get()) {
993 ASSERT( World::getInstance().getAllAtoms().size() != 0,
994 "FragmentationFragmentationAutomationAction::performCall() - please load the full molecule into the World before.");
995
996 // obtain combined charge density
997 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
998 SamplingGrid full_sample;
999 Fragment full_fragment;
1000 sumUpChargeDensity(
1001 MPQCresults,
1002 fragmentData,
1003 params.path.get(),
1004 full_sample,
1005 full_fragment);
1006
1007 // Phase Four: obtain more ids
1008 requestIds(controller, params, fragmentData.size()+1);
1009 RunService(io_service, "Requesting ids");
1010
1011 // Phase Five: create VMGJobs
1012 if (!createLongRangeJobs(controller, params, fragmentData, full_sample, full_fragment))
1013 return Action::failure;
1014 RunService(io_service, "Adding VMGJobs");
1015
1016 // Phase Six: calculate result
1017 WaitforResults(io_service, controller, params, fragmentData.size()+1);
1018 controller.receiveResults(params.host.get(), params.port.get());
1019 RunService(io_service, "Requesting long-range results");
1020 std::vector<FragmentResult::ptr> VMGresults = controller.getReceivedResults();
1021 ASSERT( MPQCresults.size()+1 == VMGresults.size(),
1022 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresultd and VMGresults don't match.");
1023
1024 std::vector<VMGData> longrangeData;
1025 ConvertFragmentResultTo<VMGData>(VMGresults, longrangeData);
1026 // remove full solution from vector, has to be treated extra
1027 VMGData fullsolutionData = longrangeData.back();
1028 longrangeData.pop_back();
1029
1030 // Final phase: print result
1031 {
1032 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
1033 printReceivedFullResults(
1034 MPQCresults,
1035 VMGresults,
1036 fragmentData,
1037 longrangeData,
1038 fullsolutionData,
1039 params.path.get(),
1040 getNoAtomsFromAdjacencyFile(params.path.get()),
1041 full_sample);
1042 }
1043 }
1044#else
1045 // Final phase: print result
1046 {
1047 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
1048 printReceivedMPQCResults(
1049 MPQCresults,
1050 fragmentData,
1051 params.path.get(),
1052 getNoAtomsFromAdjacencyFile(params.path.get()),
1053 full_sample);
1054 }
1055#endif
1056 size_t Exitflag = controller.getExitflag();
1057
1058 return (Exitflag == 0) ? Action::success : Action::failure;
1059}
1060
1061Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
1062 return Action::success;
1063}
1064
1065Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
1066 return Action::success;
1067}
1068
1069bool FragmentationFragmentationAutomationAction::canUndo() {
1070 return false;
1071}
1072
1073bool FragmentationFragmentationAutomationAction::shouldUndo() {
1074 return false;
1075}
1076/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.