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

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

Split MPQCData::energy_electron_repulsion into _coulomb and _exchange.

  • we may obtain it this way from mpqc.
  • Property mode set to 100644
File size: 19.9 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/assign.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 "Fragmentation/EnergyMatrix.hpp"
51#include "Fragmentation/ForceMatrix.hpp"
52#include "Fragmentation/Fragmentation.hpp"
53#include "Fragmentation/Histogram/Histogram.hpp"
54#include "Fragmentation/HydrogenSaturation_enum.hpp"
55#include "Fragmentation/KeySet.hpp"
56#include "Fragmentation/KeySetsContainer.hpp"
57#include "Fragmentation/Summation/Summator.hpp"
58#include "Graph/DepthFirstSearchAnalysis.hpp"
59#include "Jobs/MPQCJob.hpp"
60#include "Jobs/MPQCData.hpp"
61#include "Jobs/MPQCData_printName.hpp"
62#include "molecule.hpp"
63#include "World.hpp"
64
65#include <iostream>
66#include <string>
67#include <vector>
68
69#include <boost/mpl/for_each.hpp>
70
71#include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
72
73using namespace MoleCuilder;
74
75using namespace boost::assign;
76
77// and construct the stuff
78#include "FragmentationAutomationAction.def"
79#include "Action_impl_pre.hpp"
80/** =========== define the function ====================== */
81
82class controller_AddOn;
83
84// needs to be defined for using the FragmentController
85controller_AddOn *getAddOn()
86{
87 return NULL;
88}
89
90/** Creates a MPQCCommandJob with argument \a filename.
91 *
92 * @param jobs created job is added to this vector
93 * @param command mpqc command to execute
94 * @param filename filename being argument to job
95 * @param nextid id for this job
96 */
97void parsejob(
98 std::vector<FragmentJob::ptr> &jobs,
99 const std::string &command,
100 const std::string &filename,
101 const JobId_t nextid)
102{
103 std::ifstream file;
104 file.open(filename.c_str());
105 ASSERT( file.good(), "parsejob() - file "+filename+" does not exist.");
106 std::string output((std::istreambuf_iterator<char>(file)),
107 std::istreambuf_iterator<char>());
108 FragmentJob::ptr testJob( new MPQCJob(nextid, output) );
109 jobs.push_back(testJob);
110 file.close();
111 LOG(1, "INFO: Added MPQCCommandJob from file "+filename+".");
112}
113
114/** Helper function to get number of atoms somehow.
115 *
116 * Here, we just parse the number of lines in the adjacency file as
117 * it should correspond to the number of atoms, except when some atoms
118 * are not bonded, but then fragmentation makes no sense.
119 *
120 * @param path path to the adjacency file
121 */
122size_t getNoAtomsFromAdjacencyFile(const std::string &path)
123{
124 size_t NoAtoms = 0;
125
126 // parse in special file to get atom count (from line count)
127 std::string filename(path);
128 filename += FRAGMENTPREFIX;
129 filename += ADJACENCYFILE;
130 std::ifstream adjacency(filename.c_str());
131 if (adjacency.fail()) {
132 LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");
133 return false;
134 }
135 std::string buffer;
136 while (getline(adjacency, buffer))
137 NoAtoms++;
138 LOG(1, "INFO: There are " << NoAtoms << " atoms.");
139
140 return NoAtoms;
141}
142
143
144template <typename MapType>
145struct printSum {
146 printSum(
147 SubsetMap::ptr &_subsetmap,
148 const std::vector<MapType> &_data,
149 const std::vector<JobId_t> &_jobids,
150 const IndexSetContainer::Container_t &_container,
151 std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
152 subsetmap(_subsetmap),
153 data(_data),
154 jobids(_jobids),
155 container(_container),
156 MatrixNrLookup(_MatrixNrLookup)
157 {}
158 template <typename MapKey>
159 void operator()(MapKey &) {
160 Summator<MapType, MapKey> sum_value(
161 subsetmap, data, jobids, container, MatrixNrLookup
162 );
163 double value = sum_value();
164 LOG(0, "STATUS: Resulting " << MPQCDataNames::printName<MapKey>() << " is " << value << ".");
165 }
166
167private:
168 //!> Hierarchy of IndexSet's
169 SubsetMap::ptr &subsetmap;
170 //!> vector of data converted from MPQCData
171 const std::vector<MapType> &data;
172 //!> vector of jobids
173 const std::vector<JobId_t> &jobids;
174 //!> container with all IndexSet's
175 const IndexSetContainer::Container_t &container;
176 //!> lookup map from job ids to ordering in above vectors
177 std::map< JobId_t, size_t > MatrixNrLookup;
178};
179
180/** Print MPQCData from received results.
181 *
182 * @param results received results to extract MPQCData from
183 * @param KeySetFilename filename with keysets to associate forces correctly
184 * @param NoAtoms total number of atoms
185 */
186bool printReceivedMPQCResults(
187 const std::vector<FragmentResult::ptr> &results,
188 const std::string &KeySetFilename,
189 size_t NoAtoms)
190{
191 EnergyMatrix Energy;
192 EnergyMatrix EnergyFragments;
193 ForceMatrix Force;
194 ForceMatrix ForceFragments;
195
196 // align fragments
197 std::map< JobId_t, size_t > MatrixNrLookup;
198 size_t FragmentCounter = 0;
199 {
200 // bring ids in order ...
201 typedef std::map< JobId_t, FragmentResult::ptr> IdResultMap_t;
202 IdResultMap_t IdResultMap;
203 for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
204 iter != results.end(); ++iter) {
205 #ifndef NDEBUG
206 std::pair< IdResultMap_t::iterator, bool> inserter =
207 #endif
208 IdResultMap.insert( make_pair((*iter)->getId(), *iter) );
209 ASSERT( inserter.second,
210 "printReceivedMPQCResults() - two results have same id "
211 +toString((*iter)->getId())+".");
212 }
213 // ... and fill lookup
214 for(IdResultMap_t::const_iterator iter = IdResultMap.begin();
215 iter != IdResultMap.end(); ++iter)
216 MatrixNrLookup.insert( make_pair(iter->first, FragmentCounter++) );
217 }
218 LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
219
220 // extract results
221 std::vector<MPQCData> fragmentData(results.size());
222 MPQCData combinedData;
223
224 LOG(2, "DEBUG: Parsing now through " << results.size() << " results.");
225 for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
226 iter != results.end(); ++iter) {
227 LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
228 MPQCData extractedData;
229 std::stringstream inputstream((*iter)->result);
230 LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50));
231 boost::archive::text_iarchive ia(inputstream);
232 ia >> extractedData;
233 LOG(1, "INFO: extracted data is " << extractedData << ".");
234
235 // place results into EnergyMatrix ...
236 {
237 MatrixContainer::MatrixArray matrix;
238 matrix.resize(1);
239 matrix[0].resize(1, extractedData.energies.total);
240 if (!Energy.AddMatrix(
241 std::string("MPQCJob ")+toString((*iter)->getId()),
242 matrix,
243 MatrixNrLookup[(*iter)->getId()])) {
244 ELOG(1, "Adding energy matrix failed.");
245 return false;
246 }
247 }
248 // ... and ForceMatrix (with two empty columns in front)
249 {
250 MatrixContainer::MatrixArray matrix;
251 const size_t rows = extractedData.forces.size();
252 matrix.resize(rows);
253 for (size_t i=0;i<rows;++i) {
254 const size_t columns = 2+extractedData.forces[i].size();
255 matrix[i].resize(columns, 0.);
256 // for (size_t j=0;j<2;++j)
257 // matrix[i][j] = 0.;
258 for (size_t j=2;j<columns;++j)
259 matrix[i][j] = extractedData.forces[i][j-2];
260 }
261 if (!Force.AddMatrix(
262 std::string("MPQCJob ")+toString((*iter)->getId()),
263 matrix,
264 MatrixNrLookup[(*iter)->getId()])) {
265 ELOG(1, "Adding force matrix failed.");
266 return false;
267 }
268 }
269 }
270 // add one more matrix (not required for energy)
271 MatrixContainer::MatrixArray matrix;
272 matrix.resize(1);
273 matrix[0].resize(1, 0.);
274 if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
275 return false;
276 // but for energy because we need to know total number of atoms
277 matrix.resize(NoAtoms);
278 for (size_t i = 0; i< NoAtoms; ++i)
279 matrix[i].resize(2+NDIM, 0.);
280 if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
281 return false;
282
283 // initialise indices
284 KeySetsContainer KeySet;
285 if (!Energy.InitialiseIndices()) return false;
286
287 if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
288
289 if (!KeySet.ParseKeySets(KeySetFilename.c_str(), Force.RowCounter, Force.MatrixCounter)) return false;
290
291 /// prepare for OrthogonalSummation
292
293 // gather all present indices in AllIndices
294 IndexSet::ptr AllIndices(new IndexSet);
295 for (KeySetsContainer::ArrayOfIntVectors::const_iterator iter = KeySet.KeySets.begin();
296 iter != KeySet.KeySets.end(); ++iter)
297 for(KeySetsContainer::IntVector::const_iterator keyiter = (*iter).begin();
298 keyiter != (*iter).end(); ++keyiter) {
299 if (*keyiter != -1)
300 (*AllIndices) += *keyiter;
301 }
302 LOG(1, "INFO: AllIndices is " << AllIndices << ".");
303 // create container with all keysets
304 IndexSetContainer::ptr container(new IndexSetContainer(AllIndices));
305 for (KeySetsContainer::ArrayOfIntVectors::const_iterator iter = KeySet.KeySets.begin();
306 iter != KeySet.KeySets.end(); ++iter) {
307 IndexSet tempset;
308 for(KeySetsContainer::IntVector::const_iterator keyiter = (*iter).begin();
309 keyiter != (*iter).end(); ++keyiter)
310 if (*keyiter != -1)
311 tempset += *keyiter;
312 container->insert(tempset);
313 }
314 // create the map of all keysets
315 SubsetMap::ptr subsetmap(new SubsetMap(*container));
316
317 {
318 /// convert all MPQCData to MPQCDataMap_t
319
320 // energy_t
321 std::vector<MPQCDataEnergyMap_t> MPQCData_Energy_fused;
322 MPQCData_Energy_fused.reserve(fragmentData.size());
323 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
324 dataiter != fragmentData.end(); ++dataiter) {
325 const MPQCData &extractedData = *dataiter;
326 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
327 MPQCDataEnergyMap_t instance;
328 boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
329 boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
330 boost::fusion::at_key<MPQCDataFused::energy_electron_coulomb>(instance) = extractedData.energies.electron_coulomb;
331 boost::fusion::at_key<MPQCDataFused::energy_electron_exchange>(instance) = extractedData.energies.electron_exchange;
332 boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
333 boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
334 boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
335 boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
336 // boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
337 MPQCData_Energy_fused.push_back(instance);
338 }
339
340 // forces
341 std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
342 MPQCData_Force_fused.reserve(fragmentData.size());
343 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
344 dataiter != fragmentData.end(); ++dataiter) {
345 const MPQCData &extractedData = *dataiter;
346 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
347 MPQCDataForceMap_t instance;
348 boost::fusion::at_key<MPQCDataFused::forces>(instance) = extractedData.forces;
349 MPQCData_Force_fused.push_back(instance);
350 }
351
352 // times
353 std::vector<MPQCDataTimeMap_t> MPQCData_Time_fused;
354 MPQCData_Time_fused.reserve(fragmentData.size());
355 for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
356 dataiter != fragmentData.end(); ++dataiter) {
357 const MPQCData &extractedData = *dataiter;
358 LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
359 MPQCDataTimeMap_t instance;
360 boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = extractedData.times.walltime;
361 boost::fusion::at_key<MPQCDataFused::times_cputime>(instance) = extractedData.times.cputime;
362 boost::fusion::at_key<MPQCDataFused::times_flops>(instance) = extractedData.times.flops;
363 MPQCData_Time_fused.push_back(instance);
364 }
365
366 // create a vector of all job ids
367 std::vector<JobId_t> jobids(results.size(), JobId::IllegalJob);
368 std::transform(results.begin(), results.end(), jobids.begin(),
369 boost::bind(&FragmentResult::getId,
370 boost::bind(&FragmentResult::ptr::operator->, _1)));
371
372 // sum up and print energies
373 boost::mpl::for_each<MPQCDataEnergyVector_t>(
374 printSum<MPQCDataEnergyMap_t>(
375 subsetmap,
376 MPQCData_Energy_fused,
377 jobids,
378 container->getContainer(),
379 MatrixNrLookup)
380 );
381 // TODO: Histogram still needs cstor taking just vector<double>
382
383
384 // TODO: We need to put forces into specific class and implement operators
385// // sum up and print forces
386// boost::mpl::for_each<MPQCDataForceVector_t>(
387// printSum<MPQCDataForceMap_t>(
388// subsetmap,
389// MPQCData_Force_fused,
390// jobids,
391// container->getContainer(),
392// MatrixNrLookup)
393// );
394
395 // TODO: Times should just be summed not orthogonalized
396// // sum up and print times
397// boost::mpl::for_each<MPQCDataTimeVector_t>(
398// printSum<MPQCDataTimeMap_t>(
399// subsetmap,
400// MPQCData_Time_fused,
401// jobids,
402// container->getContainer(),
403// MatrixNrLookup)
404// );
405 }
406
407 // combine all found data
408 if (!KeySet.ParseManyBodyTerms()) return false;
409
410 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
411 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
412
413 if(!Energy.SetLastMatrix(0., 0)) return false;
414 if(!Force.SetLastMatrix(0., 2)) return false;
415
416 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
417 // --------- sum up energy --------------------
418 LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
419 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
420 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
421
422 // --------- sum up Forces --------------------
423 LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
424 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
425 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
426 }
427
428 // for debugging print resulting energy and forces
429 LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
430 std::stringstream output;
431 for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
432 for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
433 output << Force.Matrix[ FragmentCounter ][i][j] << " ";
434 output << "\n";
435 }
436 LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
437
438 return true;
439}
440
441
442void RunService(
443 boost::asio::io_service &io_service,
444 std::string message)
445{
446 message = std::string("io_service: ") + message;
447 io_service.reset();
448 Info info(message.c_str());
449 io_service.run();
450}
451
452void requestIds(
453 FragmentController &controller,
454 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
455 const size_t numberjobs)
456{
457 controller.requestIds(params.host.get(), params.port.get(), numberjobs);
458}
459
460bool createJobsFromFiles(
461 FragmentController &controller,
462 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
463 const std::vector< boost::filesystem::path > &jobfiles)
464{
465 std::vector<FragmentJob::ptr> jobs;
466 for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
467 iter != jobfiles .end(); ++iter) {
468 const std::string &filename = (*iter).string();
469 if (boost::filesystem::exists(filename)) {
470 const JobId_t next_id = controller.getAvailableId();
471 LOG(1, "INFO: Creating MPQCCommandJob with filename'"
472 +filename+"', and id "+toString(next_id)+".");
473 parsejob(jobs, params.executable.get().string(), filename, next_id);
474 } else {
475 ELOG(1, "Fragment job "+filename+" does not exist.");
476 return false;
477 }
478 }
479 controller.addJobs(jobs);
480 controller.sendJobs(params.host.get(), params.port.get());
481 return true;
482}
483
484void WaitforResults(
485 boost::asio::io_service &io_service,
486 FragmentController &controller,
487 const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
488 const size_t NoExpectedResults
489 )
490{
491 size_t NoCalculatedResults = 0;
492 while (NoCalculatedResults != NoExpectedResults) {
493 // wait a bit
494 boost::asio::deadline_timer timer(io_service);
495 timer.expires_from_now(boost::posix_time::milliseconds(500));
496 timer.wait();
497 // then request status
498 controller.checkResults(params.host.get(), params.port.get());
499 RunService(io_service, "Checking on results");
500
501 const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
502 LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
503 NoCalculatedResults = JobStatus.second;
504 }
505}
506
507
508Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
509 boost::asio::io_service io_service;
510 FragmentController controller(io_service);
511
512 // TODO: Have io_service run in second thread and merge with current again eventually
513
514 // Phase One: obtain ids
515 std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
516 requestIds(controller, params, jobfiles.size());
517 RunService(io_service, "Requesting ids");
518
519 // Phase Two: create and add jobs
520 if (!createJobsFromFiles(controller, params, jobfiles))
521 return Action::failure;
522 RunService(io_service, "Adding jobs");
523
524 // Phase Three: calculate result
525 WaitforResults(io_service, controller, params, jobfiles.size());
526
527 // Phase Three: get result
528 controller.receiveResults(params.host.get(), params.port.get());
529 RunService(io_service, "Phase Four");
530
531 // Final phase: print result
532 {
533 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
534 std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
535 printReceivedMPQCResults(
536 results,
537 params.path.get(),
538 getNoAtomsFromAdjacencyFile(params.path.get()));
539 }
540 size_t Exitflag = controller.getExitflag();
541
542 return (Exitflag == 0) ? Action::success : Action::failure;
543}
544
545Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
546 return Action::success;
547}
548
549Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
550 return Action::success;
551}
552
553bool FragmentationFragmentationAutomationAction::canUndo() {
554 return false;
555}
556
557bool FragmentationFragmentationAutomationAction::shouldUndo() {
558 return false;
559}
560/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.