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