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