source: src/joiner.cpp@ ba9f5b

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 ba9f5b was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

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