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

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

FIX: Forces-Factors are now written with global ids, HomologyContainer relies on it.

  • in FragmentationAutomationAction::performCall() we now use the ForceKeySets to create the HomologyGraph (which has global ids with hydrogens).
  • Property mode set to 100644
File size: 21.5 KB
RevLine 
[edecba]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[edecba]21 */
22
23/*
24 * FragmentationAutomationAction.cpp
25 *
26 * Created on: May 18, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <boost/archive/text_iarchive.hpp>
36// boost asio needs specific operator new
37#include <boost/asio.hpp>
38
39#include "CodePatterns/MemDebug.hpp"
40
[240c3e]41// include headers that implement a archive in simple text format
42#include <boost/archive/text_oarchive.hpp>
43#include <boost/archive/text_iarchive.hpp>
44
45
[fb881a]46#include <boost/mpl/remove.hpp>
[c9f9bb]47#include <boost/lambda/lambda.hpp>
[fb881a]48
[240c3e]49#include <iostream>
50
[6ca578]51#include "CodePatterns/Assert.hpp"
[edecba]52#include "CodePatterns/Info.hpp"
53#include "CodePatterns/Log.hpp"
54#include "JobMarket/Jobs/FragmentJob.hpp"
55
[184615]56#include "Fragmentation/Automation/createMatrixNrLookup.hpp"
[447481]57#include "Fragmentation/Automation/extractJobIds.hpp"
[27594e]58#include "Fragmentation/Automation/FragmentationChargeDensity.hpp"
[376a3b]59#include "Fragmentation/Automation/FragmentationResults.hpp"
[ffe057]60#include "Fragmentation/Automation/MPQCFragmentController.hpp"
[17c03f]61#include "Fragmentation/Automation/parseKeySetFile.hpp"
[238868]62#include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp"
[ffe057]63#include "Fragmentation/Automation/VMGFragmentController.hpp"
[edecba]64#include "Fragmentation/EnergyMatrix.hpp"
65#include "Fragmentation/ForceMatrix.hpp"
66#include "Fragmentation/Fragmentation.hpp"
[766767]67#include "Fragmentation/HydrogenSaturation_enum.hpp"
[240c3e]68#include "Fragmentation/Homology/HomologyContainer.hpp"
69#include "Fragmentation/Homology/HomologyGraph.hpp"
[766767]70#include "Fragmentation/KeySet.hpp"
71#include "Fragmentation/KeySetsContainer.hpp"
[184943]72#include "Fragmentation/SetValues/Fragment.hpp"
[e06820]73#include "Fragmentation/SetValues/Histogram.hpp"
[e13990b]74#include "Fragmentation/SetValues/IndexedVectors.hpp"
[766767]75#include "Fragmentation/Summation/IndexSetContainer.hpp"
[27afbf]76#include "Fragmentation/Summation/writeTable.hpp"
[edecba]77#include "Graph/DepthFirstSearchAnalysis.hpp"
[28e894]78#include "Jobs/MPQCJob.hpp"
[4bc75d]79#include "Jobs/MPQCData.hpp"
[1f66c7]80#include "Jobs/MPQCData_printKeyNames.hpp"
[69c733]81#ifdef HAVE_VMG
[238868]82#include "Jobs/VMGDebugGridJob.hpp"
[69c733]83#include "Jobs/VMGJob.hpp"
[358ddb]84#include "Jobs/VMGData.hpp"
85#include "Jobs/VMGDataFused.hpp"
86#include "Jobs/VMGDataMap.hpp"
87#include "Jobs/VMGData_printKeyNames.hpp"
[69c733]88#endif
[edecba]89#include "World.hpp"
90
[86cfac5]91#include <fstream>
[edecba]92#include <iostream>
93#include <string>
94#include <vector>
95
[8cae4c]96#include <boost/mpl/for_each.hpp>
97
[edecba]98#include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
99
100using namespace MoleCuilder;
101
102// and construct the stuff
103#include "FragmentationAutomationAction.def"
104#include "Action_impl_pre.hpp"
105/** =========== define the function ====================== */
106
107class controller_AddOn;
108
109// needs to be defined for using the FragmentController
110controller_AddOn *getAddOn()
111{
112 return NULL;
113}
114
115/** Helper function to get number of atoms somehow.
116 *
117 * Here, we just parse the number of lines in the adjacency file as
118 * it should correspond to the number of atoms, except when some atoms
119 * are not bonded, but then fragmentation makes no sense.
120 *
121 * @param path path to the adjacency file
122 */
123size_t getNoAtomsFromAdjacencyFile(const std::string &path)
124{
125 size_t NoAtoms = 0;
126
127 // parse in special file to get atom count (from line count)
128 std::string filename(path);
129 filename += FRAGMENTPREFIX;
130 filename += ADJACENCYFILE;
131 std::ifstream adjacency(filename.c_str());
132 if (adjacency.fail()) {
133 LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");
134 return false;
135 }
136 std::string buffer;
137 while (getline(adjacency, buffer))
138 NoAtoms++;
139 LOG(1, "INFO: There are " << NoAtoms << " atoms.");
140
141 return NoAtoms;
142}
143
144
145
[c4ee08]146/** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
147 *
148 * @param fragmentData MPQCData resulting from the jobs
149 * @param MatrixNrLookup Lookup up-map from job id to fragment number
150 * @param FragmentCounter total number of fragments
151 * @param NoAtoms total number of atoms
152 * @param Energy energy matrix to be filled on return
153 * @param Force force matrix to be filled on return
154 * @return true - everything ok, false - else
155 */
156bool putResultsintoMatrices(
[c9f9bb]157 const std::map<JobId_t, MPQCData> &fragmentData,
[3dd32f]158 const std::map< JobId_t, size_t > &MatrixNrLookup,
[c4ee08]159 const size_t FragmentCounter,
160 const size_t NoAtoms,
161 EnergyMatrix &Energy,
162 ForceMatrix &Force)
163{
[c9f9bb]164 for (std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
165 dataiter != fragmentData.end(); ++dataiter) {
166 const MPQCData &extractedData = dataiter->second;
167 const JobId_t &jobid = dataiter->first;
[3dd32f]168 std::map< JobId_t, size_t >::const_iterator nriter = MatrixNrLookup.find(jobid);
169 ASSERT( nriter != MatrixNrLookup.end(),
170 "putResultsintoMatrices() - MatrixNrLookup does not contain id "
171 +toString(jobid)+".");
[edecba]172 // place results into EnergyMatrix ...
173 {
174 MatrixContainer::MatrixArray matrix;
175 matrix.resize(1);
[a9558f]176 matrix[0].resize(1, extractedData.energies.total);
[edecba]177 if (!Energy.AddMatrix(
[c9f9bb]178 std::string("MPQCJob ")+toString(jobid),
[edecba]179 matrix,
[3dd32f]180 nriter->second)) {
[edecba]181 ELOG(1, "Adding energy matrix failed.");
182 return false;
183 }
184 }
185 // ... and ForceMatrix (with two empty columns in front)
186 {
187 MatrixContainer::MatrixArray matrix;
188 const size_t rows = extractedData.forces.size();
189 matrix.resize(rows);
190 for (size_t i=0;i<rows;++i) {
191 const size_t columns = 2+extractedData.forces[i].size();
192 matrix[i].resize(columns, 0.);
193 // for (size_t j=0;j<2;++j)
194 // matrix[i][j] = 0.;
195 for (size_t j=2;j<columns;++j)
196 matrix[i][j] = extractedData.forces[i][j-2];
197 }
198 if (!Force.AddMatrix(
[c9f9bb]199 std::string("MPQCJob ")+toString(jobid),
[edecba]200 matrix,
[3dd32f]201 nriter->second)) {
[edecba]202 ELOG(1, "Adding force matrix failed.");
203 return false;
204 }
205 }
206 }
207 // add one more matrix (not required for energy)
208 MatrixContainer::MatrixArray matrix;
209 matrix.resize(1);
210 matrix[0].resize(1, 0.);
211 if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
212 return false;
213 // but for energy because we need to know total number of atoms
214 matrix.resize(NoAtoms);
215 for (size_t i = 0; i< NoAtoms; ++i)
216 matrix[i].resize(2+NDIM, 0.);
217 if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
218 return false;
219
[c4ee08]220 return true;
221}
[849cd8]222
223/** Print MPQCData from received results.
224 *
[c9f9bb]225 * @param fragmentData MPQCData resulting from the jobs, associated to job id
[849cd8]226 * @param KeySetFilename filename with keysets to associate forces correctly
227 * @param NoAtoms total number of atoms
228 * @param full_sample summed up charge from fragments on return
[c4ee08]229 */
230bool printReceivedMPQCResults(
[c9f9bb]231 const std::map<JobId_t, MPQCData> &fragmentData,
[c4ee08]232 const std::string &KeySetFilename,
[c699f4]233 size_t NoAtoms)
[c4ee08]234{
[c9f9bb]235 // create a vector of all job ids
236 std::vector<JobId_t> jobids;
237 std::transform(fragmentData.begin(),fragmentData.end(),
238 std::back_inserter(jobids),
239 boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )
240 );
241
[c4ee08]242 // create lookup from job nr to fragment number
243 size_t FragmentCounter = 0;
[3dd32f]244 const std::map< JobId_t, size_t > MatrixNrLookup=
245 createMatrixNrLookup(jobids, FragmentCounter);
[c4ee08]246
247 // place results into maps
248 EnergyMatrix Energy;
249 ForceMatrix Force;
[c9f9bb]250 if (!putResultsintoMatrices(fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
[c4ee08]251 return false;
252
[edecba]253 if (!Energy.InitialiseIndices()) return false;
254
255 if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
256
[17c03f]257 // initialise keysets
258 KeySetsContainer KeySet;
259 parseKeySetFile(KeySet, KeySetFilename, FragmentCounter, NonHydrogenKeySets);
260 KeySetsContainer ForceKeySet;
261 parseKeySetFile(ForceKeySet, KeySetFilename, FragmentCounter, HydrogenKeySets);
[6ca578]262
263 // combine all found data
[edecba]264 if (!KeySet.ParseManyBodyTerms()) return false;
265
[c4ee08]266 EnergyMatrix EnergyFragments;
267 ForceMatrix ForceFragments;
[edecba]268 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
269 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
270
271 if(!Energy.SetLastMatrix(0., 0)) return false;
272 if(!Force.SetLastMatrix(0., 2)) return false;
273
274 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
275 // --------- sum up energy --------------------
276 LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
277 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
278 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
279
280 // --------- sum up Forces --------------------
281 LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
282 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
283 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
284 }
285
286 // for debugging print resulting energy and forces
287 LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
288 std::stringstream output;
289 for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
290 for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
291 output << Force.Matrix[ FragmentCounter ][i][j] << " ";
292 output << "\n";
293 }
294 LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
295
296 return true;
297}
298
[86cfac5]299void writeToFile(const std::string &filename, const std::string contents)
300{
301 std::ofstream tablefile(filename.c_str());
302 tablefile << contents;
303 tablefile.close();
304}
305
[358ddb]306/** Print MPQCData from received results.
307 *
[376a3b]308 * @param results summed up results container
[358ddb]309 */
[376a3b]310void printReceivedFullResults(
311 const FragmentationResults &results)
[358ddb]312{
[376a3b]313 // print tables (without eigenvalues, they go extra)
[86cfac5]314 {
315 typedef boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type
316 MPQCDataEnergyVector_noeigenvalues_t;
317 const std::string energyresult =
318 writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()(
319 results.Result_Energy_fused, results.getMaxLevel());
320 LOG(0, "Energy table is \n" << energyresult);
321 std::string filename;
322 filename += FRAGMENTPREFIX + std::string("_Energy.dat");
323 writeToFile(filename, energyresult);
324 }
325
[82cbe4]326 {
327 const std::string gridresult =
328 writeTable<VMGDataMap_t, VMGDataVector_t >()(
329 results.Result_LongRange_fused, results.getMaxLevel(), 2);
330 LOG(0, "VMG table is \n" << gridresult);
331 std::string filename;
332 filename += FRAGMENTPREFIX + std::string("_VMGEnergy.dat");
333 writeToFile(filename, gridresult);
334 }
335
[86cfac5]336 {
337 const std::string gridresult =
338 writeTable<VMGDataLongRangeMap_t, VMGDataLongRangeVector_t >()(
[d4f31f]339 results.Result_LongRangeIntegrated_fused, results.getMaxLevel(), 2);
[86cfac5]340 LOG(0, "LongRange table is \n" << gridresult);
341 std::string filename;
342 filename += FRAGMENTPREFIX + std::string("_LongRangeEnergy.dat");
343 writeToFile(filename, gridresult);
344 }
345
346 {
347 const std::string eigenvalueresult;
348 LOG(0, "Eigenvalue table is \n" << eigenvalueresult);
349 std::string filename;
350 filename += FRAGMENTPREFIX + std::string("_Eigenvalues.dat");
351 writeToFile(filename, eigenvalueresult);
352 }
353
354 {
355 const std::string forceresult =
356 writeTable<MPQCDataForceMap_t, MPQCDataForceVector_t>()(
357 results.Result_Force_fused, results.getMaxLevel());
358 LOG(0, "Force table is \n" << forceresult);
359 std::string filename;
360 filename += FRAGMENTPREFIX + std::string("_Forces.dat");
361 writeToFile(filename, forceresult);
362 }
[376a3b]363 // we don't want to print grid to a table
[86cfac5]364 {
365 // print times (without flops for now)
366 typedef boost::mpl::remove<
367 boost::mpl::remove<MPQCDataTimeVector_t, MPQCDataFused::times_total_flops>::type,
368 MPQCDataFused::times_gather_flops>::type
369 MPQCDataTimeVector_noflops_t;
370 const std::string timesresult =
371 writeTable<MPQCDataTimeMap_t, MPQCDataTimeVector_noflops_t >()(
372 results.Result_Time_fused, results.getMaxLevel());
373 LOG(0, "Times table is \n" << timesresult);
374 std::string filename;
375 filename += FRAGMENTPREFIX + std::string("_Times.dat");
376 writeToFile(filename, timesresult);
377 }
[358ddb]378}
379
[766767]380bool appendToHomologyFile(
381 const boost::filesystem::path &homology_file,
382 const FragmentationResults &results,
383 const std::string &KeySetFilename)
[240c3e]384{
385 // read homology container (if present)
386 HomologyContainer homology_container;
387 if (boost::filesystem::exists(homology_file)) {
388 std::ifstream returnstream(homology_file.string().c_str());
389 if (returnstream.good()) {
390 boost::archive::text_iarchive ia(returnstream);
391 ia >> homology_container;
392 } else {
393 ELOG(2, "Failed to parse from " << homology_file.string() << ".");
394 }
395 returnstream.close();
396 } else {
397 LOG(2, "Could not open " << homology_file.string()
398 << ", creating empty container.");
399 }
400
401 // append all fragments to a HomologyContainer
402 HomologyContainer::container_t values;
[17c03f]403 const size_t FragmentCounter = results.Result_perIndexSet_Energy.size();
404 KeySetsContainer KeySet;
405 parseKeySetFile(KeySet, KeySetFilename, FragmentCounter, NonHydrogenKeySets);
[766767]406 KeySetsContainer ForceKeySet;
[17c03f]407 parseKeySetFile(ForceKeySet, KeySetFilename, FragmentCounter, HydrogenKeySets);
408
[766767]409 // convert KeySetContainer to IndexSetContainer
[d1ba0d]410 IndexSetContainer::ptr Container(new IndexSetContainer(KeySet));
411 IndexSetContainer::ptr ForceContainer(new IndexSetContainer(ForceKeySet));
412 const IndexSetContainer::Container_t Indices = Container->getContainer();
413 const IndexSetContainer::Container_t ForceIndices = ForceContainer->getContainer();
414 IndexSetContainer::Container_t::const_iterator iter = Indices.begin();
415 IndexSetContainer::Container_t::const_iterator forceiter = ForceIndices.begin();
416 for (;iter != Indices.end(); ++iter, ++forceiter) // go through each IndexSet
[766767]417 {
[d1ba0d]418 // create graph from the force indices (i.e. with hydrogens)
419 HomologyGraph graph(**forceiter);
420 // obtain information for value of HomologyContainer entry with normal indices
[766767]421 const IndexSet::ptr &index = *iter;
422 HomologyContainer::value_t value;
423 std::map<IndexSet::ptr, MPQCDataFragmentMap_t>::const_iterator fragmentiter
424 = results.Result_perIndexSet_Fragment.find(index);
425 ASSERT( fragmentiter != results.Result_perIndexSet_Fragment.end(),
426 "appendToHomologyFile() - cannot find index "+toString(*index)
427 +" in FragmentResults.");
428 value.first = boost::fusion::at_key<MPQCDataFused::fragment>(fragmentiter->second);
429 std::map<IndexSet::ptr, MPQCDataEnergyMap_t>::const_iterator energyiter
430 = results.Result_perIndexSet_Energy.find(index);
431 ASSERT( energyiter != results.Result_perIndexSet_Energy.end(),
432 "appendToHomologyFile() - cannot find index "+toString(*index)
433 +" in FragmentResults.");
434 value.second = boost::fusion::at_key<MPQCDataFused::energy_total>(energyiter->second);
435 values.insert( std::make_pair( graph, value) );
436 }
[240c3e]437 homology_container.insert(values);
438
439 // store homology container again
440 std::ofstream outputstream(homology_file.string().c_str());
[b8f0b25]441 if (outputstream.good()) { // check if opened
[240c3e]442 boost::archive::text_oarchive oa(outputstream);
443 oa << homology_container;
444 if (outputstream.fail()) { // check if correctly written
445 LOG(1, "Failed to write to file " << homology_file.string() << ".");
446 return false;
447 } else
448 outputstream.close();
449 } else {
450 LOG(1, "Failed to open file " << homology_file.string()
451 << " for writing.");
452 return false;
453 }
454 return true;
455}
[edecba]456
[c5324f]457Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
458 boost::asio::io_service io_service;
459
460 // TODO: Have io_service run in second thread and merge with current again eventually
461
[4f056e]462 size_t Exitflag = 0;
[c9f9bb]463 std::map<JobId_t, MPQCData> fragmentData;
[4f056e]464 {
465 MPQCFragmentController mpqccontroller(io_service);
466 mpqccontroller.setHost(params.host.get());
467 mpqccontroller.setPort(params.port.get());
468 mpqccontroller.setLevel(params.level.get());
469 // Phase One: obtain ids
470 std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
471 mpqccontroller.requestIds(jobfiles.size());
472
473 // Phase Two: create and add MPQCJobs
474 if (!mpqccontroller.addJobsFromFiles(params.executable.get().string(), jobfiles))
475 return Action::failure;
476
477 // Phase Three: calculate result
478 mpqccontroller.waitforResults(jobfiles.size());
479 mpqccontroller.getResults(fragmentData);
480
481 Exitflag += mpqccontroller.getExitflag();
482 }
[c5324f]483
[69c733]484#ifdef HAVE_VMG
485 if (params.DoLongrange.get()) {
[db6f7d]486 if ( World::getInstance().getAllAtoms().size() == 0) {
487 ELOG(1, "Please load the full molecule into the world before starting this action.");
488 return Action::failure;
489 }
[06865e]490
[849cd8]491 // obtain combined charge density
[27594e]492 FragmentationChargeDensity summedChargeDensity(
[849cd8]493 fragmentData,
[27594e]494 params.path.get());
495 const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
[849cd8]496
[4f056e]497 LOG(1, "INFO: There are " << fragmentData.size() << " short-range and "
498 << full_sample.size() << " level-wise long-range jobs.");
[69c733]499
[4f056e]500 // Phase Four: obtain more ids
[c9f9bb]501 std::map<JobId_t, VMGData> longrangeData;
[4f056e]502 {
503 VMGFragmentController vmgcontroller(io_service);
504 vmgcontroller.setHost(params.host.get());
505 vmgcontroller.setPort(params.port.get());
506 const size_t NoJobs = fragmentData.size()+full_sample.size();
507 vmgcontroller.requestIds(NoJobs);
508
509 // Phase Five: create VMGJobs
510 const size_t near_field_cells = params.near_field_cells.get();
[cd2591]511 const size_t interpolation_degree = params.interpolation_degree.get();
[4f056e]512 if (!vmgcontroller.createLongRangeJobs(
513 fragmentData,
514 full_sample,
[cd2591]515 summedChargeDensity.getFragment(),
516 near_field_cells,
517 interpolation_degree))
[4f056e]518 return Action::failure;
519
520 // Phase Six: calculate result
521 vmgcontroller.waitforResults(NoJobs);
522 vmgcontroller.getResults(longrangeData);
523 ASSERT( NoJobs == longrangeData.size(),
524 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
525 +toString(full_sample.size())+"="+toString(NoJobs)
526 +" and VMGresults "+toString(longrangeData.size())+" don't match.");
527 Exitflag += vmgcontroller.getExitflag();
528 }
[a2295a]529
530 // remove full solution corresponding to full_sample from map (must be highest ids), has to be treated extra
531 std::map<JobId_t, VMGData>::iterator iter = longrangeData.end();
532 for (size_t i=0;i<full_sample.size();++i)
533 --iter;
534 std::map<JobId_t, VMGData>::iterator remove_iter = iter;
535 std::vector<VMGData> fullsolutionData;
536 for (; iter != longrangeData.end(); ++iter)
537 fullsolutionData.push_back(iter->second);
538 longrangeData.erase(remove_iter, longrangeData.end());
[358ddb]539
[376a3b]540 // Final phase: sum up and print result
[b8f0b25]541 FragmentationResults results(
542 fragmentData,
543 longrangeData,
544 fullsolutionData,
545 params.path.get(),
546 getNoAtomsFromAdjacencyFile(params.path.get()),
547 full_sample);
[238868]548
[b8f0b25]549 {
[376a3b]550 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
551 printReceivedFullResults(results);
[4f056e]552 }
[376a3b]553
[240c3e]554 // append all keysets to homology file
[b8f0b25]555 if (Exitflag == 0) {
[240c3e]556 const boost::filesystem::path &homology_file = params.homology_file.get();
[b8f0b25]557 if (homology_file.string() != "") {
558 LOG(1, "INFO: Appending HomologyGraphs to file " << homology_file.string() << ".");
[766767]559 if (!appendToHomologyFile(homology_file, results, params.path.get()))
[b8f0b25]560 Exitflag = 1;
561 }
[240c3e]562 }
563
[4f056e]564 std::map<JobId_t, std::string> debugData;
565 {
[a2295a]566 if (!full_sample.empty()) {
[376a3b]567 // create debug jobs for each level to print the summed-up potential to vtk files
[4f056e]568 VMGDebugGridFragmentController debugcontroller(io_service);
569 debugcontroller.setHost(params.host.get());
570 debugcontroller.setPort(params.port.get());
[a2295a]571 debugcontroller.requestIds(full_sample.size());
572 if (!debugcontroller.createDebugJobs(full_sample))
573 return Action::failure;
574 debugcontroller.waitforResults(full_sample.size());
575 debugcontroller.getResults(debugData);
[4f056e]576 Exitflag += debugcontroller.getExitflag();
[a2295a]577 }
[2764e0]578 }
[69c733]579 }
[358ddb]580#else
581 // Final phase: print result
582 {
583 LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
584 printReceivedMPQCResults(
585 fragmentData,
586 params.path.get(),
[c699f4]587 getNoAtomsFromAdjacencyFile(params.path.get()));
[358ddb]588 }
[69c733]589#endif
[edecba]590
591 return (Exitflag == 0) ? Action::success : Action::failure;
592}
593
594Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
595 return Action::success;
596}
597
598Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
599 return Action::success;
600}
601
602bool FragmentationFragmentationAutomationAction::canUndo() {
603 return false;
604}
605
606bool FragmentationFragmentationAutomationAction::shouldUndo() {
607 return false;
608}
609/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.