source: src/joiner.cpp@ c38826

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

  • Property mode set to 100755
File size: 12.0 KB
Line 
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
8/** \file joiner.cpp
9 *
10 * Takes evaluated fragments (energy and forces) and by reading the factors files determines total energy
11 * and each force for the whole molecule.
12 *
13 */
14
15//============================ INCLUDES ===========================
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "Helpers/MemDebug.hpp"
23
24#include <cstring>
25
26#include "datacreator.hpp"
27#include "Helpers/helpers.hpp"
28#include "parser.hpp"
29#include "periodentafel.hpp"
30#include "Helpers/Verbose.hpp"
31
32//============================== MAIN =============================
33
34int main(int argc, char **argv)
35{
36 periodentafel *periode = NULL; // and a period table of all elements
37 EnergyMatrix Energy;
38 EnergyMatrix EnergyFragments;
39
40 EnergyMatrix Hcorrection;
41 EnergyMatrix HcorrectionFragments;
42
43 ForceMatrix Force;
44 ForceMatrix ForceFragments;
45
46 HessianMatrix Hessian;
47 HessianMatrix HessianFragments;
48
49 ForceMatrix Shielding;
50 ForceMatrix ShieldingPAS;
51 ForceMatrix ShieldingFragments;
52 ForceMatrix ShieldingPASFragments;
53 ForceMatrix Chi;
54 ForceMatrix ChiPAS;
55 ForceMatrix ChiFragments;
56 ForceMatrix ChiPASFragments;
57 KeySetsContainer KeySet;
58 stringstream prefix;
59 char *dir = NULL;
60 bool NoHCorrection = false;
61 bool NoHessian = false;
62
63 DoLog(0) && (Log() << Verbose(0) << "Joiner" << endl);
64 DoLog(0) && (Log() << Verbose(0) << "======" << endl);
65
66 // Get the command line options
67 if (argc < 3) {
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);
72 return 1;
73 } else {
74 dir = new char[strlen(argv[2]) + 2];
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;
91 if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
92 NoHCorrection = true;
93 DoLog(0) && (Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl);
94 }
95 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
96 if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
97 NoHessian = true;
98 DoLog(0) && (Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl);
99 }
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;
103 if (!Chi.ParseFragmentMatrix(argv[1], dir, ChiSuffix, 1, 0)) return 1;
104 if (!ChiPAS.ParseFragmentMatrix(argv[1], dir, ChiPASSuffix, 1, 0)) return 1;
105 }
106
107 // ---------- Parse the TE Factors into an array -----------------
108 if (!Energy.InitialiseIndices()) return 1;
109 if (!NoHCorrection)
110 Hcorrection.InitialiseIndices();
111
112 // ---------- Parse the Force indices into an array ---------------
113 if (!Force.ParseIndices(argv[1])) return 1;
114
115 // ---------- Parse the Hessian (=force) indices into an array ---------------
116 if (!NoHessian)
117 if (!Hessian.InitialiseIndices((class MatrixContainer *)&Force)) return 1;
118
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;
123 if(!Chi.ParseIndices(argv[1])) return 1;
124 if(!ChiPAS.ParseIndices(argv[1])) return 1;
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;
131
132 if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
133 if (!NoHCorrection)
134 HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
135 if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
136 if (!NoHessian)
137 if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
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;
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;
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;
148 if (!NoHessian)
149 if (!Hessian.SetLastMatrix(0., 0)) return 1;
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;
153 if(!Chi.SetLastMatrix(0., 2)) return 1;
154 if(!ChiPAS.SetLastMatrix(0., 2)) return 1;
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 --------------------
162 DoLog(0) && (Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl);
163 if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
164 if (!NoHCorrection) {
165 HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
166 if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
167 Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
168 } else
169 if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
170 // --------- sum up Forces --------------------
171 DoLog(0) && (Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl);
172 if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
173 if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
174 // --------- sum up Hessian --------------------
175 if (!NoHessian) {
176 DoLog(0) && (Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl);
177 if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
178 if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
179 }
180 if (periode != NULL) { // also look for PAS values
181 DoLog(0) && (Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl);
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;
186 if (!ChiFragments.SumSubManyBodyTerms(Chi, KeySet, BondOrder)) return 1;
187 if (!Chi.SumSubForces(ChiFragments, KeySet, BondOrder, 1.)) return 1;
188 if (!ChiPASFragments.SumSubManyBodyTerms(ChiPAS, KeySet, BondOrder)) return 1;
189 if (!ChiPAS.SumSubForces(ChiPASFragments, KeySet, BondOrder, 1.)) return 1;
190 }
191
192 // --------- write the energy and forces file --------------------
193 prefix.str(" ");
194 prefix << dir << OrderSuffix << (BondOrder+1);
195 DoLog(0) && (Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl);
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;
200 // hessian
201 if (!NoHessian)
202 if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
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;
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;
209 }
210 }
211 // fragments
212 prefix.str(" ");
213 prefix << dir << EnergyFragmentSuffix;
214 if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
215 if (!NoHCorrection) {
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;
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 }
228 if (!NoHessian) {
229 prefix.str(" ");
230 prefix << dir << HessianFragmentSuffix;
231 if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
232 }
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;
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;
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;
250 if (!NoHCorrection) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
251 if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
252 if (!NoHessian)
253 if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
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;
257 if (!Chi.WriteLastMatrix(argv[1], dir, ChiFragmentSuffix)) return 1;
258 if (!ChiPAS.WriteLastMatrix(argv[1], dir, ChiPASFragmentSuffix)) return 1;
259 }
260
261 // exit
262 delete(periode);
263 delete[](dir);
264 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
265 return 0;
266};
267
268//============================ END ===========================
Note: See TracBrowser for help on using the repository browser.