[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 |
|
---|
[a3427f] | 41 | //// include headers that implement a archive in simple text format
|
---|
[55e1bc] | 42 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
---|
[240c3e] | 44 |
|
---|
[a3427f] | 45 | //
|
---|
| 46 | //#include <boost/mpl/remove.hpp>
|
---|
| 47 | //#include <boost/lambda/lambda.hpp>
|
---|
[fb881a] | 48 |
|
---|
[a3427f] | 49 | //#include <iostream>
|
---|
[240c3e] | 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 |
|
---|
[ac9ca4] | 56 | #include "Fragmentation/Automation/FragmentJobQueue.hpp"
|
---|
[ffe057] | 57 | #include "Fragmentation/Automation/MPQCFragmentController.hpp"
|
---|
[fbf143] | 58 | #include "Fragmentation/Summation/Containers/FragmentationChargeDensity.hpp"
|
---|
| 59 | #include "Fragmentation/Summation/Containers/FragmentationLongRangeResults.hpp"
|
---|
[a3427f] | 60 | #include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
|
---|
[fbf143] | 61 | #include "Fragmentation/Summation/Containers/FragmentationShortRangeResults.hpp"
|
---|
| 62 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
|
---|
[a3427f] | 63 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
[69c733] | 64 | #ifdef HAVE_VMG
|
---|
[a3427f] | 65 | #include "Fragmentation/Automation/VMGDebugGridFragmentController.hpp"
|
---|
| 66 | #include "Fragmentation/Automation/VMGFragmentController.hpp"
|
---|
[fbf143] | 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"
|
---|
[69c733] | 71 | #endif
|
---|
[edecba] | 72 | #include "World.hpp"
|
---|
| 73 |
|
---|
[86cfac5] | 74 | #include <fstream>
|
---|
[edecba] | 75 | #include <iostream>
|
---|
| 76 | #include <string>
|
---|
| 77 | #include <vector>
|
---|
| 78 |
|
---|
[8cae4c] | 79 | #include <boost/mpl/for_each.hpp>
|
---|
| 80 |
|
---|
[edecba] | 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 |
|
---|
[c5324f] | 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 |
|
---|
[a3427f] | 103 | FragmentationResultContainer &container =
|
---|
| 104 | FragmentationResultContainer::getInstance();
|
---|
| 105 | const KeySetsContainer& keysets = FragmentJobQueue::getInstance().getKeySets();
|
---|
| 106 | const KeySetsContainer& forcekeysets = FragmentJobQueue::getInstance().getFullKeySets();
|
---|
| 107 |
|
---|
[4f056e] | 108 | size_t Exitflag = 0;
|
---|
[a3427f] | 109 | std::map<JobId_t, MPQCData> shortrangedata;
|
---|
[4f056e] | 110 | {
|
---|
[ac9ca4] | 111 | const size_t NumberJobs = FragmentJobQueue::getInstance().size();
|
---|
[4f056e] | 112 | MPQCFragmentController mpqccontroller(io_service);
|
---|
| 113 | mpqccontroller.setHost(params.host.get());
|
---|
| 114 | mpqccontroller.setPort(params.port.get());
|
---|
| 115 | // Phase One: obtain ids
|
---|
[ac9ca4] | 116 | mpqccontroller.requestIds(NumberJobs);
|
---|
[4f056e] | 117 |
|
---|
[ac9ca4] | 118 | // Phase Two: add MPQCJobs and send
|
---|
[503acc1] | 119 | const size_t NoJobs = mpqccontroller.addJobsFromQueue(
|
---|
[6ff62c] | 120 | params.DoLongrange.get() ? MPQCData::DoSampleDensity : MPQCData::DontSampleDensity,
|
---|
| 121 | params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly
|
---|
| 122 | );
|
---|
[503acc1] | 123 | LOG(1, "INFO: Added " << NoJobs << " from FragmentJobsQueue.");
|
---|
[ac9ca4] | 124 | mpqccontroller.run();
|
---|
[4f056e] | 125 |
|
---|
| 126 | // Phase Three: calculate result
|
---|
[ac9ca4] | 127 | mpqccontroller.waitforResults(NumberJobs);
|
---|
[a3427f] | 128 | mpqccontroller.getResults(shortrangedata);
|
---|
[4f056e] | 129 |
|
---|
| 130 | Exitflag += mpqccontroller.getExitflag();
|
---|
| 131 | }
|
---|
[c5324f] | 132 |
|
---|
[69c733] | 133 | #ifdef HAVE_VMG
|
---|
| 134 | if (params.DoLongrange.get()) {
|
---|
[db6f7d] | 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 | }
|
---|
[06865e] | 139 |
|
---|
[849cd8] | 140 | // obtain combined charge density
|
---|
[27594e] | 141 | FragmentationChargeDensity summedChargeDensity(
|
---|
[a3427f] | 142 | shortrangedata,
|
---|
[bae7bc] | 143 | FragmentJobQueue::getInstance().getKeySets());
|
---|
[27594e] | 144 | const std::vector<SamplingGrid> full_sample = summedChargeDensity.getFullSampledGrid();
|
---|
[a3427f] | 145 | LOG(1, "INFO: There are " << shortrangedata.size() << " short-range and "
|
---|
[4f056e] | 146 | << full_sample.size() << " level-wise long-range jobs.");
|
---|
[69c733] | 147 |
|
---|
[4f056e] | 148 | // Phase Four: obtain more ids
|
---|
[a3427f] | 149 | std::map<JobId_t, VMGData> longrangedata;
|
---|
[4f056e] | 150 | {
|
---|
| 151 | VMGFragmentController vmgcontroller(io_service);
|
---|
| 152 | vmgcontroller.setHost(params.host.get());
|
---|
| 153 | vmgcontroller.setPort(params.port.get());
|
---|
[a3427f] | 154 | const size_t NoJobs = shortrangedata.size()+full_sample.size();
|
---|
[4f056e] | 155 | vmgcontroller.requestIds(NoJobs);
|
---|
| 156 |
|
---|
| 157 | // Phase Five: create VMGJobs
|
---|
| 158 | const size_t near_field_cells = params.near_field_cells.get();
|
---|
[cd2591] | 159 | const size_t interpolation_degree = params.interpolation_degree.get();
|
---|
[4f056e] | 160 | if (!vmgcontroller.createLongRangeJobs(
|
---|
[a3427f] | 161 | shortrangedata,
|
---|
[4f056e] | 162 | full_sample,
|
---|
[cd2591] | 163 | near_field_cells,
|
---|
[6ff62c] | 164 | interpolation_degree,
|
---|
| 165 | params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly))
|
---|
[53c579] | 166 | // can't use the summed up fragment due to saturation hydrogens
|
---|
| 167 | // summedChargeDensity.getFragment(),
|
---|
[4f056e] | 168 | return Action::failure;
|
---|
| 169 |
|
---|
| 170 | // Phase Six: calculate result
|
---|
| 171 | vmgcontroller.waitforResults(NoJobs);
|
---|
[a3427f] | 172 | vmgcontroller.getResults(longrangedata);
|
---|
| 173 | ASSERT( NoJobs == longrangedata.size(),
|
---|
[4f056e] | 174 | "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
|
---|
| 175 | +toString(full_sample.size())+"="+toString(NoJobs)
|
---|
[a3427f] | 176 | +" and VMGresults "+toString(longrangedata.size())+" don't match.");
|
---|
[4f056e] | 177 | Exitflag += vmgcontroller.getExitflag();
|
---|
| 178 | }
|
---|
[a2295a] | 179 |
|
---|
[4f056e] | 180 | std::map<JobId_t, std::string> debugData;
|
---|
| 181 | {
|
---|
[a2295a] | 182 | if (!full_sample.empty()) {
|
---|
[376a3b] | 183 | // create debug jobs for each level to print the summed-up potential to vtk files
|
---|
[4f056e] | 184 | VMGDebugGridFragmentController debugcontroller(io_service);
|
---|
| 185 | debugcontroller.setHost(params.host.get());
|
---|
| 186 | debugcontroller.setPort(params.port.get());
|
---|
[a2295a] | 187 | debugcontroller.requestIds(full_sample.size());
|
---|
| 188 | if (!debugcontroller.createDebugJobs(full_sample))
|
---|
| 189 | return Action::failure;
|
---|
| 190 | debugcontroller.waitforResults(full_sample.size());
|
---|
| 191 | debugcontroller.getResults(debugData);
|
---|
[4f056e] | 192 | Exitflag += debugcontroller.getExitflag();
|
---|
[a2295a] | 193 | }
|
---|
[2764e0] | 194 | }
|
---|
[a3427f] | 195 | container.addFullResults(keysets, forcekeysets, shortrangedata, longrangedata);
|
---|
| 196 | } else {
|
---|
| 197 | container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
|
---|
[69c733] | 198 | }
|
---|
[a3427f] | 199 | #else
|
---|
| 200 | container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
|
---|
[69c733] | 201 | #endif
|
---|
[edecba] | 202 |
|
---|
[bae7bc] | 203 | // now clear all present jobs as we are done
|
---|
| 204 | FragmentJobQueue::getInstance().clear();
|
---|
| 205 |
|
---|
[55e1bc] | 206 | // if file is given, advise results container to store to file
|
---|
| 207 | if (!params.resultsfile.get().empty()) {
|
---|
| 208 | boost::filesystem::path resultsfile = params.resultsfile.get();
|
---|
| 209 | std::ofstream returnstream(resultsfile.string().c_str());
|
---|
| 210 | if (returnstream.good()) {
|
---|
| 211 | boost::archive::text_oarchive oa(returnstream);
|
---|
| 212 | oa << container;
|
---|
| 213 | }
|
---|
| 214 | Exitflag += (int)(!returnstream.good());
|
---|
| 215 | returnstream.close();
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[edecba] | 218 | return (Exitflag == 0) ? Action::success : Action::failure;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
|
---|
| 222 | return Action::success;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
|
---|
| 226 | return Action::success;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | bool FragmentationFragmentationAutomationAction::canUndo() {
|
---|
| 230 | return false;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | bool FragmentationFragmentationAutomationAction::shouldUndo() {
|
---|
| 234 | return false;
|
---|
| 235 | }
|
---|
| 236 | /** =========== end of function ====================== */
|
---|