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