source: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp@ 2cc1cb

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 2cc1cb was c09f94, checked in by Frederik Heber <heber@…>, 11 years ago

Transformed FragmentationAutomationAction into a Process.

  • Removed MaxSteps parameter in Process' cstor (MaxSteps is not a const member anyway).
  • Action preprocessor magic knows new token BASECLASS by which derivation may be switche from Action to Process (defaults to Action).
  • FragmentationAutomationAction::performCall() uses start(), stop(), and setMaxSteps().
  • Property mode set to 100644
File size: 11.3 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 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * FragmentationAutomationAction.cpp
26 *
27 * Created on: May 18, 2012
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include <boost/archive/text_iarchive.hpp>
37// boost asio needs specific operator new
38#include <boost/asio.hpp>
39
40#include "CodePatterns/MemDebug.hpp"
41
42//// include headers that implement a archive in simple text format
43#include <boost/archive/text_oarchive.hpp>
44#include <boost/archive/text_iarchive.hpp>
45
46//
47//#include <boost/mpl/remove.hpp>
48//#include <boost/lambda/lambda.hpp>
49
50//#include <iostream>
51
52#include "CodePatterns/Assert.hpp"
53#include "CodePatterns/Info.hpp"
54#include "CodePatterns/Log.hpp"
55#include "JobMarket/Jobs/FragmentJob.hpp"
56
57#include "Fragmentation/Automation/FragmentJobQueue.hpp"
58#include "Fragmentation/Automation/MPQCFragmentController.hpp"
59#include "Fragmentation/Summation/Containers/FragmentationChargeDensity.hpp"
60#include "Fragmentation/Summation/Containers/FragmentationLongRangeResults.hpp"
61#include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
62#include "Fragmentation/Summation/Containers/FragmentationShortRangeResults.hpp"
63#include "Fragmentation/Summation/Containers/MPQCData.hpp"
64#include "Fragmentation/KeySetsContainer.hpp"
65#ifdef HAVE_VMG
66#include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp"
67#include "Fragmentation/Automation/VMGFragmentController.hpp"
68#include "Fragmentation/Summation/Containers/VMGData.hpp"
69#include "Fragmentation/Summation/Containers/VMGDataFused.hpp"
70#include "Fragmentation/Summation/Containers/VMGDataMap.hpp"
71#include "Fragmentation/Summation/Containers/VMGData_printKeyNames.hpp"
72#endif
73#include "World.hpp"
74
75#include <boost/bind.hpp>
76#include <boost/thread.hpp>
77#include <fstream>
78#include <iostream>
79#include <string>
80#include <vector>
81
82#include <boost/mpl/for_each.hpp>
83
84#include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
85
86using namespace MoleCuilder;
87
88// and construct the stuff
89#include "FragmentationAutomationAction.def"
90#include "Action_impl_pre.hpp"
91/** =========== define the function ====================== */
92
93class controller_AddOn;
94
95// needs to be defined for using the FragmentController
96controller_AddOn *getAddOn()
97{
98 return NULL;
99}
100
101static void updateSteps(Process &p, const size_t step, const size_t total)
102{
103 LOG(1, "There are " << step << " steps out of " << total << " done.");
104 p.setCurrStep(step);
105}
106
107ActionState::ptr FragmentationFragmentationAutomationAction::performCall() {
108 boost::asio::io_service io_service;
109
110 // TODO: Have io_service run in second thread and merge with current again eventually
111
112 FragmentationResultContainer &container =
113 FragmentationResultContainer::getInstance();
114 const KeySetsContainer& keysets = FragmentJobQueue::getInstance().getKeySets();
115 const KeySetsContainer& forcekeysets = FragmentJobQueue::getInstance().getFullKeySets();
116
117 size_t Exitflag = 0;
118 std::map<JobId_t, MPQCData> shortrangedata;
119 {
120 const size_t NumberJobs = FragmentJobQueue::getInstance().size();
121 MPQCFragmentController mpqccontroller(io_service);
122 mpqccontroller.setHost(params.host.get());
123 mpqccontroller.setPort(params.port.get());
124 // Phase One: obtain ids
125 mpqccontroller.requestIds(NumberJobs);
126
127 // Phase Two: add MPQCJobs and send
128 const size_t NoJobs = mpqccontroller.addJobsFromQueue(
129 params.DoLongrange.get() ? MPQCData::DoSampleDensity : MPQCData::DontSampleDensity,
130 params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly
131 );
132 LOG(1, "INFO: Added " << NoJobs << " from FragmentJobsQueue.");
133 mpqccontroller.run();
134
135 // Phase Three: calculate result
136 setMaxSteps(NumberJobs);
137 mpqccontroller.setUpdateHandler(
138 boost::bind(&updateSteps, boost::ref(*this), _1, _2)
139 );
140 start();
141 boost::thread wait_thread(
142 boost::bind(&MPQCFragmentController::waitforResults, boost::ref(mpqccontroller), boost::cref(NumberJobs))
143 );
144 wait_thread.join();
145 stop();
146 mpqccontroller.getResults(shortrangedata);
147
148 Exitflag += mpqccontroller.getExitflag();
149 }
150
151#ifdef HAVE_VMG
152 if (params.DoLongrange.get()) {
153 if ( World::getInstance().getAllAtoms().size() == 0) {
154 ELOG(1, "Please load the full molecule into the world before starting this action.");
155 return Action::failure;
156 }
157
158 // obtain combined charge density
159 FragmentationChargeDensity summedChargeDensity(
160 shortrangedata,
161 FragmentJobQueue::getInstance().getKeySets());
162 const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
163 LOG(1, "INFO: There are " << shortrangedata.size() << " short-range and "
164 << full_sample.size() << " level-wise long-range jobs.");
165
166 // check boundary conditions
167 const BoundaryConditions::Conditions_t &conditions =
168 World::getInstance().getDomain().getConditions();
169 const bool OpenBoundaryConditions =
170 !((conditions[0] == BoundaryConditions::Wrap) &&
171 (conditions[1] == BoundaryConditions::Wrap) &&
172 (conditions[2] == BoundaryConditions::Wrap));
173 LOG(1, std::string("INFO: Using ")
174 << (OpenBoundaryConditions ? "open" : "periodic")
175 << " boundary conditions.");
176
177 // Phase Four: obtain more ids
178 std::map<JobId_t, VMGData> longrangedata;
179 {
180 VMGFragmentController vmgcontroller(io_service);
181 vmgcontroller.setHost(params.host.get());
182 vmgcontroller.setPort(params.port.get());
183 const size_t NoJobs = shortrangedata.size()+full_sample.size();
184 vmgcontroller.requestIds(2*NoJobs);
185
186 // Phase Five a: create VMGJobs for electronic charge distribution
187 const size_t near_field_cells = params.near_field_cells.get();
188 const size_t interpolation_degree = params.interpolation_degree.get();
189 if (!vmgcontroller.createLongRangeJobs(
190 shortrangedata,
191 full_sample,
192 near_field_cells,
193 interpolation_degree,
194 VMGFragmentController::DontSampleParticles,
195 VMGFragmentController::DoTreatGrid,
196 params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly,
197 params.DoPrintDebug.get(),
198 OpenBoundaryConditions))
199 return Action::failure;
200
201 // Phase Six a: calculate result
202 vmgcontroller.waitforResults(NoJobs);
203 vmgcontroller.getResults(longrangedata);
204 ASSERT( NoJobs == longrangedata.size(),
205 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
206 +toString(full_sample.size())+"="+toString(NoJobs)
207 +" and first VMGresults "+toString(longrangedata.size())+" don't match.");
208 Exitflag += vmgcontroller.getExitflag();
209
210 {
211 std::map<JobId_t, VMGData> longrangedata_both;
212 // Phase Five b: create VMGJobs for nuclei charge distributions
213 const size_t near_field_cells = params.near_field_cells.get();
214 const size_t interpolation_degree = params.interpolation_degree.get();
215 if (!vmgcontroller.createLongRangeJobs(
216 shortrangedata,
217 full_sample,
218 near_field_cells,
219 interpolation_degree,
220 VMGFragmentController::DoSampleParticles,
221 VMGFragmentController::DoTreatGrid,
222 params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly,
223 params.DoPrintDebug.get(),
224 OpenBoundaryConditions))
225 return Action::failure;
226
227 // Phase Six b: calculate result
228 vmgcontroller.waitforResults(NoJobs);
229 vmgcontroller.getResults(longrangedata_both);
230 ASSERT( NoJobs == longrangedata_both.size(),
231 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
232 +toString(full_sample.size())+"="+toString(NoJobs)
233 +" and second VMGresults "+toString(longrangedata_both.size())+" don't match.");
234 Exitflag += vmgcontroller.getExitflag();
235
236 // go through either data and replace nuclei_long with contribution from both
237 ASSERT( longrangedata.size() == longrangedata_both.size(),
238 "FragmentationFragmentationAutomationAction::performCall() - longrange results have different sizes.");
239 std::map<JobId_t, VMGData>::iterator destiter = longrangedata.begin();
240 std::map<JobId_t, VMGData>::const_iterator srciter = longrangedata_both.begin();
241 for (;destiter != longrangedata.end(); ++srciter, ++destiter) {
242 destiter->second.both_sampled_potential = srciter->second.sampled_potential;
243 destiter->second.nuclei_long = srciter->second.nuclei_long;
244 }
245 }
246 }
247
248 if (params.DoPrintDebug.get()) {
249 std::map<JobId_t, std::string> debugData;
250 {
251 if (!full_sample.empty()) {
252 // create debug jobs for each level to print the summed-up potential to vtk files
253 VMGDebugGridFragmentController debugcontroller(io_service);
254 debugcontroller.setHost(params.host.get());
255 debugcontroller.setPort(params.port.get());
256 debugcontroller.requestIds(full_sample.size());
257 if (!debugcontroller.createDebugJobs(full_sample, OpenBoundaryConditions))
258 return Action::failure;
259 debugcontroller.waitforResults(full_sample.size());
260 debugcontroller.getResults(debugData);
261 Exitflag += debugcontroller.getExitflag();
262 }
263 }
264 }
265 container.addFullResults(keysets, forcekeysets, shortrangedata, longrangedata);
266 } else {
267 container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
268 }
269#else
270 container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
271#endif
272
273 // now clear all present jobs as we are done
274 FragmentJobQueue::getInstance().clear();
275
276 // if file is given, advise results container to store to file
277 if (!params.resultsfile.get().empty()) {
278 boost::filesystem::path resultsfile = params.resultsfile.get();
279 std::ofstream returnstream(resultsfile.string().c_str());
280 if (returnstream.good()) {
281 boost::archive::text_oarchive oa(returnstream);
282 oa << container;
283 }
284 Exitflag += (int)(!returnstream.good());
285 returnstream.close();
286 }
287
288 return (Exitflag == 0) ? Action::success : Action::failure;
289}
290
291ActionState::ptr FragmentationFragmentationAutomationAction::performUndo(ActionState::ptr _state) {
292 return Action::success;
293}
294
295ActionState::ptr FragmentationFragmentationAutomationAction::performRedo(ActionState::ptr _state){
296 return Action::success;
297}
298
299bool FragmentationFragmentationAutomationAction::canUndo() {
300 return false;
301}
302
303bool FragmentationFragmentationAutomationAction::shouldUndo() {
304 return false;
305}
306/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.