source: src/joiner.cpp@ 00b59d5

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 00b59d5 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

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