source: molecuilder/src/joiner.cpp@ b4c71a

Last change on this file since b4c71a was b4c71a, checked in by Frederik Heber <heber@…>, 17 years ago

ColumnCounter -> *ColumnCounter

columns of the MatrixContainer class may now be variable over each matrix. This was changed globally to allow for varying column numbers of the new class HessianMatrix.

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