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