source: src/joiner.cpp@ a8f53c4

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 a8f53c4 was 234af2, checked in by Frederik Heber <heber@…>, 17 years ago

Implemented analysis of magnetic susceptibilites.

This is very similar to Sigma(PAS), however not with ForceMatrix class but with EnergyMatrix. This is still not finished and yet not working. However, it does not impact on other functions of joiner or analyzer.

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