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