source: src/joiner.cpp@ bf3817

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since bf3817 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100755
File size: 11.8 KB
Line 
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 config.h
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15#include "Helpers/MemDebug.hpp"
16
17#include <cstring>
18
19#include "datacreator.hpp"
20#include "Helpers/helpers.hpp"
21#include "parser.hpp"
22#include "periodentafel.hpp"
23#include "Helpers/Verbose.hpp"
24
25//============================== MAIN =============================
26
27int main(int argc, char **argv)
28{
29 periodentafel *periode = NULL; // and a period table of all elements
30 EnergyMatrix Energy;
31 EnergyMatrix EnergyFragments;
32
33 EnergyMatrix Hcorrection;
34 EnergyMatrix HcorrectionFragments;
35
36 ForceMatrix Force;
37 ForceMatrix ForceFragments;
38
39 HessianMatrix Hessian;
40 HessianMatrix HessianFragments;
41
42 ForceMatrix Shielding;
43 ForceMatrix ShieldingPAS;
44 ForceMatrix ShieldingFragments;
45 ForceMatrix ShieldingPASFragments;
46 ForceMatrix Chi;
47 ForceMatrix ChiPAS;
48 ForceMatrix ChiFragments;
49 ForceMatrix ChiPASFragments;
50 KeySetsContainer KeySet;
51 stringstream prefix;
52 char *dir = NULL;
53 bool NoHCorrection = false;
54 bool NoHessian = false;
55
56 DoLog(0) && (Log() << Verbose(0) << "Joiner" << endl);
57 DoLog(0) && (Log() << Verbose(0) << "======" << endl);
58
59 // Get the command line options
60 if (argc < 3) {
61 DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> [elementsdb]" << endl);
62 DoLog(0) && (Log() << Verbose(0) << "<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);
63 DoLog(0) && (Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl);
64 DoLog(0) && (Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl);
65 return 1;
66 } else {
67 dir = new char[strlen(argv[2]) + 2];
68 strcpy(dir, "/");
69 strcat(dir, argv[2]);
70 }
71 if (argc > 3) {
72 periode = new periodentafel;
73 periode->LoadPeriodentafel(argv[3]);
74 }
75
76 // Test the given directory
77 if (!TestParams(argc, argv))
78 return 1;
79
80 // +++++++++++++++++ PARSING +++++++++++++++++++++++++++++++
81
82 // ------------- Parse through all Fragment subdirs --------
83 if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
84 if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
85 NoHCorrection = true;
86 DoLog(0) && (Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl);
87 }
88 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
89 if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
90 NoHessian = true;
91 DoLog(0) && (Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl);
92 }
93 if (periode != NULL) { // also look for PAS values
94 if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
95 if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
96 if (!Chi.ParseFragmentMatrix(argv[1], dir, ChiSuffix, 1, 0)) return 1;
97 if (!ChiPAS.ParseFragmentMatrix(argv[1], dir, ChiPASSuffix, 1, 0)) return 1;
98 }
99
100 // ---------- Parse the TE Factors into an array -----------------
101 if (!Energy.InitialiseIndices()) return 1;
102 if (!NoHCorrection)
103 Hcorrection.InitialiseIndices();
104
105 // ---------- Parse the Force indices into an array ---------------
106 if (!Force.ParseIndices(argv[1])) return 1;
107
108 // ---------- Parse the Hessian (=force) indices into an array ---------------
109 if (!NoHessian)
110 if (!Hessian.InitialiseIndices((class MatrixContainer *)&Force)) return 1;
111
112 // ---------- Parse the shielding indices into an array ---------------
113 if (periode != NULL) { // also look for PAS values
114 if(!Shielding.ParseIndices(argv[1])) return 1;
115 if(!ShieldingPAS.ParseIndices(argv[1])) return 1;
116 if(!Chi.ParseIndices(argv[1])) return 1;
117 if(!ChiPAS.ParseIndices(argv[1])) return 1;
118 }
119
120 // ---------- Parse the KeySets into an array ---------------
121 if (!KeySet.ParseKeySets(argv[1], Force.RowCounter, Force.MatrixCounter)) return 1;
122
123 if (!KeySet.ParseManyBodyTerms()) return 1;
124
125 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
126 if (!NoHCorrection)
127 HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
128 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
129 if (!NoHessian)
130 if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
131 if (periode != NULL) { // also look for PAS values
132 if (!ShieldingFragments.AllocateMatrix(Shielding.Header, Shielding.MatrixCounter, Shielding.RowCounter, Shielding.ColumnCounter)) return 1;
133 if (!ShieldingPASFragments.AllocateMatrix(ShieldingPAS.Header, ShieldingPAS.MatrixCounter, ShieldingPAS.RowCounter, ShieldingPAS.ColumnCounter)) return 1;
134 if (!ChiFragments.AllocateMatrix(Chi.Header, Chi.MatrixCounter, Chi.RowCounter, Chi.ColumnCounter)) return 1;
135 if (!ChiPASFragments.AllocateMatrix(ChiPAS.Header, ChiPAS.MatrixCounter, ChiPAS.RowCounter, ChiPAS.ColumnCounter)) return 1;
136 }
137
138 // ----------- Resetting last matrices (where full QM values are stored right now)
139 if(!Energy.SetLastMatrix(0., 0)) return 1;
140 if(!Force.SetLastMatrix(0., 2)) return 1;
141 if (!NoHessian)
142 if (!Hessian.SetLastMatrix(0., 0)) return 1;
143 if (periode != NULL) { // also look for PAS values
144 if(!Shielding.SetLastMatrix(0., 2)) return 1;
145 if(!ShieldingPAS.SetLastMatrix(0., 2)) return 1;
146 if(!Chi.SetLastMatrix(0., 2)) return 1;
147 if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
148 }
149
150 // +++++++++++++++++ SUMMING +++++++++++++++++++++++++++++++
151
152 // --------- sum up and write for each order----------------
153 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
154 // --------- sum up energy --------------------
155 DoLog(0) && (Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl);
156 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
157 if (!NoHCorrection) {
158 HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
159 if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
160 Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
161 } else
162 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
163 // --------- sum up Forces --------------------
164 DoLog(0) && (Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl);
165 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
166 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
167 // --------- sum up Hessian --------------------
168 if (!NoHessian) {
169 DoLog(0) && (Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl);
170 if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
171 if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
172 }
173 if (periode != NULL) { // also look for PAS values
174 DoLog(0) && (Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl);
175 if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
176 if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
177 if (!ShieldingPASFragments.SumSubManyBodyTerms(ShieldingPAS, KeySet, BondOrder)) return 1;
178 if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder, 1.)) return 1;
179 if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
180 if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
181 if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
182 if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
183 }
184
185 // --------- write the energy and forces file --------------------
186 prefix.str(" ");
187 prefix << dir << OrderSuffix << (BondOrder+1);
188 DoLog(0) && (Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl);
189 // energy
190 if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1;
191 // forces
192 if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1;
193 // hessian
194 if (!NoHessian)
195 if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
196 // shieldings
197 if (periode != NULL) { // also look for PAS values
198 if (!Shielding.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingSuffix)) return 1;
199 if (!ShieldingPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ShieldingPASSuffix)) return 1;
200 if (!Chi.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiSuffix)) return 1;
201 if (!ChiPAS.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ChiPASSuffix)) return 1;
202 }
203 }
204 // fragments
205 prefix.str(" ");
206 prefix << dir << EnergyFragmentSuffix;
207 if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
208 if (!NoHCorrection) {
209 prefix.str(" ");
210 prefix << dir << HcorrectionFragmentSuffix;
211 if (!HcorrectionFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
212 }
213 prefix.str(" ");
214 prefix << dir << ForceFragmentSuffix;
215 if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
216 {
217 std::string fileprefix(FRAGMENTPREFIX);
218 fileprefix += ENERGYPERFRAGMENT;
219 if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], fileprefix.c_str(), "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
220 }
221 if (!NoHessian) {
222 prefix.str(" ");
223 prefix << dir << HessianFragmentSuffix;
224 if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
225 }
226 if (periode != NULL) { // also look for PAS values
227 prefix.str(" ");
228 prefix << dir << ShieldingFragmentSuffix;
229 if (!ShieldingFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
230 prefix.str(" ");
231 prefix << dir << ShieldingPASFragmentSuffix;
232 if (!ShieldingPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
233 prefix.str(" ");
234 prefix << dir << ChiFragmentSuffix;
235 if (!ChiFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
236 prefix.str(" ");
237 prefix << dir << ChiPASFragmentSuffix;
238 if (!ChiPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
239 }
240
241 // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds
242 if (!Energy.WriteLastMatrix(argv[1], dir, EnergyFragmentSuffix)) return 1;
243 if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
244 if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
245 if (!NoHessian)
246 if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
247 if (periode != NULL) { // also look for PAS values
248 if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
249 if (!ShieldingPAS.WriteLastMatrix(argv[1], dir, ShieldingPASFragmentSuffix)) return 1;
250 if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
251 if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
252 }
253
254 // exit
255 delete(periode);
256 delete[](dir);
257 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
258 return 0;
259};
260
261//============================ END ===========================
Note: See TracBrowser for help on using the repository browser.