source: src/Fragmentation/ForceMatrix.cpp@ 50e4e5

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 50e4e5 was 9758f7, checked in by Frederik Heber <heber@…>, 13 years ago

Removed C arrays in KeySetsContainer and MatrixContainer.

  • replaced by std::vector<>s.
  • transition is so far very minimal, external (range) counters are still present.
  • extracted allocation of memory into own block in MatrixContainer::parseMatrix().
  • Property mode set to 100644
File size: 5.9 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/*
9 * ForceMatrix.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 "Fragmentation/helpers.hpp"
29#include "Helpers/defs.hpp"
30#include "Helpers/helpers.hpp"
31
32#include "ForceMatrix.hpp"
33
34/** Parsing force Indices of each fragment
35 * \param *name directory with \a ForcesFile
36 * \return parsing successful
37 */
38bool ForceMatrix::ParseIndices(const char *name)
39{
40 ifstream input;
41 char *FragmentNumber = NULL;
42 char filename[1023];
43 stringstream line;
44
45 DoLog(0) && (Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl);
46 Indices.resize(MatrixCounter + 1);
47 line << name << FRAGMENTPREFIX << FORCESFILE;
48 input.open(line.str().c_str(), ios::in);
49 //Log() << Verbose(0) << "Opening " << line.str() << " ... " << input << endl;
50 if (input.fail()) {
51 DoLog(0) && (Log() << Verbose(0) << endl << "ForceMatrix::ParseIndices: Unable to open " << line.str() << ", is the directory correct?" << endl);
52 return false;
53 }
54 for (int i=0;(i<MatrixCounter) && (!input.eof());i++) {
55 // get the number of atoms for this fragment
56 input.getline(filename, 1023);
57 line.str(filename);
58 // parse the values
59 Indices[i].resize(RowCounter[i]);
60 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
61 //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
62 delete[](FragmentNumber);
63 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
64 line >> Indices[i][j];
65 //Log() << Verbose(0) << " " << Indices[i][j];
66 }
67 //Log() << Verbose(0) << endl;
68 }
69 Indices[MatrixCounter].resize(RowCounter[MatrixCounter]);
70 for(int j=RowCounter[MatrixCounter];j--;) {
71 Indices[MatrixCounter][j] = j;
72 }
73 input.close();
74 return true;
75};
76
77
78/** Sums the forces and puts into last element of \a ForceMatrix::Matrix.
79 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
80 * \param KeySets KeySetContainer with bond Order and association mapping of each fragment to an order
81 * \param Order bond order
82 * \param sign +1 or -1
83 * \return true if summing was successful
84 */
85bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, int Order, double sign)
86{
87 int FragmentNr;
88 // sum forces
89 for(int i=0;i<KeySets.FragmentsPerOrder[Order];i++) {
90 FragmentNr = KeySets.OrderSet[Order][i];
91 for(int l=0;l<RowCounter[ FragmentNr ];l++) {
92 int j = Indices[ FragmentNr ][l];
93 if (j > RowCounter[MatrixCounter]) {
94 DoeLog(0) && (eLog()<< Verbose(0) << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl);
95 performCriticalExit();
96 return false;
97 }
98 if (j != -1) {
99 //if (j == 0) Log() << Verbose(0) << "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << "." << endl;
100 for(int k=2;k<ColumnCounter[MatrixCounter];k++)
101 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][k];
102 }
103 }
104 }
105 return true;
106};
107
108
109/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
110 * \param *name directory with files
111 * \param *prefix prefix of each matrix file
112 * \param *suffix suffix of each matrix file
113 * \param skiplines number of inital lines to skip
114 * \param skiplines number of inital columns to skip
115 * \return parsing successful
116 */
117bool ForceMatrix::ParseFragmentMatrix(const char *name, const char *prefix, string suffix, int skiplines, int skipcolumns)
118{
119 char filename[1023];
120 ifstream input;
121 stringstream file;
122 int nr;
123 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
124
125 if (status) {
126 // count number of atoms for last plus one matrix
127 file << name << FRAGMENTPREFIX << KEYSETFILE;
128 input.open(file.str().c_str(), ios::in);
129 if (input.fail()) {
130 DoLog(0) && (Log() << Verbose(0) << endl << "ForceMatrix::ParseFragmentMatrix: Unable to open " << file.str() << ", is the directory correct?" << endl);
131 return false;
132 }
133 RowCounter[MatrixCounter] = 0;
134 while (!input.eof()) {
135 input.getline(filename, 1023);
136 stringstream zeile(filename);
137 while (!zeile.eof()) {
138 zeile >> nr;
139 //Log() << Verbose(0) << "Current index: " << getNr() << "." << endl;
140 if (nr > RowCounter[MatrixCounter])
141 RowCounter[MatrixCounter] = nr;
142 }
143 }
144 RowCounter[MatrixCounter]++; // Nr start at 0, count starts at 1
145 input.close();
146
147 ColumnCounter[MatrixCounter] = 0;
148 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
149 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
150 ColumnCounter[MatrixCounter] = ColumnCounter[j];
151 }
152
153 // allocate last plus one matrix
154 if (Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
155 Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
156 for(int j=0;j<=RowCounter[MatrixCounter];j++)
157 if (Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
158 Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
159
160 // try independently to parse global forcesuffix file if present
161 strncpy(filename, name, 1023);
162 strncat(filename, prefix, 1023-strlen(filename));
163 strncat(filename, suffix.c_str(), 1023-strlen(filename));
164 std::ifstream input(filename);
165 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter);
166 input.close();
167 }
168
169
170 return status;
171};
Note: See TracBrowser for help on using the repository browser.