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