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