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 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 | //
|
---|
46 | //#include <boost/mpl/remove.hpp>
|
---|
47 | //#include <boost/lambda/lambda.hpp>
|
---|
48 |
|
---|
49 | //#include <iostream>
|
---|
50 |
|
---|
51 | #include "CodePatterns/Assert.hpp"
|
---|
52 | #include "CodePatterns/Info.hpp"
|
---|
53 | #include "CodePatterns/Log.hpp"
|
---|
54 | #include "JobMarket/Jobs/FragmentJob.hpp"
|
---|
55 |
|
---|
56 | #include "Fragmentation/Automation/FragmentJobQueue.hpp"
|
---|
57 | #include "Fragmentation/Automation/MPQCFragmentController.hpp"
|
---|
58 | #include "Fragmentation/Summation/Containers/FragmentationChargeDensity.hpp"
|
---|
59 | #include "Fragmentation/Summation/Containers/FragmentationLongRangeResults.hpp"
|
---|
60 | #include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
|
---|
61 | #include "Fragmentation/Summation/Containers/FragmentationShortRangeResults.hpp"
|
---|
62 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
|
---|
63 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
64 | #ifdef HAVE_VMG
|
---|
65 | #include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp"
|
---|
66 | #include "Fragmentation/Automation/VMGFragmentController.hpp"
|
---|
67 | #include "Fragmentation/Summation/Containers/VMGData.hpp"
|
---|
68 | #include "Fragmentation/Summation/Containers/VMGDataFused.hpp"
|
---|
69 | #include "Fragmentation/Summation/Containers/VMGDataMap.hpp"
|
---|
70 | #include "Fragmentation/Summation/Containers/VMGData_printKeyNames.hpp"
|
---|
71 | #endif
|
---|
72 | #include "World.hpp"
|
---|
73 |
|
---|
74 | #include <fstream>
|
---|
75 | #include <iostream>
|
---|
76 | #include <string>
|
---|
77 | #include <vector>
|
---|
78 |
|
---|
79 | #include <boost/mpl/for_each.hpp>
|
---|
80 |
|
---|
81 | #include "Actions/FragmentationAction/FragmentationAutomationAction.hpp"
|
---|
82 |
|
---|
83 | using namespace MoleCuilder;
|
---|
84 |
|
---|
85 | // and construct the stuff
|
---|
86 | #include "FragmentationAutomationAction.def"
|
---|
87 | #include "Action_impl_pre.hpp"
|
---|
88 | /** =========== define the function ====================== */
|
---|
89 |
|
---|
90 | class controller_AddOn;
|
---|
91 |
|
---|
92 | // needs to be defined for using the FragmentController
|
---|
93 | controller_AddOn *getAddOn()
|
---|
94 | {
|
---|
95 | return NULL;
|
---|
96 | }
|
---|
97 |
|
---|
98 | Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
|
---|
99 | boost::asio::io_service io_service;
|
---|
100 |
|
---|
101 | // TODO: Have io_service run in second thread and merge with current again eventually
|
---|
102 |
|
---|
103 | FragmentationResultContainer &container =
|
---|
104 | FragmentationResultContainer::getInstance();
|
---|
105 | const KeySetsContainer& keysets = FragmentJobQueue::getInstance().getKeySets();
|
---|
106 | const KeySetsContainer& forcekeysets = FragmentJobQueue::getInstance().getFullKeySets();
|
---|
107 |
|
---|
108 | size_t Exitflag = 0;
|
---|
109 | std::map<JobId_t, MPQCData> shortrangedata;
|
---|
110 | {
|
---|
111 | const size_t NumberJobs = FragmentJobQueue::getInstance().size();
|
---|
112 | MPQCFragmentController mpqccontroller(io_service);
|
---|
113 | mpqccontroller.setHost(params.host.get());
|
---|
114 | mpqccontroller.setPort(params.port.get());
|
---|
115 | // Phase One: obtain ids
|
---|
116 | mpqccontroller.requestIds(NumberJobs);
|
---|
117 |
|
---|
118 | // Phase Two: add MPQCJobs and send
|
---|
119 | const size_t NoJobs = mpqccontroller.addJobsFromQueue(
|
---|
120 | params.DoLongrange.get() ? MPQCData::DoSampleDensity : MPQCData::DontSampleDensity,
|
---|
121 | params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly
|
---|
122 | );
|
---|
123 | LOG(1, "INFO: Added " << NoJobs << " from FragmentJobsQueue.");
|
---|
124 | mpqccontroller.run();
|
---|
125 |
|
---|
126 | // Phase Three: calculate result
|
---|
127 | mpqccontroller.waitforResults(NumberJobs);
|
---|
128 | mpqccontroller.getResults(shortrangedata);
|
---|
129 |
|
---|
130 | Exitflag += mpqccontroller.getExitflag();
|
---|
131 | }
|
---|
132 |
|
---|
133 | #ifdef HAVE_VMG
|
---|
134 | if (params.DoLongrange.get()) {
|
---|
135 | if ( World::getInstance().getAllAtoms().size() == 0) {
|
---|
136 | ELOG(1, "Please load the full molecule into the world before starting this action.");
|
---|
137 | return Action::failure;
|
---|
138 | }
|
---|
139 |
|
---|
140 | // obtain combined charge density
|
---|
141 | FragmentationChargeDensity summedChargeDensity(
|
---|
142 | shortrangedata,
|
---|
143 | FragmentJobQueue::getInstance().getKeySets());
|
---|
144 | const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
|
---|
145 | LOG(1, "INFO: There are " << shortrangedata.size() << " short-range and "
|
---|
146 | << full_sample.size() << " level-wise long-range jobs.");
|
---|
147 |
|
---|
148 | // Phase Four: obtain more ids
|
---|
149 | std::map<JobId_t, VMGData> longrangedata;
|
---|
150 | {
|
---|
151 | VMGFragmentController vmgcontroller(io_service);
|
---|
152 | vmgcontroller.setHost(params.host.get());
|
---|
153 | vmgcontroller.setPort(params.port.get());
|
---|
154 | const size_t NoJobs = shortrangedata.size()+full_sample.size();
|
---|
155 | vmgcontroller.requestIds(NoJobs);
|
---|
156 |
|
---|
157 | // Phase Five: create VMGJobs
|
---|
158 | const size_t near_field_cells = params.near_field_cells.get();
|
---|
159 | const size_t interpolation_degree = params.interpolation_degree.get();
|
---|
160 | if (!vmgcontroller.createLongRangeJobs(
|
---|
161 | shortrangedata,
|
---|
162 | full_sample,
|
---|
163 | near_field_cells,
|
---|
164 | interpolation_degree,
|
---|
165 | params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly,
|
---|
166 | params.DoPrintDebug.get()))
|
---|
167 | // can't use the summed up fragment due to saturation hydrogens
|
---|
168 | // summedChargeDensity.getFragment(),
|
---|
169 | return Action::failure;
|
---|
170 |
|
---|
171 | // Phase Six: calculate result
|
---|
172 | vmgcontroller.waitforResults(NoJobs);
|
---|
173 | vmgcontroller.getResults(longrangedata);
|
---|
174 | ASSERT( NoJobs == longrangedata.size(),
|
---|
175 | "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
|
---|
176 | +toString(full_sample.size())+"="+toString(NoJobs)
|
---|
177 | +" and VMGresults "+toString(longrangedata.size())+" don't match.");
|
---|
178 | Exitflag += vmgcontroller.getExitflag();
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (params.DoPrintDebug.get()) {
|
---|
182 | std::map<JobId_t, std::string> debugData;
|
---|
183 | {
|
---|
184 | if (!full_sample.empty()) {
|
---|
185 | // create debug jobs for each level to print the summed-up potential to vtk files
|
---|
186 | VMGDebugGridFragmentController debugcontroller(io_service);
|
---|
187 | debugcontroller.setHost(params.host.get());
|
---|
188 | debugcontroller.setPort(params.port.get());
|
---|
189 | debugcontroller.requestIds(full_sample.size());
|
---|
190 | if (!debugcontroller.createDebugJobs(full_sample))
|
---|
191 | return Action::failure;
|
---|
192 | debugcontroller.waitforResults(full_sample.size());
|
---|
193 | debugcontroller.getResults(debugData);
|
---|
194 | Exitflag += debugcontroller.getExitflag();
|
---|
195 | }
|
---|
196 | }
|
---|
197 | }
|
---|
198 | container.addFullResults(keysets, forcekeysets, shortrangedata, longrangedata);
|
---|
199 | } else {
|
---|
200 | container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
|
---|
201 | }
|
---|
202 | #else
|
---|
203 | container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
|
---|
204 | #endif
|
---|
205 |
|
---|
206 | // now clear all present jobs as we are done
|
---|
207 | FragmentJobQueue::getInstance().clear();
|
---|
208 |
|
---|
209 | // if file is given, advise results container to store to file
|
---|
210 | if (!params.resultsfile.get().empty()) {
|
---|
211 | boost::filesystem::path resultsfile = params.resultsfile.get();
|
---|
212 | std::ofstream returnstream(resultsfile.string().c_str());
|
---|
213 | if (returnstream.good()) {
|
---|
214 | boost::archive::text_oarchive oa(returnstream);
|
---|
215 | oa << container;
|
---|
216 | }
|
---|
217 | Exitflag += (int)(!returnstream.good());
|
---|
218 | returnstream.close();
|
---|
219 | }
|
---|
220 |
|
---|
221 | return (Exitflag == 0) ? Action::success : Action::failure;
|
---|
222 | }
|
---|
223 |
|
---|
224 | Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
|
---|
225 | return Action::success;
|
---|
226 | }
|
---|
227 |
|
---|
228 | Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
|
---|
229 | return Action::success;
|
---|
230 | }
|
---|
231 |
|
---|
232 | bool FragmentationFragmentationAutomationAction::canUndo() {
|
---|
233 | return false;
|
---|
234 | }
|
---|
235 |
|
---|
236 | bool FragmentationFragmentationAutomationAction::shouldUndo() {
|
---|
237 | return false;
|
---|
238 | }
|
---|
239 | /** =========== end of function ====================== */
|
---|