source: src/Fragmentation/joiner.cpp@ dcbb5d

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

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100755
File size: 12.4 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/** \file joiner.cpp
24 *
25 * Takes evaluated fragments (energy and forces) and by reading the factors files determines total energy
26 * and each force for the whole molecule.
27 *
28 */
29
30//============================ INCLUDES ===========================
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 <cstring>
40#include <cmath>
41
42#include "datacreator.hpp"
43#include "Element/periodentafel.hpp"
44#include "Fragmentation/defs.hpp"
45#include "Fragmentation/EnergyMatrix.hpp"
46#include "Fragmentation/ForceMatrix.hpp"
47#include "Fragmentation/helpers.hpp"
48#include "Fragmentation/HessianMatrix.hpp"
49#include "Fragmentation/KeySetsContainer.hpp"
50#include "CodePatterns/Log.hpp"
51#include "CodePatterns/Verbose.hpp"
52
53//============================== MAIN =============================
54
55int main(int argc, char **argv)
56{
57 periodentafel *periode = NULL; // and a period table of all elements
58 EnergyMatrix Energy;
59 EnergyMatrix EnergyFragments;
60
61 EnergyMatrix Hcorrection;
62 EnergyMatrix HcorrectionFragments;
63
64 ForceMatrix Force;
65 ForceMatrix ForceFragments;
66
67 HessianMatrix Hessian;
68 HessianMatrix HessianFragments;
69
70 ForceMatrix Shielding;
71 ForceMatrix ShieldingPAS;
72 ForceMatrix ShieldingFragments;
73 ForceMatrix ShieldingPASFragments;
74 ForceMatrix Chi;
75 ForceMatrix ChiPAS;
76 ForceMatrix ChiFragments;
77 ForceMatrix ChiPASFragments;
78 KeySetsContainer KeySet;
79 stringstream prefix;
80 char *dir = NULL;
81 bool NoHCorrection = false;
82 bool NoHessian = false;
83
84 LOG(0, "Joiner");
85 LOG(0, "======");
86
87 // Get the command line options
88 if (argc < 3) {
89 LOG(0, "Usage: " << argv[0] << " <inputdir> <prefix> [elementsdb]");
90 LOG(0, "<inputdir>\ttherein the output of a molecuilder fragmentation is expected, each fragment with a subdir containing an energy.all and a forces.all file.");
91 LOG(0, "<prefix>\tprefix of energy and forces file.");
92 LOG(0, "[elementsdb]\tpath to elements database, needed for shieldings.");
93 return 1;
94 } else {
95 dir = new char[strlen(argv[2]) + 2];
96 strcpy(dir, "/");
97 strcat(dir, argv[2]);
98 }
99 if (argc > 3) {
100 periode = new periodentafel;
101 periode->LoadPeriodentafel(argv[3]);
102 }
103
104 // Test the given directory
105 if (!TestParams(argc, argv))
106 return 1;
107
108 // +++++++++++++++++ PARSING +++++++++++++++++++++++++++++++
109
110 // ------------- Parse through all Fragment subdirs --------
111 if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
112 if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
113 NoHCorrection = true;
114 LOG(0, "No HCorrection matrices found, skipping these.");
115 }
116 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
117 if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
118 NoHessian = true;
119 LOG(0, "No hessian matrices found, skipping these.");
120 }
121 if (periode != NULL) { // also look for PAS values
122 if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
123 if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
124 if (!Chi.ParseFragmentMatrix(argv[1], dir, ChiSuffix, 1, 0)) return 1;
125 if (!ChiPAS.ParseFragmentMatrix(argv[1], dir, ChiPASSuffix, 1, 0)) return 1;
126 }
127
128 // ---------- Parse the TE Factors into an array -----------------
129 if (!Energy.InitialiseIndices()) return 1;
130 if (!NoHCorrection)
131 Hcorrection.InitialiseIndices();
132
133 // ---------- Parse the Force indices into an array ---------------
134 if (!Force.ParseIndices(argv[1])) return 1;
135
136 // ---------- Parse the Hessian (=force) indices into an array ---------------
137 if (!NoHessian)
138 if (!Hessian.InitialiseIndices((class MatrixContainer *)&Force)) return 1;
139
140 // ---------- Parse the shielding indices into an array ---------------
141 if (periode != NULL) { // also look for PAS values
142 if(!Shielding.ParseIndices(argv[1])) return 1;
143 if(!ShieldingPAS.ParseIndices(argv[1])) return 1;
144 if(!Chi.ParseIndices(argv[1])) return 1;
145 if(!ChiPAS.ParseIndices(argv[1])) return 1;
146 }
147
148 // ---------- Parse the KeySets into an array ---------------
149 if (!KeySet.ParseKeySets(argv[1], Force.RowCounter, Force.MatrixCounter)) return 1;
150
151 if (!KeySet.ParseManyBodyTerms()) return 1;
152
153 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
154 if (!NoHCorrection)
155 HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
156 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
157 if (!NoHessian)
158 if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
159 if (periode != NULL) { // also look for PAS values
160 if (!ShieldingFragments.AllocateMatrix(Shielding.Header, Shielding.MatrixCounter, Shielding.RowCounter, Shielding.ColumnCounter)) return 1;
161 if (!ShieldingPASFragments.AllocateMatrix(ShieldingPAS.Header, ShieldingPAS.MatrixCounter, ShieldingPAS.RowCounter, ShieldingPAS.ColumnCounter)) return 1;
162 if (!ChiFragments.AllocateMatrix(Chi.Header, Chi.MatrixCounter, Chi.RowCounter, Chi.ColumnCounter)) return 1;
163 if (!ChiPASFragments.AllocateMatrix(ChiPAS.Header, ChiPAS.MatrixCounter, ChiPAS.RowCounter, ChiPAS.ColumnCounter)) return 1;
164 }
165
166 // ----------- Resetting last matrices (where full QM values are stored right now)
167 if(!Energy.SetLastMatrix(0., 0)) return 1;
168 if(!Force.SetLastMatrix(0., 2)) return 1;
169 if (!NoHessian)
170 if (!Hessian.SetLastMatrix(0., 0)) return 1;
171 if (periode != NULL) { // also look for PAS values
172 if(!Shielding.SetLastMatrix(0., 2)) return 1;
173 if(!ShieldingPAS.SetLastMatrix(0., 2)) return 1;
174 if(!Chi.SetLastMatrix(0., 2)) return 1;
175 if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
176 }
177
178 // +++++++++++++++++ SUMMING +++++++++++++++++++++++++++++++
179
180 // --------- sum up and write for each order----------------
181 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
182 // --------- sum up energy --------------------
183 LOG(0, "Summing energy of order " << BondOrder+1 << " ...");
184 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
185 if (!NoHCorrection) {
186 HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
187 if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
188 Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
189 } else
190 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
191 // --------- sum up Forces --------------------
192 LOG(0, "Summing forces of order " << BondOrder+1 << " ...");
193 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
194 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
195 // --------- sum up Hessian --------------------
196 if (!NoHessian) {
197 LOG(0, "Summing Hessian of order " << BondOrder+1 << " ...");
198 if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
199 if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
200 }
201 if (periode != NULL) { // also look for PAS values
202 LOG(0, "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ...");
203 if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
204 if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
205 if (!ShieldingPASFragments.SumSubManyBodyTerms(ShieldingPAS, KeySet, BondOrder)) return 1;
206 if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder, 1.)) return 1;
207 if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
208 if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
209 if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
210 if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
211 }
212
213 // --------- write the energy and forces file --------------------
214 prefix.str(" ");
215 prefix << dir << OrderSuffix << (BondOrder+1);
216 LOG(0, "Writing files " << argv[1] << prefix.str() << ". ...");
217 // energy
218 if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1;
219 // forces
220 if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1;
221 // hessian
222 if (!NoHessian)
223 if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
224 // shieldings
225 if (periode != NULL) { // also look for PAS values
226 if (!Shielding.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingSuffix)) return 1;
227 if (!ShieldingPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingPASSuffix)) return 1;
228 if (!Chi.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiSuffix)) return 1;
229 if (!ChiPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiPASSuffix)) return 1;
230 }
231 }
232 // fragments
233 prefix.str(" ");
234 prefix << dir << EnergyFragmentSuffix;
235 if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
236 if (!NoHCorrection) {
237 prefix.str(" ");
238 prefix << dir << HcorrectionFragmentSuffix;
239 if (!HcorrectionFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
240 }
241 prefix.str(" ");
242 prefix << dir << ForceFragmentSuffix;
243 if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
244 {
245 std::string fileprefix(FRAGMENTPREFIX);
246 fileprefix += ENERGYPERFRAGMENT;
247 if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], fileprefix.c_str(), "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
248 }
249 if (!NoHessian) {
250 prefix.str(" ");
251 prefix << dir << HessianFragmentSuffix;
252 if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
253 }
254 if (periode != NULL) { // also look for PAS values
255 prefix.str(" ");
256 prefix << dir << ShieldingFragmentSuffix;
257 if (!ShieldingFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
258 prefix.str(" ");
259 prefix << dir << ShieldingPASFragmentSuffix;
260 if (!ShieldingPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
261 prefix.str(" ");
262 prefix << dir << ChiFragmentSuffix;
263 if (!ChiFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
264 prefix.str(" ");
265 prefix << dir << ChiPASFragmentSuffix;
266 if (!ChiPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
267 }
268
269 // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds
270 if (!Energy.WriteLastMatrix(argv[1], dir, EnergyFragmentSuffix)) return 1;
271 if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
272 if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
273 if (!NoHessian)
274 if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
275 if (periode != NULL) { // also look for PAS values
276 if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
277 if (!ShieldingPAS.WriteLastMatrix(argv[1], dir, ShieldingPASFragmentSuffix)) return 1;
278 if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
279 if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
280 }
281
282 // exit
283 delete(periode);
284 delete[](dir);
285 LOG(0, "done.");
286 return 0;
287};
288
289//============================ END ===========================
Note: See TracBrowser for help on using the repository browser.