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

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 e2925fd was e2925fd, checked in by Frederik Heber <heber@…>, 12 years ago

Split long-range calculations into two parts to overcome E-N-potential problems.

The general problem is that smeared-out nuclei charges cannot interact with
electron charge densities as they always overlap, hence we always make a large
error. The idea then is - as the potential energy is symmetric both
densities - to flip from N-E to E-N, i.\,e. to take the electron potential and
evaluate at nuclei positions instead of smeared-out nuclei charges with
eletronic charge distribution. However, then we need to make two calculations
for the four contributions: E-E, E-N and N-N, N-E (=E-N).

  • new enums SampleParticles_t eventually tells InterfaceVMGJob whether to sample the nuclei charges onto the grid or not.
  • TreatGrid_t tells InterfaceVMGJob whether to actually add the electronic charge onto the grid (this was added but is actually not required anymore).
  • FragmentationAutomationAction::performCall() now creates twice as many long-range jobs. This requires two variables in VMGData for storing integrated long-range energy: electron_long, nuclei_long, as both calculations are combined into a single VMGData instance per fragment.
  • Summation of long-range contributions is split into three instead of formerly two parts: electron (E-E), nuclei (N-N), and mixed (E-N). This allows to easierly check their cancellation. This needs new member in fusion map and name in printKeyNames.
  • naturally, the enums have to be passed a long way: VMGFragmentController, VMGJob, VMGData.
  • VMGData now has serialization version 1 due to new entry.
  • we enhanced documentation in FragmentationLongRangeResults::operator()() of how and what is summed per level.
  • FIX: InterfaceVMGJob::ImportRightHandSide() subtracted grid instead of adding it. Now, we set correct sign of electron charge distribution in MPQC.
  • TESTFIX: Regression test AnalyseFragmentResults now has short- and long-range part. Long-range part is only diff'ed when the compiled code has the capabilities.
  • Property mode set to 100644
File size: 10.1 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 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
83using namespace MoleCuilder;
84
85// and construct the stuff
86#include "FragmentationAutomationAction.def"
87#include "Action_impl_pre.hpp"
88/** =========== define the function ====================== */
89
90class controller_AddOn;
91
92// needs to be defined for using the FragmentController
93controller_AddOn *getAddOn()
94{
95 return NULL;
96}
97
98Action::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(2*NoJobs);
156
157 // Phase Five a: create VMGJobs for electronic charge distribution
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 VMGFragmentController::DontSampleParticles,
166 VMGFragmentController::DoTreatGrid,
167 params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly,
168 params.DoPrintDebug.get()))
169 return Action::failure;
170
171 // Phase Six a: 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 first VMGresults "+toString(longrangedata.size())+" don't match.");
178 Exitflag += vmgcontroller.getExitflag();
179
180 {
181 std::map<JobId_t, VMGData> longrangedata_both;
182 // Phase Five b: create VMGJobs for nuclei charge distributions
183 const size_t near_field_cells = params.near_field_cells.get();
184 const size_t interpolation_degree = params.interpolation_degree.get();
185 if (!vmgcontroller.createLongRangeJobs(
186 shortrangedata,
187 full_sample,
188 near_field_cells,
189 interpolation_degree,
190 VMGFragmentController::DoSampleParticles,
191 VMGFragmentController::DoTreatGrid,
192 params.DoValenceOnly.get() ? MPQCData::DoSampleValenceOnly : MPQCData::DontSampleValenceOnly,
193 params.DoPrintDebug.get()))
194 return Action::failure;
195
196 // Phase Six b: calculate result
197 vmgcontroller.waitforResults(NoJobs);
198 vmgcontroller.getResults(longrangedata_both);
199 ASSERT( NoJobs == longrangedata_both.size(),
200 "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresults+"
201 +toString(full_sample.size())+"="+toString(NoJobs)
202 +" and second VMGresults "+toString(longrangedata_both.size())+" don't match.");
203 Exitflag += vmgcontroller.getExitflag();
204
205 // go through either data and replace nuclei_long with contribution from both
206 ASSERT( longrangedata.size() == longrangedata_both.size(),
207 "FragmentationFragmentationAutomationAction::performCall() - longrange results have different sizes.");
208 std::map<JobId_t, VMGData>::iterator destiter = longrangedata.begin();
209 std::map<JobId_t, VMGData>::iterator srciter = longrangedata_both.begin();
210 for (;destiter != longrangedata.end(); ++srciter, ++destiter)
211 destiter->second.nuclei_long = srciter->second.nuclei_long;
212 }
213 }
214
215 if (params.DoPrintDebug.get()) {
216 std::map<JobId_t, std::string> debugData;
217 {
218 if (!full_sample.empty()) {
219 // create debug jobs for each level to print the summed-up potential to vtk files
220 VMGDebugGridFragmentController debugcontroller(io_service);
221 debugcontroller.setHost(params.host.get());
222 debugcontroller.setPort(params.port.get());
223 debugcontroller.requestIds(full_sample.size());
224 if (!debugcontroller.createDebugJobs(full_sample))
225 return Action::failure;
226 debugcontroller.waitforResults(full_sample.size());
227 debugcontroller.getResults(debugData);
228 Exitflag += debugcontroller.getExitflag();
229 }
230 }
231 }
232 container.addFullResults(keysets, forcekeysets, shortrangedata, longrangedata);
233 } else {
234 container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
235 }
236#else
237 container.addShortRangeResults(keysets, forcekeysets, shortrangedata);
238#endif
239
240 // now clear all present jobs as we are done
241 FragmentJobQueue::getInstance().clear();
242
243 // if file is given, advise results container to store to file
244 if (!params.resultsfile.get().empty()) {
245 boost::filesystem::path resultsfile = params.resultsfile.get();
246 std::ofstream returnstream(resultsfile.string().c_str());
247 if (returnstream.good()) {
248 boost::archive::text_oarchive oa(returnstream);
249 oa << container;
250 }
251 Exitflag += (int)(!returnstream.good());
252 returnstream.close();
253 }
254
255 return (Exitflag == 0) ? Action::success : Action::failure;
256}
257
258Action::state_ptr FragmentationFragmentationAutomationAction::performUndo(Action::state_ptr _state) {
259 return Action::success;
260}
261
262Action::state_ptr FragmentationFragmentationAutomationAction::performRedo(Action::state_ptr _state){
263 return Action::success;
264}
265
266bool FragmentationFragmentationAutomationAction::canUndo() {
267 return false;
268}
269
270bool FragmentationFragmentationAutomationAction::shouldUndo() {
271 return false;
272}
273/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.