[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 ---------------
|
---|
| 149 | if (!KeySet.ParseKeySets(argv[1], Force.RowCounter, Force.MatrixCounter)) return 1;
|
---|
| 150 |
|
---|
| 151 | if (!KeySet.ParseManyBodyTerms()) return 1;
|
---|
[674220] | 152 |
|
---|
[042f82] | 153 | if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
|
---|
[b12a35] | 154 | if (!NoHCorrection)
|
---|
| 155 | HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
|
---|
[042f82] | 156 | if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
|
---|
[85d278] | 157 | if (!NoHessian)
|
---|
| 158 | if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
|
---|
[042f82] | 159 | if (periode != NULL) { // also look for PAS values
|
---|
| 160 | if (!ShieldingFragments.AllocateMatrix(Shielding.Header, Shielding.MatrixCounter, Shielding.RowCounter, Shielding.ColumnCounter)) return 1;
|
---|
| 161 | if (!ShieldingPASFragments.AllocateMatrix(ShieldingPAS.Header, ShieldingPAS.MatrixCounter, ShieldingPAS.RowCounter, ShieldingPAS.ColumnCounter)) return 1;
|
---|
[674220] | 162 | if (!ChiFragments.AllocateMatrix(Chi.Header, Chi.MatrixCounter, Chi.RowCounter, Chi.ColumnCounter)) return 1;
|
---|
| 163 | if (!ChiPASFragments.AllocateMatrix(ChiPAS.Header, ChiPAS.MatrixCounter, ChiPAS.RowCounter, ChiPAS.ColumnCounter)) return 1;
|
---|
[042f82] | 164 | }
|
---|
| 165 |
|
---|
| 166 | // ----------- Resetting last matrices (where full QM values are stored right now)
|
---|
| 167 | if(!Energy.SetLastMatrix(0., 0)) return 1;
|
---|
| 168 | if(!Force.SetLastMatrix(0., 2)) return 1;
|
---|
[85d278] | 169 | if (!NoHessian)
|
---|
| 170 | if (!Hessian.SetLastMatrix(0., 0)) return 1;
|
---|
[042f82] | 171 | if (periode != NULL) { // also look for PAS values
|
---|
| 172 | if(!Shielding.SetLastMatrix(0., 2)) return 1;
|
---|
| 173 | if(!ShieldingPAS.SetLastMatrix(0., 2)) return 1;
|
---|
[674220] | 174 | if(!Chi.SetLastMatrix(0., 2)) return 1;
|
---|
| 175 | if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
|
---|
[042f82] | 176 | }
|
---|
| 177 |
|
---|
| 178 | // +++++++++++++++++ SUMMING +++++++++++++++++++++++++++++++
|
---|
| 179 |
|
---|
| 180 | // --------- sum up and write for each order----------------
|
---|
| 181 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
---|
| 182 | // --------- sum up energy --------------------
|
---|
[47d041] | 183 | LOG(0, "Summing energy of order " << BondOrder+1 << " ...");
|
---|
[042f82] | 184 | if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
|
---|
[b12a35] | 185 | if (!NoHCorrection) {
|
---|
[042f82] | 186 | HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
|
---|
| 187 | if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
[b12a35] | 188 | Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
|
---|
[390248] | 189 | } else
|
---|
[042f82] | 190 | if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
|
---|
| 191 | // --------- sum up Forces --------------------
|
---|
[47d041] | 192 | LOG(0, "Summing forces of order " << BondOrder+1 << " ...");
|
---|
[042f82] | 193 | if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
|
---|
| 194 | if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
[85d278] | 195 | // --------- sum up Hessian --------------------
|
---|
| 196 | if (!NoHessian) {
|
---|
[47d041] | 197 | LOG(0, "Summing Hessian of order " << BondOrder+1 << " ...");
|
---|
[85d278] | 198 | if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
|
---|
| 199 | if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
| 200 | }
|
---|
[042f82] | 201 | if (periode != NULL) { // also look for PAS values
|
---|
[47d041] | 202 | LOG(0, "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ...");
|
---|
[042f82] | 203 | if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
|
---|
| 204 | if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
| 205 | if (!ShieldingPASFragments.SumSubManyBodyTerms(ShieldingPAS, KeySet, BondOrder)) return 1;
|
---|
| 206 | if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
[674220] | 207 | if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
|
---|
[234af2] | 208 | if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
[674220] | 209 | if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
|
---|
[234af2] | 210 | if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
|
---|
[042f82] | 211 | }
|
---|
| 212 |
|
---|
| 213 | // --------- write the energy and forces file --------------------
|
---|
| 214 | prefix.str(" ");
|
---|
| 215 | prefix << dir << OrderSuffix << (BondOrder+1);
|
---|
[47d041] | 216 | LOG(0, "Writing files " << argv[1] << prefix.str() << ". ...");
|
---|
[042f82] | 217 | // energy
|
---|
| 218 | if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1;
|
---|
| 219 | // forces
|
---|
| 220 | if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1;
|
---|
[85d278] | 221 | // hessian
|
---|
[b12a35] | 222 | if (!NoHessian)
|
---|
| 223 | if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
|
---|
[042f82] | 224 | // shieldings
|
---|
| 225 | if (periode != NULL) { // also look for PAS values
|
---|
| 226 | if (!Shielding.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingSuffix)) return 1;
|
---|
| 227 | if (!ShieldingPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingPASSuffix)) return 1;
|
---|
[674220] | 228 | if (!Chi.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiSuffix)) return 1;
|
---|
| 229 | if (!ChiPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiPASSuffix)) return 1;
|
---|
[042f82] | 230 | }
|
---|
| 231 | }
|
---|
| 232 | // fragments
|
---|
| 233 | prefix.str(" ");
|
---|
| 234 | prefix << dir << EnergyFragmentSuffix;
|
---|
| 235 | if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
[b12a35] | 236 | if (!NoHCorrection) {
|
---|
[042f82] | 237 | prefix.str(" ");
|
---|
| 238 | prefix << dir << HcorrectionFragmentSuffix;
|
---|
| 239 | if (!HcorrectionFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
| 240 | }
|
---|
| 241 | prefix.str(" ");
|
---|
| 242 | prefix << dir << ForceFragmentSuffix;
|
---|
| 243 | if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
[88b400] | 244 | {
|
---|
| 245 | std::string fileprefix(FRAGMENTPREFIX);
|
---|
| 246 | fileprefix += ENERGYPERFRAGMENT;
|
---|
| 247 | if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], fileprefix.c_str(), "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
|
---|
| 248 | }
|
---|
[85d278] | 249 | if (!NoHessian) {
|
---|
| 250 | prefix.str(" ");
|
---|
| 251 | prefix << dir << HessianFragmentSuffix;
|
---|
| 252 | if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
| 253 | }
|
---|
[042f82] | 254 | if (periode != NULL) { // also look for PAS values
|
---|
| 255 | prefix.str(" ");
|
---|
| 256 | prefix << dir << ShieldingFragmentSuffix;
|
---|
| 257 | if (!ShieldingFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
| 258 | prefix.str(" ");
|
---|
| 259 | prefix << dir << ShieldingPASFragmentSuffix;
|
---|
| 260 | if (!ShieldingPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
[674220] | 261 | prefix.str(" ");
|
---|
| 262 | prefix << dir << ChiFragmentSuffix;
|
---|
| 263 | if (!ChiFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
| 264 | prefix.str(" ");
|
---|
| 265 | prefix << dir << ChiPASFragmentSuffix;
|
---|
| 266 | if (!ChiPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
|
---|
[042f82] | 267 | }
|
---|
| 268 |
|
---|
| 269 | // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds
|
---|
| 270 | if (!Energy.WriteLastMatrix(argv[1], dir, EnergyFragmentSuffix)) return 1;
|
---|
[b12a35] | 271 | if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
|
---|
[042f82] | 272 | if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
|
---|
[85d278] | 273 | if (!NoHessian)
|
---|
| 274 | if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
|
---|
[042f82] | 275 | if (periode != NULL) { // also look for PAS values
|
---|
| 276 | if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
|
---|
| 277 | if (!ShieldingPAS.WriteLastMatrix(argv[1], dir, ShieldingPASFragmentSuffix)) return 1;
|
---|
[674220] | 278 | if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
|
---|
| 279 | if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
|
---|
[042f82] | 280 | }
|
---|
| 281 |
|
---|
| 282 | // exit
|
---|
| 283 | delete(periode);
|
---|
[920c70] | 284 | delete[](dir);
|
---|
[47d041] | 285 | LOG(0, "done.");
|
---|
[042f82] | 286 | return 0;
|
---|
[14de469] | 287 | };
|
---|
| 288 |
|
---|
| 289 | //============================ END ===========================
|
---|