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