source: src/Fragmentation/EnergyMatrix.cpp@ 1cfd17

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 1cfd17 was 955b91, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: Removed using namespace std in Vector.hpp.

  • this caused some follow-up problems in other LinearAlgebra modules,
mostly stuff from iostream not having std
prefix then.
this also caused more of them in MoleCuilder modules, mostly due to string,
stringstream, and numeric_limits with std
prefix.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * EnergyMatrix.cpp
10 *
11 * Created on: Sep 15, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <cstring>
23#include <fstream>
24
25#include "CodePatterns/Log.hpp"
26#include "KeySetsContainer.hpp"
27
28#include "EnergyMatrix.hpp"
29
30/** Create a trivial energy index mapping.
31 * This just maps 1 to 1, 2 to 2 and so on for all fragments.
32 * \return creation sucessful
33 */
34bool EnergyMatrix::ParseIndices()
35{
36 LOG(0, "Parsing energy indices.");
37 Indices.resize(MatrixCounter + 1);
38 for(int i=MatrixCounter+1;i--;) {
39 Indices[i].resize(RowCounter[i]);
40 for(int j=RowCounter[i];j--;)
41 Indices[i][j] = j;
42 }
43 return true;
44};
45
46/** Sums the energy with each factor and put into last element of \a EnergyMatrix::Matrix.
47 * Sums over the "F"-terms in ANOVA decomposition.
48 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
49 * \param CorrectionFragments MatrixContainer with hydrogen saturation correction per fragments
50 * \param KeySets KeySetContainer with bond Order and association mapping of each fragment to an order
51 * \param Order bond order
52 * \parsm sign +1 or -1
53 * \return true if summing was successful
54 */
55bool EnergyMatrix::SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySets, int Order, double sign)
56{
57 // sum energy
58 if (CorrectionFragments == NULL)
59 for(int i=KeySets.FragmentsPerOrder[Order];i--;)
60 for(int j=RowCounter[ KeySets.OrderSet[Order][i] ];j--;)
61 for(int k=ColumnCounter[ KeySets.OrderSet[Order][i] ];k--;)
62 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ KeySets.OrderSet[Order][i] ][j][k];
63 else
64 for(int i=KeySets.FragmentsPerOrder[Order];i--;)
65 for(int j=RowCounter[ KeySets.OrderSet[Order][i] ];j--;)
66 for(int k=ColumnCounter[ KeySets.OrderSet[Order][i] ];k--;)
67 Matrix[MatrixCounter][j][k] += sign*(Fragments.Matrix[ KeySets.OrderSet[Order][i] ][j][k] + CorrectionFragments->Matrix[ KeySets.OrderSet[Order][i] ][j][k]);
68 return true;
69};
70
71/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
72 * \param *name directory with files
73 * \param *prefix prefix of each matrix file
74 * \param *suffix suffix of each matrix file
75 * \param skiplines number of inital lines to skip
76 * \param skiplines number of inital columns to skip
77 * \return parsing successful
78 */
79bool EnergyMatrix::ParseFragmentMatrix(const char *name, const char *prefix, std::string suffix, int skiplines, int skipcolumns)
80{
81 char filename[1024];
82 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
83
84 if (status) {
85 // count maximum of columns
86 RowCounter[MatrixCounter] = 0;
87 ColumnCounter[MatrixCounter] = 0;
88 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
89 if (RowCounter[j] > RowCounter[MatrixCounter])
90 RowCounter[MatrixCounter] = RowCounter[j];
91 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
92 ColumnCounter[MatrixCounter] = ColumnCounter[j];
93 }
94 // allocate last plus one matrix
95 if ((int)Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
96 Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
97 for(int j=0;j<=RowCounter[MatrixCounter];j++)
98 if ((int)Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
99 Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
100
101 // try independently to parse global energysuffix file if present
102 strncpy(filename, name, 1023);
103 strncat(filename, prefix, 1023-strlen(filename));
104 strncat(filename, suffix.c_str(), 1023-strlen(filename));
105 std::ifstream input(filename);
106 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter);
107 input.close();
108 }
109 return status;
110};
Note: See TracBrowser for help on using the repository browser.