source: src/joiner.cpp@ 5f1d5b8

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 5f1d5b8 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
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
[bf3817]10// include config.h
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
[112b09]15#include "Helpers/MemDebug.hpp"
16
[49e1ae]17#include <cstring>
18
[6ac7ee]19#include "datacreator.hpp"
[952f38]20#include "Helpers/helpers.hpp"
[6ac7ee]21#include "parser.hpp"
22#include "periodentafel.hpp"
[952f38]23#include "Helpers/Verbose.hpp"
[14de469]24
25//============================== MAIN =============================
26
27int main(int argc, char **argv)
28{
[042f82]29 periodentafel *periode = NULL; // and a period table of all elements
30 EnergyMatrix Energy;
31 EnergyMatrix EnergyFragments;
[85d278]32
33 EnergyMatrix Hcorrection;
[042f82]34 EnergyMatrix HcorrectionFragments;
[85d278]35
36 ForceMatrix Force;
[042f82]37 ForceMatrix ForceFragments;
[85d278]38
39 HessianMatrix Hessian;
40 HessianMatrix HessianFragments;
41
[042f82]42 ForceMatrix Shielding;
43 ForceMatrix ShieldingPAS;
44 ForceMatrix ShieldingFragments;
45 ForceMatrix ShieldingPASFragments;
[71e7c7]46 ForceMatrix Chi;
47 ForceMatrix ChiPAS;
48 ForceMatrix ChiFragments;
49 ForceMatrix ChiPASFragments;
[14de469]50 KeySetsContainer KeySet;
[042f82]51 stringstream prefix;
52 char *dir = NULL;
[b12a35]53 bool NoHCorrection = false;
[85d278]54 bool NoHessian = false;
[042f82]55
[a67d19]56 DoLog(0) && (Log() << Verbose(0) << "Joiner" << endl);
57 DoLog(0) && (Log() << Verbose(0) << "======" << endl);
[042f82]58
59 // Get the command line options
60 if (argc < 3) {
[a67d19]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);
[042f82]65 return 1;
66 } else {
[920c70]67 dir = new char[strlen(argv[2]) + 2];
[042f82]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;
[b12a35]84 if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
85 NoHCorrection = true;
[a67d19]86 DoLog(0) && (Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl);
[b12a35]87 }
[042f82]88 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
[85d278]89 if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
90 NoHessian = true;
[a67d19]91 DoLog(0) && (Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl);
[85d278]92 }
[042f82]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;
[674220]96 if (!Chi.ParseFragmentMatrix(argv[1], dir, ChiSuffix, 1, 0)) return 1;
97 if (!ChiPAS.ParseFragmentMatrix(argv[1], dir, ChiPASSuffix, 1, 0)) return 1;
[042f82]98 }
99
100 // ---------- Parse the TE Factors into an array -----------------
[f731ae]101 if (!Energy.InitialiseIndices()) return 1;
[b12a35]102 if (!NoHCorrection)
103 Hcorrection.InitialiseIndices();
[14de469]104
[042f82]105 // ---------- Parse the Force indices into an array ---------------
106 if (!Force.ParseIndices(argv[1])) return 1;
107
[85d278]108 // ---------- Parse the Hessian (=force) indices into an array ---------------
[b12a35]109 if (!NoHessian)
110 if (!Hessian.InitialiseIndices((class MatrixContainer *)&Force)) return 1;
[85d278]111
[042f82]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;
[234af2]116 if(!Chi.ParseIndices(argv[1])) return 1;
117 if(!ChiPAS.ParseIndices(argv[1])) return 1;
[042f82]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;
[674220]124
[042f82]125 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
[b12a35]126 if (!NoHCorrection)
127 HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
[042f82]128 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
[85d278]129 if (!NoHessian)
130 if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
[042f82]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;
[674220]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;
[042f82]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;
[85d278]141 if (!NoHessian)
142 if (!Hessian.SetLastMatrix(0., 0)) return 1;
[042f82]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;
[674220]146 if(!Chi.SetLastMatrix(0., 2)) return 1;
147 if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
[042f82]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 --------------------
[a67d19]155 DoLog(0) && (Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl);
[042f82]156 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
[b12a35]157 if (!NoHCorrection) {
[042f82]158 HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
159 if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
[b12a35]160 Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
[390248]161 } else
[042f82]162 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
163 // --------- sum up Forces --------------------
[a67d19]164 DoLog(0) && (Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl);
[042f82]165 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
166 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
[85d278]167 // --------- sum up Hessian --------------------
168 if (!NoHessian) {
[a67d19]169 DoLog(0) && (Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl);
[85d278]170 if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
171 if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
172 }
[042f82]173 if (periode != NULL) { // also look for PAS values
[a67d19]174 DoLog(0) && (Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl);
[042f82]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;
[674220]179 if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
[234af2]180 if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
[674220]181 if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
[234af2]182 if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
[042f82]183 }
184
185 // --------- write the energy and forces file --------------------
186 prefix.str(" ");
187 prefix << dir << OrderSuffix << (BondOrder+1);
[a67d19]188 DoLog(0) && (Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl);
[042f82]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;
[85d278]193 // hessian
[b12a35]194 if (!NoHessian)
195 if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
[042f82]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;
[674220]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;
[042f82]202 }
203 }
204 // fragments
205 prefix.str(" ");
206 prefix << dir << EnergyFragmentSuffix;
207 if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
[b12a35]208 if (!NoHCorrection) {
[042f82]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;
[88b400]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 }
[85d278]221 if (!NoHessian) {
222 prefix.str(" ");
223 prefix << dir << HessianFragmentSuffix;
224 if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
225 }
[042f82]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;
[674220]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;
[042f82]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;
[b12a35]243 if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
[042f82]244 if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
[85d278]245 if (!NoHessian)
246 if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
[042f82]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;
[674220]250 if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
251 if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
[042f82]252 }
253
254 // exit
255 delete(periode);
[920c70]256 delete[](dir);
[a67d19]257 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
[042f82]258 return 0;
[14de469]259};
260
261//============================ END ===========================
Note: See TracBrowser for help on using the repository browser.