source: src/Fragmentation/Summation/Containers/FragmentationLongRangeResults.cpp@ 20bb3b

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 20bb3b was 94db13, checked in by Frederik Heber <heber@…>, 10 years ago

Again changes to obtain correct longrange forces, also forces are optional.

  • renamed particle_forces -> forces to make it consistent with MPQCData_Fused.
  • MPQCData_Fused and VMGData_Fused are structs and no longer namespace as the latter cannot serve as template arguments.
  • split off forces in VMGData into VMGDataForceMap_t and VMGDataForceVector_t.
  • changed ConvertMPQCDataToForceMap() into template function ConvertDataToForceMap(), working also on VMGDataForceMap_t.
  • this required changes in FragmentationShortRangeResults.
  • FragmentationLongRangeResults now also converts the longrange forces correctly.
  • AnalyseFragmentResults now prints also a ..VMGForces.dat file.
  • VMGData's forces are now optional to some degree and analysis chain can deal with it.
  • introducing forces we must still maintain working code when results without forces are calculated (e.g. as in the regression tests). Hence, a boolean im VMGData and FragmentationLongRangeResults states whether forces have been found or not and whether these should be summed up or not subsequently.
  • Property mode set to 100644
File size: 11.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 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 * FragmentationLongRangeResults.cpp
26 *
27 * Created on: Aug 31, 2012
28 * Author: heber
29 */
30
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "CodePatterns/MemDebug.hpp"
38
39#include "FragmentationLongRangeResults.hpp"
40
41#include <boost/mpl/for_each.hpp>
42#include <boost/mpl/remove.hpp>
43#include <sstream>
44
45#include "CodePatterns/Assert.hpp"
46#include "CodePatterns/Log.hpp"
47
48#include "Fragmentation/KeySetsContainer.hpp"
49#include "Fragmentation/parseKeySetFile.hpp"
50#include "Fragmentation/Summation/Converter/DataConverter.hpp"
51#include "Fragmentation/Summation/Containers/createMatrixNrLookup.hpp"
52#include "Fragmentation/Summation/Containers/extractJobIds.hpp"
53#include "Fragmentation/Summation/AllLevelOrthogonalSummator.hpp"
54#include "Fragmentation/Summation/IndexSetContainer.hpp"
55#include "Fragmentation/Summation/OrthogonalSumUpPerLevel.hpp"
56#include "Fragmentation/Summation/SubsetMap.hpp"
57#include "Fragmentation/Summation/SumUpPerLevel.hpp"
58
59#include "Helpers/defs.hpp"
60
61FragmentationLongRangeResults::FragmentationLongRangeResults(
62 const std::map<JobId_t,MPQCData> &fragmentData,
63 std::map<JobId_t,VMGData> &longrangeData,
64 const KeySetsContainer& _KeySet,
65 const KeySetsContainer& _ForceKeySet) :
66 KeySet(_KeySet),
67 ForceKeySet(_ForceKeySet),
68 hasForces((!longrangeData.empty()) && (longrangeData.begin()->second.hasForces))
69{
70 initLookups(fragmentData, longrangeData);
71
72 // convert KeySetContainer to IndexSetContainer
73 container.reset(new IndexSetContainer(KeySet));
74 // create the map of all keysets
75 subsetmap.reset(new SubsetMap(*container));
76}
77
78void FragmentationLongRangeResults::initLookups(
79 const std::map<JobId_t,MPQCData> &fragmentData,
80 std::map<JobId_t,VMGData> &longrangeData
81 )
82{
83 // create lookup from job nr to fragment number
84 {
85 size_t MPQCFragmentCounter = 0;
86 std::vector<bool> ValueMask(fragmentData.size(), true);
87 const std::vector<JobId_t> mpqcjobids = extractJobIds<MPQCData>(fragmentData);
88 MPQCMatrixNrLookup =
89 createMatrixNrLookup(mpqcjobids, MPQCFragmentCounter, ValueMask);
90 }
91
92 {
93 size_t VMGFragmentCounter = 0;
94 std::vector<bool> ValueMask(longrangeData.size(), true);
95 const std::vector<JobId_t> vmgjobids = extractJobIds<VMGData>(longrangeData);
96 VMGMatrixNrLookup =
97 createMatrixNrLookup(vmgjobids, VMGFragmentCounter, ValueMask);
98 }
99}
100
101void FragmentationLongRangeResults::operator()(
102 const std::map<JobId_t,MPQCData> &fragmentData,
103 std::map<JobId_t,VMGData> &longrangeData,
104 const std::vector<VMGData> &fullsolutionData,
105 const std::vector<SamplingGrid> &full_sample)
106{
107 MaxLevel = subsetmap->getMaximumSetLevel();
108 LOG(1, "INFO: Summing up results till level " << MaxLevel << ".");
109 /// convert all MPQCData to MPQCDataMap_t
110 {
111 ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
112 "FragmentationLongRangeResults::FragmentationLongRangeResults() - ForceKeySet's KeySets and fragmentData differ in size.");
113
114 OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCData, MPQCDataGridVector_t>(
115 fragmentData, MPQCMatrixNrLookup, container, subsetmap,
116 Result_Grid_fused, Result_perIndexSet_Grid);
117
118 // multiply each short-range potential with the respective charge
119 std::map<JobId_t,MPQCData>::const_iterator mpqciter = fragmentData.begin();
120 std::map<JobId_t,VMGData>::iterator vmgiter = longrangeData.begin();
121 for (; vmgiter != longrangeData.end(); ++mpqciter, ++vmgiter) {
122 vmgiter->second.sampled_potential *= mpqciter->second.sampled_grid;
123 }
124 // then sum up
125 OrthogonalSumUpPerLevel<VMGDataMap_t, VMGData, VMGDataVector_t>(
126 longrangeData, VMGMatrixNrLookup, container, subsetmap,
127 Result_LongRange_fused, Result_perIndexSet_LongRange);
128
129 if (hasLongRangeForces()) {
130 // force has extra data converter (this is similar to MPQCData's forces
131 std::map<JobId_t, VMGDataForceMap_t> VMGData_Force_fused;
132 convertDatatoForceMap<VMGData, VMGDataForceMap_t, VMGDataFused>(
133 longrangeData, ForceKeySet, VMGData_Force_fused);
134 Result_ForceLongRange_fused.resize(MaxLevel); // we need the results of correct size already
135 AllLevelOrthogonalSummator<VMGDataForceMap_t> forceSummer(
136 subsetmap,
137 VMGData_Force_fused,
138 container->getContainer(),
139 VMGMatrixNrLookup,
140 Result_ForceLongRange_fused,
141 Result_perIndexSet_LongRange_Force);
142 boost::mpl::for_each<VMGDataForceVector_t>(boost::ref(forceSummer));
143 }
144
145 // then sum up
146 OrthogonalSumUpPerLevel<VMGDataGridMap_t, VMGData, VMGDataGridVector_t>(
147 longrangeData, VMGMatrixNrLookup, container, subsetmap,
148 Result_GridLongRange_fused, Result_perIndexSet_LongRange_Grid);
149
150 Result_LongRangeIntegrated_fused.reserve(MaxLevel);
151 // NOTE: potential for level 1 is wrongly calculated within a molecule
152 // as saturation hydrogen are not removed on this level yet
153 for (size_t level = 1; level <= MaxLevel; ++level) {
154 // We have calculated three different contributions: e-e, e-n+n-n, and n-n.
155 // And we want to have e-e+e-n, n-n+n-e (where e-n = n-e).
156 // For each of these three contributions we have a full solution and summed
157 // up short range solutions.
158
159 // first we obtain the full e-e energy as potential times charge on the
160 // respective level.
161 const SamplingGrid &charge_weight =
162 boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused[level-1]);
163 SamplingGrid full_sample_solution = fullsolutionData[level-1].sampled_potential;
164 full_sample_solution *= charge_weight;
165 double electron_solution_energy = full_sample_solution.integral();
166
167 // then we subtract the summed-up short-range e-e interaction energy from
168 // the full solution.
169 const SamplingGrid &short_range_correction =
170 boost::fusion::at_key<VMGDataFused::sampled_potential>(Result_GridLongRange_fused[level-1]);
171 double electron_short_range_energy = short_range_correction.integral();
172 full_sample_solution -= short_range_correction;
173 electron_solution_energy -= electron_short_range_energy;
174 ASSERT( fabs(electron_solution_energy - full_sample_solution.integral()) < 1e-7,
175 "FragmentationLongRangeResults::operator() - integral and energy are not exchangeable.");
176
177 // then, we obtain the e-n+n-n full solution in the same way
178 double nuclei_solution_energy = fullsolutionData[level-1].nuclei_long;
179 double nuclei_short_range_energy =
180 boost::fusion::at_key<VMGDataFused::nuclei_long>(Result_LongRange_fused[level-1]);
181 nuclei_solution_energy -= nuclei_short_range_energy;
182
183 // and also the e-n full solution
184 double both_solution_energy = fullsolutionData[level-1].electron_long;
185 double both_short_range_energy =
186 boost::fusion::at_key<VMGDataFused::electron_long>(Result_LongRange_fused[level-1]);
187 both_solution_energy -= both_short_range_energy;
188
189 // energies from interpolation at nuclei position has factor of 1/2 already
190 electron_solution_energy *= .5;
191 electron_short_range_energy *= .5;
192
193 // At last, we subtract e-n from n-n+e-n for full solution and short-range
194 // correction.
195 nuclei_solution_energy -= both_solution_energy;
196 nuclei_short_range_energy -= both_short_range_energy;
197
198 VMGDataLongRangeMap_t instance;
199 boost::fusion::at_key<VMGDataFused::electron_longrange>(instance) = electron_solution_energy;
200// LOG(0, "Remaining long-range potential integral of level " << level << " is "
201// << full_sample_solution.integral() << ".");
202 boost::fusion::at_key<VMGDataFused::electron_shortrange>(instance) = electron_short_range_energy;
203// LOG(0, "Short-range correction potential integral of level " << level << " is "
204// << short_range_correction.integral() << ".");
205 boost::fusion::at_key<VMGDataFused::mixed_longrange>(instance) = both_solution_energy;
206// LOG(0, "Remaining long-range energy from potential integral of level " << level << " is "
207// << full_solution_energy << ".");
208 boost::fusion::at_key<VMGDataFused::mixed_shortrange>(instance) = both_short_range_energy;
209// LOG(0, "Short-range correction energy from potential integral of level " << level << " is "
210// << short_range_energy << ".");
211 boost::fusion::at_key<VMGDataFused::nuclei_longrange>(instance) = nuclei_solution_energy;
212// LOG(0, "Remaining long-range energy from potential integral of level " << level << " is "
213// << full_solution_energy << ".");
214 boost::fusion::at_key<VMGDataFused::nuclei_shortrange>(instance) = nuclei_short_range_energy;
215// LOG(0, "Short-range correction energy from potential integral of level " << level << " is "
216// << short_range_energy << ".");
217 boost::fusion::at_key<VMGDataFused::total_longrange>(instance) =
218 boost::fusion::at_key<VMGDataFused::electron_longrange>(instance)
219 + 2.*boost::fusion::at_key<VMGDataFused::mixed_longrange>(instance)
220 + boost::fusion::at_key<VMGDataFused::nuclei_longrange>(instance);
221 boost::fusion::at_key<VMGDataFused::total_shortrange>(instance) =
222 boost::fusion::at_key<VMGDataFused::electron_shortrange>(instance)
223 + 2.*boost::fusion::at_key<VMGDataFused::mixed_shortrange>(instance)
224 + boost::fusion::at_key<VMGDataFused::nuclei_shortrange>(instance);
225 Result_LongRangeIntegrated_fused.push_back(instance);
226 }
227// {
228// // LOG(0, "Remaining long-range energy from energy_potential is " << full_sample_solution.integral()-epotentialSummer.getFullContribution() << ".");
229// SamplingGrid full_sample_solution = fullsolutionData.back().sampled_potential;
230// const SamplingGrid &short_range_correction =
231// boost::fusion::at_key<VMGDataFused::sampled_potential>(Result_GridLongRange_fused.back()).getFullContribution();
232// full_sample_solution -= short_range_correction;
233// // multiply element-wise with charge distribution
234// LOG(0, "Remaining long-range potential integral is " << full_sample_solution.integral() << ".");
235// LOG(0, "Short-range correction potential integral of level is " << short_range_correction.integral() << ".");
236// LOG(0, "Remaining long-range energy from potential integral is "
237// << full_sample_solution.integral(full_sample.back()) << ".");
238// LOG(0, "Short-range correction energy from potential integral is "
239// << short_range_correction.integral(full_sample.back()) << ".");
240//
241// double e_long = fullsolutionData.back().e_long;
242// e_long -= boost::fusion::at_key<VMGDataFused::energy_long>(Result_LongRange_fused.back()).getFullContribution();
243// LOG(0, "Remaining long-range energy is " << e_long << ".");
244// }
245
246 // TODO: Extract long-range corrections to forces
247 // NOTE: potential is in atomic length units, NOT IN ANGSTROEM!
248
249 }
250}
Note: See TracBrowser for help on using the repository browser.