source: src/joiner.cpp@ 2f40c0e

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 2f40c0e was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

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