source: src/joiner.cpp@ 4217e7

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 4217e7 was 255829, checked in by Frederik Heber <heber@…>, 14 years ago

Removed Helpers.hpp, deleted Helpers.cpp and libMoleCuilderHelpers.la is history.

  • defs.cpp is now compiled into libmolecuilder.la.
  • ShapeUnitTest alone needs defs.cpp.
  • Most changes are removal of Helpers/helpers.hpp.
  • performCriticalExit() now inline function in Helpers/helpers.hpp.
  • also inclusion possible where performCriticalExit() is needed.
  • Helpers/helpers.hpp does not include defs.hpp anymore and this causes lots of missing Helpers/defs.hpp, CodePatterns/Log.hpp and alikes.
  • removed src/Helpers from configure.ac.
  • Property mode set to 100755
File size: 12.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file joiner.cpp
9 *
10 * Takes evaluated fragments (energy and forces) and by reading the factors files determines total energy
11 * and each force for the whole molecule.
12 *
13 */
14
15//============================ INCLUDES ===========================
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "CodePatterns/MemDebug.hpp"
23
24#include <cstring>
25#include <cmath>
26
27#include "datacreator.hpp"
28#include "parser.hpp"
29#include "periodentafel.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/Verbose.hpp"
32
33//============================== MAIN =============================
34
35int main(int argc, char **argv)
36{
37 periodentafel *periode = NULL; // and a period table of all elements
38 EnergyMatrix Energy;
39 EnergyMatrix EnergyFragments;
40
41 EnergyMatrix Hcorrection;
42 EnergyMatrix HcorrectionFragments;
43
44 ForceMatrix Force;
45 ForceMatrix ForceFragments;
46
47 HessianMatrix Hessian;
48 HessianMatrix HessianFragments;
49
50 ForceMatrix Shielding;
51 ForceMatrix ShieldingPAS;
52 ForceMatrix ShieldingFragments;
53 ForceMatrix ShieldingPASFragments;
54 ForceMatrix Chi;
55 ForceMatrix ChiPAS;
56 ForceMatrix ChiFragments;
57 ForceMatrix ChiPASFragments;
58 KeySetsContainer KeySet;
59 stringstream prefix;
60 char *dir = NULL;
61 bool NoHCorrection = false;
62 bool NoHessian = false;
63
64 DoLog(0) && (Log() << Verbose(0) << "Joiner" << endl);
65 DoLog(0) && (Log() << Verbose(0) << "======" << endl);
66
67 // Get the command line options
68 if (argc < 3) {
69 DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> [elementsdb]" << endl);
70 DoLog(0) && (Log() << Verbose(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." << endl);
71 DoLog(0) && (Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl);
72 DoLog(0) && (Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl);
73 return 1;
74 } else {
75 dir = new char[strlen(argv[2]) + 2];
76 strcpy(dir, "/");
77 strcat(dir, argv[2]);
78 }
79 if (argc > 3) {
80 periode = new periodentafel;
81 periode->LoadPeriodentafel(argv[3]);
82 }
83
84 // Test the given directory
85 if (!TestParams(argc, argv))
86 return 1;
87
88 // +++++++++++++++++ PARSING +++++++++++++++++++++++++++++++
89
90 // ------------- Parse through all Fragment subdirs --------
91 if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
92 if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
93 NoHCorrection = true;
94 DoLog(0) && (Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl);
95 }
96 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
97 if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
98 NoHessian = true;
99 DoLog(0) && (Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl);
100 }
101 if (periode != NULL) { // also look for PAS values
102 if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
103 if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
104 if (!Chi.ParseFragmentMatrix(argv[1], dir, ChiSuffix, 1, 0)) return 1;
105 if (!ChiPAS.ParseFragmentMatrix(argv[1], dir, ChiPASSuffix, 1, 0)) return 1;
106 }
107
108 // ---------- Parse the TE Factors into an array -----------------
109 if (!Energy.InitialiseIndices()) return 1;
110 if (!NoHCorrection)
111 Hcorrection.InitialiseIndices();
112
113 // ---------- Parse the Force indices into an array ---------------
114 if (!Force.ParseIndices(argv[1])) return 1;
115
116 // ---------- Parse the Hessian (=force) indices into an array ---------------
117 if (!NoHessian)
118 if (!Hessian.InitialiseIndices((class MatrixContainer *)&Force)) return 1;
119
120 // ---------- Parse the shielding indices into an array ---------------
121 if (periode != NULL) { // also look for PAS values
122 if(!Shielding.ParseIndices(argv[1])) return 1;
123 if(!ShieldingPAS.ParseIndices(argv[1])) return 1;
124 if(!Chi.ParseIndices(argv[1])) return 1;
125 if(!ChiPAS.ParseIndices(argv[1])) return 1;
126 }
127
128 // ---------- Parse the KeySets into an array ---------------
129 if (!KeySet.ParseKeySets(argv[1], Force.RowCounter, Force.MatrixCounter)) return 1;
130
131 if (!KeySet.ParseManyBodyTerms()) return 1;
132
133 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
134 if (!NoHCorrection)
135 HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
136 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
137 if (!NoHessian)
138 if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
139 if (periode != NULL) { // also look for PAS values
140 if (!ShieldingFragments.AllocateMatrix(Shielding.Header, Shielding.MatrixCounter, Shielding.RowCounter, Shielding.ColumnCounter)) return 1;
141 if (!ShieldingPASFragments.AllocateMatrix(ShieldingPAS.Header, ShieldingPAS.MatrixCounter, ShieldingPAS.RowCounter, ShieldingPAS.ColumnCounter)) return 1;
142 if (!ChiFragments.AllocateMatrix(Chi.Header, Chi.MatrixCounter, Chi.RowCounter, Chi.ColumnCounter)) return 1;
143 if (!ChiPASFragments.AllocateMatrix(ChiPAS.Header, ChiPAS.MatrixCounter, ChiPAS.RowCounter, ChiPAS.ColumnCounter)) return 1;
144 }
145
146 // ----------- Resetting last matrices (where full QM values are stored right now)
147 if(!Energy.SetLastMatrix(0., 0)) return 1;
148 if(!Force.SetLastMatrix(0., 2)) return 1;
149 if (!NoHessian)
150 if (!Hessian.SetLastMatrix(0., 0)) return 1;
151 if (periode != NULL) { // also look for PAS values
152 if(!Shielding.SetLastMatrix(0., 2)) return 1;
153 if(!ShieldingPAS.SetLastMatrix(0., 2)) return 1;
154 if(!Chi.SetLastMatrix(0., 2)) return 1;
155 if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
156 }
157
158 // +++++++++++++++++ SUMMING +++++++++++++++++++++++++++++++
159
160 // --------- sum up and write for each order----------------
161 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
162 // --------- sum up energy --------------------
163 DoLog(0) && (Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl);
164 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
165 if (!NoHCorrection) {
166 HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
167 if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
168 Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
169 } else
170 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
171 // --------- sum up Forces --------------------
172 DoLog(0) && (Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl);
173 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
174 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
175 // --------- sum up Hessian --------------------
176 if (!NoHessian) {
177 DoLog(0) && (Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl);
178 if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
179 if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
180 }
181 if (periode != NULL) { // also look for PAS values
182 DoLog(0) && (Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl);
183 if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
184 if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
185 if (!ShieldingPASFragments.SumSubManyBodyTerms(ShieldingPAS, KeySet, BondOrder)) return 1;
186 if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder, 1.)) return 1;
187 if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
188 if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
189 if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
190 if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
191 }
192
193 // --------- write the energy and forces file --------------------
194 prefix.str(" ");
195 prefix << dir << OrderSuffix << (BondOrder+1);
196 DoLog(0) && (Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl);
197 // energy
198 if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1;
199 // forces
200 if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1;
201 // hessian
202 if (!NoHessian)
203 if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
204 // shieldings
205 if (periode != NULL) { // also look for PAS values
206 if (!Shielding.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingSuffix)) return 1;
207 if (!ShieldingPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingPASSuffix)) return 1;
208 if (!Chi.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiSuffix)) return 1;
209 if (!ChiPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiPASSuffix)) return 1;
210 }
211 }
212 // fragments
213 prefix.str(" ");
214 prefix << dir << EnergyFragmentSuffix;
215 if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
216 if (!NoHCorrection) {
217 prefix.str(" ");
218 prefix << dir << HcorrectionFragmentSuffix;
219 if (!HcorrectionFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
220 }
221 prefix.str(" ");
222 prefix << dir << ForceFragmentSuffix;
223 if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
224 {
225 std::string fileprefix(FRAGMENTPREFIX);
226 fileprefix += ENERGYPERFRAGMENT;
227 if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], fileprefix.c_str(), "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
228 }
229 if (!NoHessian) {
230 prefix.str(" ");
231 prefix << dir << HessianFragmentSuffix;
232 if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
233 }
234 if (periode != NULL) { // also look for PAS values
235 prefix.str(" ");
236 prefix << dir << ShieldingFragmentSuffix;
237 if (!ShieldingFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
238 prefix.str(" ");
239 prefix << dir << ShieldingPASFragmentSuffix;
240 if (!ShieldingPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
241 prefix.str(" ");
242 prefix << dir << ChiFragmentSuffix;
243 if (!ChiFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
244 prefix.str(" ");
245 prefix << dir << ChiPASFragmentSuffix;
246 if (!ChiPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
247 }
248
249 // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds
250 if (!Energy.WriteLastMatrix(argv[1], dir, EnergyFragmentSuffix)) return 1;
251 if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
252 if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
253 if (!NoHessian)
254 if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
255 if (periode != NULL) { // also look for PAS values
256 if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
257 if (!ShieldingPAS.WriteLastMatrix(argv[1], dir, ShieldingPASFragmentSuffix)) return 1;
258 if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
259 if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
260 }
261
262 // exit
263 delete(periode);
264 delete[](dir);
265 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
266 return 0;
267};
268
269//============================ END ===========================
Note: See TracBrowser for help on using the repository browser.