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