source: src/Fragmentation/ForceMatrix.cpp@ 95b384

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 95b384 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: 5.7 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 * 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 LOG(0, "Parsing force indices for " << MatrixCounter << " matrices.");
46 Indices.resize(MatrixCounter + 1);
47 line << name << FRAGMENTPREFIX << FORCESFILE;
48 input.open(line.str().c_str(), ios::in);
49 //LOG(0, "Opening " << line.str() << " ... " << input);
50 if (input.fail()) {
51 LOG(0, endl << "ForceMatrix::ParseIndices: Unable to open " << line.str() << ", is the directory correct?");
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 //std::stringstream output;
62 //output << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
63 delete[](FragmentNumber);
64 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
65 line >> Indices[i][j];
66 //output << " " << Indices[i][j];
67 }
68 //LOG(0, output.str());
69 }
70 Indices[MatrixCounter].resize(RowCounter[MatrixCounter]);
71 for(int j=RowCounter[MatrixCounter];j--;) {
72 Indices[MatrixCounter][j] = j;
73 }
74 input.close();
75 return true;
76};
77
78
79/** Sums the forces and puts into last element of \a ForceMatrix::Matrix.
80 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
81 * \param KeySets KeySetContainer with bond Order and association mapping of each fragment to an order
82 * \param Order bond order
83 * \param sign +1 or -1
84 * \return true if summing was successful
85 */
86bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, int Order, double sign)
87{
88 int FragmentNr;
89 // sum forces
90 for(int i=0;i<KeySets.FragmentsPerOrder[Order];i++) {
91 FragmentNr = KeySets.OrderSet[Order][i];
92 for(int l=0;l<RowCounter[ FragmentNr ];l++) {
93 int j = Indices[ FragmentNr ][l];
94 if (j > RowCounter[MatrixCounter]) {
95 ELOG(0, "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!");
96 performCriticalExit();
97 return false;
98 }
99 if (j != -1) {
100 //if (j == 0) LOG(0, "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << ".");
101 for(int k=2;k<ColumnCounter[MatrixCounter];k++)
102 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][k];
103 }
104 }
105 }
106 return true;
107};
108
109
110/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
111 * \param *name directory with files
112 * \param *prefix prefix of each matrix file
113 * \param *suffix suffix of each matrix file
114 * \param skiplines number of inital lines to skip
115 * \param skiplines number of inital columns to skip
116 * \return parsing successful
117 */
118bool ForceMatrix::ParseFragmentMatrix(const char *name, const char *prefix, std::string suffix, int skiplines, int skipcolumns)
119{
120 char filename[1023];
121 ifstream input;
122 stringstream file;
123 int nr;
124 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
125
126 if (status) {
127 // count number of atoms for last plus one matrix
128 file << name << FRAGMENTPREFIX << KEYSETFILE;
129 input.open(file.str().c_str(), ios::in);
130 if (input.fail()) {
131 LOG(0, endl << "ForceMatrix::ParseFragmentMatrix: Unable to open " << file.str() << ", is the directory correct?");
132 return false;
133 }
134 RowCounter[MatrixCounter] = 0;
135 while (!input.eof()) {
136 input.getline(filename, 1023);
137 stringstream zeile(filename);
138 while (!zeile.eof()) {
139 zeile >> nr;
140 //LOG(0, "Current index: " << getNr() << ".");
141 if (nr > RowCounter[MatrixCounter])
142 RowCounter[MatrixCounter] = nr;
143 }
144 }
145 RowCounter[MatrixCounter]++; // Nr start at 0, count starts at 1
146 input.close();
147
148 ColumnCounter[MatrixCounter] = 0;
149 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
150 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
151 ColumnCounter[MatrixCounter] = ColumnCounter[j];
152 }
153
154 // allocate last plus one matrix
155 if ((int)Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
156 Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
157 for(int j=0;j<=RowCounter[MatrixCounter];j++)
158 if ((int)Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
159 Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
160
161 // try independently to parse global forcesuffix file if present
162 strncpy(filename, name, 1023);
163 strncat(filename, prefix, 1023-strlen(filename));
164 strncat(filename, suffix.c_str(), 1023-strlen(filename));
165 std::ifstream input(filename);
166 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter);
167 input.close();
168 }
169
170
171 return status;
172};
Note: See TracBrowser for help on using the repository browser.