source: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp@ 69c733

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 Candidate_v1.7.0 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 69c733 was 69c733, checked in by Frederik Heber <heber@…>, 13 years ago

Added second part to FragmentationAutomationAction that calculates long-range part.

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