| 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 |  | 
|---|
| 10 | #include "helpers.hpp" | 
|---|
| 11 | #include "parser.hpp" | 
|---|
| 12 |  | 
|---|
| 13 | //============================== MAIN ============================= | 
|---|
| 14 |  | 
|---|
| 15 | int main(int argc, char **argv) | 
|---|
| 16 | { | 
|---|
| 17 | EnergyMatrix Energy; | 
|---|
| 18 | ForceMatrix Force; | 
|---|
| 19 | EnergyMatrix EnergyFragments; | 
|---|
| 20 | ForceMatrix ForceFragments; | 
|---|
| 21 | KeySetsContainer KeySet; | 
|---|
| 22 | stringstream prefix; | 
|---|
| 23 |  | 
|---|
| 24 | cout << "Joiner" << endl; | 
|---|
| 25 | cout << "======" << endl; | 
|---|
| 26 |  | 
|---|
| 27 | // Get the command line options | 
|---|
| 28 | if (argc < 3) { | 
|---|
| 29 | cout << "Usage: " << argv[0] << " <inputdir> <prefix>" << endl; | 
|---|
| 30 | 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; | 
|---|
| 31 | cout << "<prefix>\tprefix of energy and forces file." << endl; | 
|---|
| 32 | return 1; | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | // Test the given directory | 
|---|
| 36 | if (!TestParams(argc, argv)) | 
|---|
| 37 | return 1; | 
|---|
| 38 |  | 
|---|
| 39 | // +++++++++++++++++ PARSING +++++++++++++++++++++++++++++++ | 
|---|
| 40 |  | 
|---|
| 41 | // ------------- Parse through all Fragment subdirs -------- | 
|---|
| 42 | if (!Energy.ParseMatrix(argv[1], argv[2], EnergySuffix,0,0)) return 1; | 
|---|
| 43 | //if (!ParseSubEnergies(argv[1], argv[2], EnergySuffix, data.EnergyHeader, data.Energies, data.EnergyIndices, data.LevelCounter, data.ColumnCounter, data.FragmentCounter)) return 1; | 
|---|
| 44 | if (!Force.ParseMatrix(argv[1], argv[2], ForcesSuffix, 0,0)) return 1; | 
|---|
| 45 | //if (!ParseSubForces(argv[1], argv[2], ForcesSuffix, data.ForcesHeader, data.Forces, data.AtomCounter, data.Column2Counter, data.FragmentCounter)) return 1; | 
|---|
| 46 |  | 
|---|
| 47 | // ---------- Parse the TE Factors into an array ----------------- | 
|---|
| 48 | if (!Energy.ParseIndices()) return 1; | 
|---|
| 49 |  | 
|---|
| 50 | // ---------- Parse the Force indices into an array --------------- | 
|---|
| 51 | if (!Force.ParseIndices(argv[1])) return 1; | 
|---|
| 52 | //if (!ParseForceIndices(argv[1], data.ForcesIndices, data.AtomCounter, data.FragmentCounter)) return 1; | 
|---|
| 53 |  | 
|---|
| 54 | // ---------- Parse the KeySets into an array --------------- | 
|---|
| 55 | if (!KeySet.ParseKeySets(argv[1], Force.RowCounter, Force.MatrixCounter)) return 1; | 
|---|
| 56 | //if (!ParseKeySets(argv[1], data.KeySets, data.AtomCounter, data.FragmentCounter)) return 1; | 
|---|
| 57 |  | 
|---|
| 58 | if (!KeySet.ParseManyBodyTerms()) return 1; | 
|---|
| 59 | //if (!ParseManyBodyTerms(data.Order, data.OrderSet, data.FragmentsPerOrder, data.KeySets, data.AtomCounter, data.FragmentCounter)) return 1; | 
|---|
| 60 | if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1; | 
|---|
| 61 | //if (!ParseSubEnergies(argv[1], argv[2], EnergyFragmentSuffix, data.EnergyHeader, data.EnergyFragments, data.EnergyFragmentIndices, data.LevelFragmentCounter, data.ColumnFragmentCounter, data.FragmentCounter)) return 1; | 
|---|
| 62 | if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1; | 
|---|
| 63 | //if (!ParseSubForces(argv[1], argv[2], ForceFragmentSuffix, data.ForcesHeader, data.ForceFragments, data.AtomCounter, data.Column2Counter, data.FragmentCounter)) return 1; | 
|---|
| 64 |  | 
|---|
| 65 | // ----------- Resetting last matrices (where full QM values are stored right now) | 
|---|
| 66 | if(!Energy.SetLastMatrix(0., 0)) return 1; | 
|---|
| 67 | if(!Force.SetLastMatrix(0., 2)) return 1; | 
|---|
| 68 |  | 
|---|
| 69 | // +++++++++++++++++ SUMMING +++++++++++++++++++++++++++++++ | 
|---|
| 70 |  | 
|---|
| 71 | // --------- sum up and write for each order---------------- | 
|---|
| 72 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) { | 
|---|
| 73 | // --------- sum up energy -------------------- | 
|---|
| 74 | cout << "Summing energy of order " << BondOrder+1 << " ..." << endl; | 
|---|
| 75 | if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1; | 
|---|
| 76 | if (!Energy.SumSubEnergy(EnergyFragments, KeySet, BondOrder)) return 1; | 
|---|
| 77 | // --------- sum up Forces -------------------- | 
|---|
| 78 | cout << "Summing forces of order " << BondOrder+1 << " ..." << endl; | 
|---|
| 79 | if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1; | 
|---|
| 80 | if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder)) return 1; | 
|---|
| 81 |  | 
|---|
| 82 | // --------- write the energy and forces file -------------------- | 
|---|
| 83 | prefix.str(" "); | 
|---|
| 84 | prefix << argv[2] << OrderSuffix << (BondOrder+1); | 
|---|
| 85 | cout << "Writing files " << argv[1] << prefix.str() << ". ..." << endl; | 
|---|
| 86 | // energy | 
|---|
| 87 | if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1; | 
|---|
| 88 | // forces | 
|---|
| 89 | if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1; | 
|---|
| 90 | } | 
|---|
| 91 | // fragments | 
|---|
| 92 | prefix.str(" "); | 
|---|
| 93 | prefix << argv[2] << EnergyFragmentSuffix; | 
|---|
| 94 | if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1; | 
|---|
| 95 | prefix.str(" "); | 
|---|
| 96 | prefix << argv[2] << ForceFragmentSuffix; | 
|---|
| 97 | if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1; | 
|---|
| 98 |  | 
|---|
| 99 | // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds | 
|---|
| 100 | if (!Energy.WriteLastMatrix(argv[1], argv[2], EnergyFragmentSuffix)) return 1; | 
|---|
| 101 | if (!Force.WriteLastMatrix(argv[1], argv[2], ForceFragmentSuffix)) return 1; | 
|---|
| 102 |  | 
|---|
| 103 | // exit | 
|---|
| 104 | cout << "done." << endl; | 
|---|
| 105 | return 0; | 
|---|
| 106 | }; | 
|---|
| 107 |  | 
|---|
| 108 | //============================ END =========================== | 
|---|