source: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp@ c5feef

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 c5feef was c5feef, checked in by Frederik Heber <heber@…>, 12 years ago

Added energy_potential to fusion keys in VMGDataFused and summing up energy_potential.

  • Property mode set to 100644
File size: 41.1 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 KeySetFilename filename with keysets to associate forces correctly
713 * @param NoAtoms total number of atoms
714 * @param full_sample summed up charge from fragments on return
715 */
716bool printReceivedFullResults(
717 const std::vector<FragmentResult::ptr> &fragmentresults,
718 const std::vector<FragmentResult::ptr> &longrangeresults,
719 const std::vector<MPQCData> &fragmentData,
720 const std::vector<VMGData> &longrangeData,
721 const std::string &KeySetFilename,
722 size_t NoAtoms,
723 SamplingGrid &full_sample)
724{
725 // create lookup from job nr to fragment number
726 std::map< JobId_t, size_t > MatrixNrLookup;
727 size_t FragmentCounter = 0;
728 createMatrixNrLookup(fragmentresults, MatrixNrLookup, FragmentCounter);
729
730 // initialise keysets
731 KeySetsContainer KeySet;
732 KeySetsContainer ForceKeySet;
733 {
734 // else needs keysets without hydrogens
735 std::stringstream filename;
736 filename << FRAGMENTPREFIX << KEYSETFILE;
737 if (!KeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
738 }
739
740 {
741 // forces need keysets including hydrogens
742 std::stringstream filename;
743 filename << FRAGMENTPREFIX << FORCESFILE;
744 if (!ForceKeySet.ParseKeySets(KeySetFilename, filename.str(), FragmentCounter)) return false;
745 }
746
747 /// prepare for OrthogonalSummation
748
749 // convert KeySetContainer to IndexSetContainer
750 IndexSetContainer::ptr container(new IndexSetContainer(KeySet));
751 // create the map of all keysets
752 SubsetMap::ptr subsetmap(new SubsetMap(*container));
753
754 // create a vector of all job ids from short-range
755 std::vector<JobId_t> jobids(fragmentresults.size(), JobId::IllegalJob);
756 std::transform(fragmentresults.begin(), fragmentresults.end(), jobids.begin(),
757 boost::bind(&FragmentResult::getId,
758 boost::bind(&FragmentResult::ptr::operator->, _1)));
759
760 /// convert all MPQCData to MPQCDataMap_t
761 {
762 typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type MPQCDataEnergyVector_noeigenvalues_t;
763 std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
764 OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
765 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
766 std::vector<MPQCDataGridMap_t> Result_Grid_fused(
767 OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
768 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
769 std::vector<MPQCDataTimeMap_t> Result_Time_fused(
770 SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
771 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
772 std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
773 OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
774 fragmentData, jobids, MatrixNrLookup, container, subsetmap));
775
776 // force has extra converter
777 std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
778 convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
779 std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
780 AllLevelOrthogonalSummator<MPQCDataForceMap_t> forceSummer(
781 subsetmap,
782 MPQCData_Force_fused,
783 jobids,
784 container->getContainer(),
785 MatrixNrLookup,
786 Result_Force_fused);
787 boost::mpl::for_each<MPQCDataForceVector_t>(boost::ref(forceSummer));
788
789 // full solution has to treated extra and not used in summation
790 std::vector<VMGData> temp_longrangeData(longrangeData.begin(), --longrangeData.end());
791
792 // obtain full grid
793 std::vector<VMGDataMap_t> VMGData_Potential_fused;
794 convertDataTo<VMGData, VMGDataMap_t>(temp_longrangeData, VMGData_Potential_fused);
795 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::sampled_potential> potentialSummer(
796 subsetmap,
797 VMGData_Potential_fused,
798 jobids,
799 container->getContainer(),
800 MatrixNrLookup);
801 potentialSummer(subsetmap->getMaximumSubsetLevel());
802 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_potential> epotentialSummer(
803 subsetmap,
804 VMGData_Potential_fused,
805 jobids,
806 container->getContainer(),
807 MatrixNrLookup);
808 epotentialSummer(subsetmap->getMaximumSubsetLevel());
809 SamplingGrid full_sample = longrangeData.back().sampled_potential;
810 LOG(0, "Remaining long-range energy from energy_potential is " << full_sample.integral()-epotentialSummer.getFullContribution() << ".");
811 full_sample -= potentialSummer.getFullContribution();
812 LOG(0, "Remaining long-range energy from potential integral is " << full_sample.integral() << ".");
813
814
815 OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::energy_long> elongSummer(
816 subsetmap,
817 VMGData_Potential_fused,
818 jobids,
819 container->getContainer(),
820 MatrixNrLookup);
821 elongSummer(subsetmap->getMaximumSubsetLevel());
822 double e_long = longrangeData.back().e_long;
823 e_long -= elongSummer.getFullContribution();
824 LOG(0, "Remaining long-range energy is " << e_long << ".");
825
826 // print tables (without eigenvalues, they go extra)
827 const size_t MaxLevel = subsetmap->getMaximumSubsetLevel();
828 const std::string energyresult =
829 writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
830 Result_Energy_fused, MaxLevel);
831 LOG(0, "Energy table is \n" << energyresult);
832 const std::string eigenvalueresult;
833
834 LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
835 const std::string forceresult =
836 writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
837 Result_Force_fused, MaxLevel);
838 LOG(0, "Force table is \n" << forceresult);
839 // we don't want to print grid to a table
840 // print times (without flops for now)
841 typedef boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_flops>::type MPQCDataTimeVector_noflops_t;
842 const std::string timesresult =
843 writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
844 Result_Time_fused, MaxLevel);
845 LOG(0, "Times table is \n" << timesresult);
846 }
847
848 return true;
849}
850
851
852void RunService(
853 boost::asio::io_service &io_service,
854 std::string message)
855{
856 message = std::string("io_service: ") + message;
857 io_service.reset();
858 Info info(message.c_str());
859 io_service.run();
860}
861
862void requestIds(
863 FragmentController &controller,
864 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
865 const size_t numberjobs)
866{
867 controller.requestIds(params.host.get(), params.port.get(), numberjobs);
868}
869
870bool createJobsFromFiles(
871 FragmentController &controller,
872 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
873 const std::vector< boost::filesystem::path > &jobfiles)
874{
875 std::vector<FragmentJob::ptr> jobs;
876 for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
877 iter != jobfiles .end(); ++iter) {
878 const std::string &filename = (*iter).string();
879 if (boost::filesystem::exists(filename)) {
880 const JobId_t next_id = controller.getAvailableId();
881 LOG(1, "INFO: Creating MPQCCommandJob with filename'"
882 +filename+"', and id "+toString(next_id)+".");
883 parsejob(jobs, params.executable.get().string(), filename, next_id);
884 } else {
885 ELOG(1, "Fragment job "+filename+" does not exist.");
886 return false;
887 }
888 }
889 controller.addJobs(jobs);
890 controller.sendJobs(params.host.get(), params.port.get());
891 return true;
892}
893
894#ifdef HAVE_VMG
895bool createLongRangeJobs(
896 FragmentController &controller,
897 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
898 const std::vector<MPQCData> &fragmentData,
899 const SamplingGrid &full_sampled_grid,
900 const Fragment &full_fragment)
901{
902 std::vector<FragmentJob::ptr> jobs;
903 // add one job for each fragment as the short-range correction which we need
904 // to subtract from the obtained full potential to get the long-range part only
905 for (std::vector<MPQCData>::const_iterator iter = fragmentData.begin();
906 iter != fragmentData.end(); ++iter) {
907 const JobId_t next_id = controller.getAvailableId();
908 LOG(1, "INFO: Creating VMGJob with " << iter->sampled_grid.sampled_grid.size()
909 << " gridpoints and " << iter->charges.size() << " particle charges.");
910 FragmentJob::ptr testJob(
911 new VMGJob(next_id, iter->sampled_grid, iter->positions, iter->charges) );
912 jobs.push_back(testJob);
913 }
914
915 {
916 const World::AtomComposite &atoms = World::getInstance().getAllAtoms();
917 std::vector< std::vector<double> > positions;
918 positions.reserve(atoms.size());
919 std::vector<double> charges;
920 charges.reserve(atoms.size());
921 std::vector<double> position(3, 0.);
922 for (World::AtomComposite::const_iterator iter = atoms.begin();
923 iter != atoms.end(); ++iter) {
924 const Vector &pos = (*iter)->getPosition();
925 for (size_t i=0;i<3;++i) position[i] = pos[i];
926 positions.push_back(position);
927 charges.push_back((double)((*iter)->getElement().getAtomicNumber()));
928 }
929 const JobId_t next_id = controller.getAvailableId();
930 LOG(1, "INFO: Creating full VMGJob with " << full_sampled_grid.sampled_grid.size()
931 << " gridpoints and " << charges.size() << " particle charges.");
932 FragmentJob::ptr testJob(
933 new VMGJob(next_id, full_sampled_grid, positions, charges) );
934 jobs.push_back(testJob);
935 }
936
937 // then send jobs to controller
938 controller.addJobs(jobs);
939 controller.sendJobs(params.host.get(), params.port.get());
940 return true;
941}
942#endif
943
944void WaitforResults(
945 boost::asio::io_service &io_service,
946 FragmentController &controller,
947 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
948 const size_t NoExpectedResults
949 )
950{
951 size_t NoCalculatedResults = 0;
952 while (NoCalculatedResults != NoExpectedResults) {
953 // wait a bit
954 boost::asio::deadline_timer timer(io_service);
955 timer.expires_from_now(boost::posix_time::milliseconds(500));
956 timer.wait();
957 // then request status
958 controller.checkResults(params.host.get(), params.port.get());
959 RunService(io_service, "Checking on results");
960
961 const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
962 LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
963 NoCalculatedResults = JobStatus.second;
964 }
965}
966
967
968Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
969 boost::asio::io_service io_service;
970 FragmentController controller(io_service);
971
972 // TODO: Have io_service run in second thread and merge with current again eventually
973
974 // Phase One: obtain ids
975 std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
976 requestIds(controller, params, jobfiles.size());
977 RunService(io_service, "Requesting ids");
978
979 // Phase Two: create and add MPQCJobs
980 if (!createJobsFromFiles(controller, params, jobfiles))
981 return Action::failure;
982 RunService(io_service, "Adding MPQCJobs");
983
984 // Phase Three: calculate result
985 WaitforResults(io_service, controller, params, jobfiles.size());
986 controller.receiveResults(params.host.get(), params.port.get());
987 RunService(io_service, "Requesting short-range results");
988 std::vector<FragmentResult::ptr> MPQCresults = controller.getReceivedResults();
989 std::vector<MPQCData> fragmentData;
990 ConvertFragmentResultTo<MPQCData>(MPQCresults, fragmentData);
991
992#ifdef HAVE_VMG
993 if (params.DoLongrange.get()) {
994 ASSERT( World::getInstance().getAllAtoms().size() != 0,
995 "FragmentationFragmentationAutomationAction::performCall() - please load the full molecule into the World before.");
996
997 // obtain combined charge density
998 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
999 SamplingGrid full_sample;
1000 Fragment full_fragment;
1001 sumUpChargeDensity(
1002 MPQCresults,
1003 fragmentData,
1004 params.path.get(),
1005 full_sample,
1006 full_fragment);
1007
1008 // Phase Four: obtain more ids
1009 requestIds(controller, params, fragmentData.size()+1);
1010 RunService(io_service, "Requesting ids");
1011
1012 // Phase Five: create VMGJobs
1013 if (!createLongRangeJobs(controller, params, fragmentData, full_sample, full_fragment))
1014 return Action::failure;
1015 RunService(io_service, "Adding VMGJobs");
1016
1017 // Phase Six: calculate result
1018 WaitforResults(io_service, controller, params, fragmentData.size()+1);
1019 controller.receiveResults(params.host.get(), params.port.get());
1020 RunService(io_service, "Requesting long-range results");
1021 std::vector<FragmentResult::ptr> VMGresults = controller.getReceivedResults();
1022 ASSERT( MPQCresults.size()+1 == VMGresults.size(),
1023 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresultd and VMGresults don't match.");
1024
1025 std::vector<VMGData> longrangeData;
1026 ConvertFragmentResultTo<VMGData>(VMGresults, longrangeData);
1027
1028 // Final phase: print result
1029 {
1030 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
1031 printReceivedFullResults(
1032 MPQCresults,
1033 VMGresults,
1034 fragmentData,
1035 longrangeData,
1036 params.path.get(),
1037 getNoAtomsFromAdjacencyFile(params.path.get()),
1038 full_sample);
1039 }
1040 }
1041#else
1042 // Final phase: print result
1043 {
1044 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
1045 printReceivedMPQCResults(
1046 MPQCresults,
1047 fragmentData,
1048 params.path.get(),
1049 getNoAtomsFromAdjacencyFile(params.path.get()),
1050 full_sample);
1051 }
1052#endif
1053 size_t Exitflag = controller.getExitflag();
1054
1055 return (Exitflag == 0) ? Action::success : Action::failure;
1056}
1057
1058Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
1059 return Action::success;
1060}
1061
1062Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
1063 return Action::success;
1064}
1065
1066bool FragmentationFragmentationAutomationAction::canUndo() {
1067 return false;
1068}
1069
1070bool FragmentationFragmentationAutomationAction::shouldUndo() {
1071 return false;
1072}
1073/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.